aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-08-30 02:39:52 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-08-30 02:39:52 +0800
commit1c3b2b7141138f8da82197dfbdbdbfd76e7780b7 (patch)
tree729805d651424b1fc9ff8c8f7effc01d58efdcdf /packages/contracts/src
parentf44644ad9029148c43f69d666356ed9fb18de4e2 (diff)
downloaddexon-sol-tools-1c3b2b7141138f8da82197dfbdbdbfd76e7780b7.tar
dexon-sol-tools-1c3b2b7141138f8da82197dfbdbdbfd76e7780b7.tar.gz
dexon-sol-tools-1c3b2b7141138f8da82197dfbdbdbfd76e7780b7.tar.bz2
dexon-sol-tools-1c3b2b7141138f8da82197dfbdbdbfd76e7780b7.tar.lz
dexon-sol-tools-1c3b2b7141138f8da82197dfbdbdbfd76e7780b7.tar.xz
dexon-sol-tools-1c3b2b7141138f8da82197dfbdbdbfd76e7780b7.tar.zst
dexon-sol-tools-1c3b2b7141138f8da82197dfbdbdbfd76e7780b7.zip
Updated readBytes4 to match spec + added unit tests. These are 3.5/3.6 from audit
Diffstat (limited to 'packages/contracts/src')
-rw-r--r--packages/contracts/src/2.0.0/protocol/AssetProxyOwner/AssetProxyOwner.sol13
-rw-r--r--packages/contracts/src/2.0.0/utils/LibBytes/LibBytes.sol7
2 files changed, 17 insertions, 3 deletions
diff --git a/packages/contracts/src/2.0.0/protocol/AssetProxyOwner/AssetProxyOwner.sol b/packages/contracts/src/2.0.0/protocol/AssetProxyOwner/AssetProxyOwner.sol
index 8b7333646..e661f2427 100644
--- a/packages/contracts/src/2.0.0/protocol/AssetProxyOwner/AssetProxyOwner.sol
+++ b/packages/contracts/src/2.0.0/protocol/AssetProxyOwner/AssetProxyOwner.sol
@@ -105,11 +105,20 @@ contract AssetProxyOwner is
uint256 index
)
internal
+ pure
returns (bytes4 result)
{
- require(b.length >= index + 4);
+ require(
+ b.length >= index + 4,
+ "GREATER_OR_EQUAL_TO_4_LENGTH_REQUIRED"
+ );
+
+ // Arrays are prefixed by a 32 byte length field
+ index += 32;
+
+ // Read the bytes4 from array memory
assembly {
- result := mload(add(b, 32))
+ result := mload(add(b, index))
// Solidity does not require us to clean the trailing bytes.
// We do it anyway
result := and(result, 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000)
diff --git a/packages/contracts/src/2.0.0/utils/LibBytes/LibBytes.sol b/packages/contracts/src/2.0.0/utils/LibBytes/LibBytes.sol
index 504e950a8..93873cbcc 100644
--- a/packages/contracts/src/2.0.0/utils/LibBytes/LibBytes.sol
+++ b/packages/contracts/src/2.0.0/utils/LibBytes/LibBytes.sol
@@ -467,8 +467,13 @@ library LibBytes {
b.length >= index + 4,
"GREATER_OR_EQUAL_TO_4_LENGTH_REQUIRED"
);
+
+ // Arrays are prefixed by a 32 byte length field
+ index += 32;
+
+ // Read the bytes4 from array memory
assembly {
- result := mload(add(b, 32))
+ result := mload(add(b, index))
// Solidity does not require us to clean the trailing bytes.
// We do it anyway
result := and(result, 0xFFFFFFFF00000000000000000000000000000000000000000000000000000000)