diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-08-30 02:39:52 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-08-30 02:39:52 +0800 |
commit | 1c3b2b7141138f8da82197dfbdbdbfd76e7780b7 (patch) | |
tree | 729805d651424b1fc9ff8c8f7effc01d58efdcdf /packages/contracts/src | |
parent | f44644ad9029148c43f69d666356ed9fb18de4e2 (diff) | |
download | dexon-0x-contracts-1c3b2b7141138f8da82197dfbdbdbfd76e7780b7.tar dexon-0x-contracts-1c3b2b7141138f8da82197dfbdbdbfd76e7780b7.tar.gz dexon-0x-contracts-1c3b2b7141138f8da82197dfbdbdbfd76e7780b7.tar.bz2 dexon-0x-contracts-1c3b2b7141138f8da82197dfbdbdbfd76e7780b7.tar.lz dexon-0x-contracts-1c3b2b7141138f8da82197dfbdbdbfd76e7780b7.tar.xz dexon-0x-contracts-1c3b2b7141138f8da82197dfbdbdbfd76e7780b7.tar.zst dexon-0x-contracts-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.sol | 13 | ||||
-rw-r--r-- | packages/contracts/src/2.0.0/utils/LibBytes/LibBytes.sol | 7 |
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) |