From 35182b30fe1341b482200da6956f05932c82a42e Mon Sep 17 00:00:00 2001 From: Anton Bukov Date: Tue, 23 Oct 2018 15:59:17 +0300 Subject: [PATCH] Fix short address decoding Example addresses: ``` 0x0014F55A50b281EFD12294f0Cda821Bd8171e920 0x0000000000000000000000000000000000000000 ``` --- Testpool.sol | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Testpool.sol b/Testpool.sol index 9c10e58..ea64b5e 100644 --- a/Testpool.sol +++ b/Testpool.sol @@ -819,14 +819,10 @@ library RLP { /// @param self The RLPItem. /// @return The decoded string. function toAddress(RLPItem memory self) internal constant returns (address data) { - if(!isData(self)) - throw; - var (rStartPos, len) = _decode(self); - if (len != 20) + var (, len) = _decode(self); + if (len > 20) throw; - assembly { - data := div(mload(rStartPos), exp(256, 12)) - } + return address(toUint(self)); } // Get the payload offset.