From c2ccc0c19dcb7e957645e20a27fd321d6f018ba0 Mon Sep 17 00:00:00 2001 From: Anton Bukov Date: Mon, 22 Oct 2018 21:38:21 +0300 Subject: [PATCH] Fix short address decoding --- contracts/src/codec/RLP.sol | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/contracts/src/codec/RLP.sol b/contracts/src/codec/RLP.sol index c5a7bb2..6580968 100644 --- a/contracts/src/codec/RLP.sol +++ b/contracts/src/codec/RLP.sol @@ -289,14 +289,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.