aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src
diff options
context:
space:
mode:
authorRemco Bloemen <remco@wicked.ventures>2018-06-14 00:13:17 +0800
committerRemco Bloemen <remco@wicked.ventures>2018-06-23 19:53:38 +0800
commit4bf4f96f478ba8e08bf2d44817294ddd5fe895c5 (patch)
tree083706667bbd51da211dce187b66b5b012b7e923 /packages/contracts/src
parent384cd2f6059bba994a6af2992a7df4909e24897c (diff)
downloaddexon-sol-tools-4bf4f96f478ba8e08bf2d44817294ddd5fe895c5.tar
dexon-sol-tools-4bf4f96f478ba8e08bf2d44817294ddd5fe895c5.tar.gz
dexon-sol-tools-4bf4f96f478ba8e08bf2d44817294ddd5fe895c5.tar.bz2
dexon-sol-tools-4bf4f96f478ba8e08bf2d44817294ddd5fe895c5.tar.lz
dexon-sol-tools-4bf4f96f478ba8e08bf2d44817294ddd5fe895c5.tar.xz
dexon-sol-tools-4bf4f96f478ba8e08bf2d44817294ddd5fe895c5.tar.zst
dexon-sol-tools-4bf4f96f478ba8e08bf2d44817294ddd5fe895c5.zip
Fix LibBytes.equals
Diffstat (limited to 'packages/contracts/src')
-rw-r--r--packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol25
1 files changed, 4 insertions, 21 deletions
diff --git a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol
index 2862ee3dd..3149a47e5 100644
--- a/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol
+++ b/packages/contracts/src/contracts/current/utils/LibBytes/LibBytes.sol
@@ -270,27 +270,10 @@ library LibBytes {
pure
returns (bool equal)
{
- assembly {
- // Get the number of words occupied by <lhs>
- let lenFullWords := div(add(mload(lhs), 0x1F), 0x20)
-
- // Add 1 to the number of words, to account for the length field
- lenFullWords := add(lenFullWords, 0x1)
-
- // Test equality word-by-word.
- // Terminates early if there is a mismatch.
- for {let i := 0} lt(i, lenFullWords) {i := add(i, 1)} {
- let lhsWord := mload(add(lhs, mul(i, 0x20)))
- let rhsWord := mload(add(rhs, mul(i, 0x20)))
- equal := eq(lhsWord, rhsWord)
- if eq(equal, 0) {
- // Break
- i := lenFullWords
- }
- }
- }
-
- return equal;
+ // Keccak gas cost is 30 + numWords * 6. This is a cheap way to compare.
+ // We early exit on unequal lengths, but keccak would also correctly
+ // handle this.
+ return lhs.length == rhs.length && keccak256(lhs) == keccak256(rhs);
}
/// @dev Reads an address from a position in a byte array.