From 13af865b88c4026ee45076c49c675be68339e79f Mon Sep 17 00:00:00 2001 From: Anton Bukov Date: Tue, 23 Oct 2018 16:21:32 +0300 Subject: [PATCH] Fix short address decoding Example addresses: ``` 0x0014F55A50b281EFD12294f0Cda821Bd8171e920 0x0000000000000000000000000000000000000000 ``` --- contracts/lib/RLP.sol | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/contracts/lib/RLP.sol b/contracts/lib/RLP.sol index bfb88ec..77dfd4f 100644 --- a/contracts/lib/RLP.sol +++ b/contracts/lib/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.