From 045aaede9e79b2f77fc03b79144e268551805dd9 Mon Sep 17 00:00:00 2001 From: Anton Bukov Date: Tue, 23 Oct 2018 15:52:32 +0300 Subject: [PATCH] Fix short address decoding Example addresses: ``` 0x0014F55A50b281EFD12294f0Cda821Bd8171e920 0x0000000000000000000000000000000000000000 ``` --- contracts/RLP.sol | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/contracts/RLP.sol b/contracts/RLP.sol index 9f86c8f..8f50db7 100755 --- a/contracts/RLP.sol +++ b/contracts/RLP.sol @@ -314,13 +314,11 @@ function toBytes32(RLPItem memory self) internal pure returns (bytes32 data, boo function toAddress(RLPItem memory self) internal pure returns (address data, bool valid) { if (!isData(self)) return; - (uint256 rStartPos, uint256 len) = _decode(self); - if (len != 20) + (, uint256 len) = _decode(self); + if (len > 20) return; - assembly { - data := div(mload(rStartPos), exp(256, 12)) - } - return (data, true); + (uint256 data, bool validUint) = toUint(self); + return (address(data), validUint); } // Get the payload offset. @@ -435,4 +433,4 @@ function _validate(RLPItem memory self) internal pure returns (bool ret) { return false; return true; } -} \ No newline at end of file +}