From 0a251acb9b26d4c2d283f925e25c74941eda9ed4 Mon Sep 17 00:00:00 2001 From: Anton Bukov Date: Tue, 23 Oct 2018 16:15:18 +0300 Subject: [PATCH] Fix short address decoding Example addresses: ``` 0x0014F55A50b281EFD12294f0Cda821Bd8171e920 0x0000000000000000000000000000000000000000 ``` --- contracts/libraries/RLP.sol | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/contracts/libraries/RLP.sol b/contracts/libraries/RLP.sol index 99be918..77dfd4f 100644 --- a/contracts/libraries/RLP.sol +++ b/contracts/libraries/RLP.sol @@ -300,16 +300,11 @@ library RLP { /// @param self The RLPItem. /// @return The decoded string. function toAddress(RLPItem memory self) internal pure returns (address data) { - if(!isData(self)) - revert(); - uint rStartPos; uint len; - (rStartPos, len) = _decode(self); - if (len != 20) + (, len) = _decode(self); + if (len > 20) revert(); - assembly { - data := div(mload(rStartPos), exp(256, 12)) - } + return address(toUint(self)); } // Get the payload offset. @@ -424,4 +419,4 @@ library RLP { return false; return true; } -} \ No newline at end of file +}