diff --git a/contracts/src/codec/RLP.sol b/contracts/src/codec/RLP.sol index c5a7bb2..2df6b43 100644 --- a/contracts/src/codec/RLP.sol +++ b/contracts/src/codec/RLP.sol @@ -28,27 +28,26 @@ library RLP { /* Iterator */ - function next(Iterator memory self) internal constant returns (RLPItem memory subItem) { + function next(Iterator memory self) internal pure returns (RLPItem memory subItem) { if(hasNext(self)) { - var ptr = self._unsafe_nextPtr; - var itemLength = _itemLength(ptr); + uint ptr = self._unsafe_nextPtr; + uint itemLength = _itemLength(ptr); subItem._unsafe_memPtr = ptr; subItem._unsafe_length = itemLength; self._unsafe_nextPtr = ptr + itemLength; } else - throw; + revert(); } - function next(Iterator memory self, bool strict) internal constant returns (RLPItem memory subItem) { + function next(Iterator memory self, bool strict) internal pure returns (RLPItem memory subItem) { subItem = next(self); if(strict && !_validate(subItem)) - throw; - return; + revert(); } - function hasNext(Iterator memory self) internal constant returns (bool) { - var item = self._unsafe_item; + function hasNext(Iterator memory self) internal pure returns (bool) { + RLPItem memory item = self._unsafe_item; return self._unsafe_nextPtr < item._unsafe_memPtr + item._unsafe_length; } @@ -57,7 +56,7 @@ library RLP { /// @dev Creates an RLPItem from an array of RLP encoded bytes. /// @param self The RLP encoded bytes. /// @return An RLPItem - function toRLPItem(bytes memory self) internal constant returns (RLPItem memory) { + function toRLPItem(bytes memory self) internal pure returns (RLPItem memory) { uint len = self.length; if (len == 0) { return RLPItem(0, 0); @@ -71,18 +70,18 @@ library RLP { /// @dev Creates an RLPItem from an array of RLP encoded bytes. /// @param self The RLP encoded bytes. - /// @param strict Will throw if the data is not RLP encoded. + /// @param strict Will revert() if the data is not RLP encoded. /// @return An RLPItem - function toRLPItem(bytes memory self, bool strict) internal constant returns (RLPItem memory) { - var item = toRLPItem(self); + function toRLPItem(bytes memory self, bool strict) internal pure returns (RLPItem memory) { + RLPItem memory item = toRLPItem(self); if(strict) { uint len = self.length; if(_payloadOffset(item) > len) - throw; + revert(); if(_itemLength(item._unsafe_memPtr) != len) - throw; + revert(); if(!_validate(item)) - throw; + revert(); } return item; } @@ -90,14 +89,14 @@ library RLP { /// @dev Check if the RLP item is null. /// @param self The RLP item. /// @return 'true' if the item is null. - function isNull(RLPItem memory self) internal constant returns (bool ret) { + function isNull(RLPItem memory self) internal pure returns (bool ret) { return self._unsafe_length == 0; } /// @dev Check if the RLP item is a list. /// @param self The RLP item. /// @return 'true' if the item is a list. - function isList(RLPItem memory self) internal constant returns (bool ret) { + function isList(RLPItem memory self) internal pure returns (bool ret) { if (self._unsafe_length == 0) return false; uint memPtr = self._unsafe_memPtr; @@ -109,7 +108,7 @@ library RLP { /// @dev Check if the RLP item is data. /// @param self The RLP item. /// @return 'true' if the item is data. - function isData(RLPItem memory self) internal constant returns (bool ret) { + function isData(RLPItem memory self) internal pure returns (bool ret) { if (self._unsafe_length == 0) return false; uint memPtr = self._unsafe_memPtr; @@ -121,7 +120,7 @@ library RLP { /// @dev Check if the RLP item is empty (string or list). /// @param self The RLP item. /// @return 'true' if the item is null. - function isEmpty(RLPItem memory self) internal constant returns (bool ret) { + function isEmpty(RLPItem memory self) internal pure returns (bool ret) { if(isNull(self)) return false; uint b0; @@ -135,7 +134,7 @@ library RLP { /// @dev Get the number of items in an RLP encoded list. /// @param self The RLP item. /// @return The number of items. - function items(RLPItem memory self) internal constant returns (uint) { + function items(RLPItem memory self) internal pure returns (uint) { if (!isList(self)) return 0; uint b0; @@ -156,9 +155,9 @@ library RLP { /// @dev Create an iterator. /// @param self The RLP item. /// @return An 'Iterator' over the item. - function iterator(RLPItem memory self) internal constant returns (Iterator memory it) { + function iterator(RLPItem memory self) internal pure returns (Iterator memory it) { if (!isList(self)) - throw; + revert(); uint ptr = self._unsafe_memPtr + _payloadOffset(self); it._unsafe_item = self; it._unsafe_nextPtr = ptr; @@ -167,22 +166,24 @@ library RLP { /// @dev Return the RLP encoded bytes. /// @param self The RLPItem. /// @return The bytes. - function toBytes(RLPItem memory self) internal constant returns (bytes memory bts) { - var len = self._unsafe_length; - if (len == 0) - return; + function toBytes(RLPItem memory self) internal pure returns (bytes memory bts) { + uint len = self._unsafe_length; bts = new bytes(len); - _copyToBytes(self._unsafe_memPtr, bts, len); + if (len != 0) { + _copyToBytes(self._unsafe_memPtr, bts, len); + } } /// @dev Decode an RLPItem into bytes. This will not work if the /// RLPItem is a list. /// @param self The RLPItem. /// @return The decoded string. - function toData(RLPItem memory self) internal constant returns (bytes memory bts) { + function toData(RLPItem memory self) internal pure returns (bytes memory bts) { if(!isData(self)) - throw; - var (rStartPos, len) = _decode(self); + revert(); + uint rStartPos; + uint len; + (rStartPos, len) = _decode(self); bts = new bytes(len); _copyToBytes(rStartPos, bts, len); } @@ -191,12 +192,12 @@ library RLP { /// Warning: This is inefficient, as it requires that the list is read twice. /// @param self The RLP item. /// @return Array of RLPItems. - function toList(RLPItem memory self) internal constant returns (RLPItem[] memory list) { + function toList(RLPItem memory self) internal pure returns (RLPItem[] memory list) { if(!isList(self)) - throw; - var numItems = items(self); + revert(); + uint numItems = items(self); list = new RLPItem[](numItems); - var it = iterator(self); + Iterator memory it = iterator(self); uint idx; while(hasNext(it)) { list[idx] = next(it); @@ -208,10 +209,12 @@ library RLP { /// RLPItem is a list. /// @param self The RLPItem. /// @return The decoded string. - function toAscii(RLPItem memory self) internal constant returns (string memory str) { + function toAscii(RLPItem memory self) internal pure returns (string memory str) { if(!isData(self)) - throw; - var (rStartPos, len) = _decode(self); + revert(); + uint rStartPos; + uint len; + (rStartPos, len) = _decode(self); bytes memory bts = new bytes(len); _copyToBytes(rStartPos, bts, len); str = string(bts); @@ -221,12 +224,16 @@ library RLP { /// RLPItem is a list. /// @param self The RLPItem. /// @return The decoded string. - function toUint(RLPItem memory self) internal constant returns (uint data) { + function toUint(RLPItem memory self) internal pure returns (uint data) { if(!isData(self)) - throw; - var (rStartPos, len) = _decode(self); - if (len > 32 || len == 0) - throw; + revert(); + uint rStartPos; + uint len; + (rStartPos, len) = _decode(self); + if (len > 32) + revert(); + else if (len == 0) + return 0; assembly { data := div(mload(rStartPos), exp(256, sub(32, len))) } @@ -236,18 +243,20 @@ library RLP { /// RLPItem is a list. /// @param self The RLPItem. /// @return The decoded string. - function toBool(RLPItem memory self) internal constant returns (bool data) { + function toBool(RLPItem memory self) internal pure returns (bool data) { if(!isData(self)) - throw; - var (rStartPos, len) = _decode(self); + revert(); + uint rStartPos; + uint len; + (rStartPos, len) = _decode(self); if (len != 1) - throw; + revert(); uint temp; assembly { temp := byte(0, mload(rStartPos)) } if (temp > 1) - throw; + revert(); return temp == 1 ? true : false; } @@ -255,24 +264,26 @@ library RLP { /// RLPItem is a list. /// @param self The RLPItem. /// @return The decoded string. - function toByte(RLPItem memory self) internal constant returns (byte data) { + function toByte(RLPItem memory self) internal pure returns (byte data) { if(!isData(self)) - throw; - var (rStartPos, len) = _decode(self); + revert(); + uint rStartPos; + uint len; + (rStartPos, len) = _decode(self); if (len != 1) - throw; - uint temp; + revert(); + byte temp; assembly { temp := byte(0, mload(rStartPos)) } - return byte(temp); + return temp; } /// @dev Decode an RLPItem into an int. This will not work if the /// RLPItem is a list. /// @param self The RLPItem. /// @return The decoded string. - function toInt(RLPItem memory self) internal constant returns (int data) { + function toInt(RLPItem memory self) internal pure returns (int data) { return int(toUint(self)); } @@ -280,7 +291,7 @@ library RLP { /// RLPItem is a list. /// @param self The RLPItem. /// @return The decoded string. - function toBytes32(RLPItem memory self) internal constant returns (bytes32 data) { + function toBytes32(RLPItem memory self) internal pure returns (bytes32 data) { return bytes32(toUint(self)); } @@ -288,19 +299,21 @@ library RLP { /// RLPItem is a list. /// @param self The RLPItem. /// @return The decoded string. - function toAddress(RLPItem memory self) internal constant returns (address data) { + function toAddress(RLPItem memory self) internal pure returns (address data) { if(!isData(self)) - throw; - var (rStartPos, len) = _decode(self); + revert(); + uint rStartPos; + uint len; + (rStartPos, len) = _decode(self); if (len != 20) - throw; + revert(); assembly { data := div(mload(rStartPos), exp(256, 12)) } } // Get the payload offset. - function _payloadOffset(RLPItem memory self) private constant returns (uint) { + function _payloadOffset(RLPItem memory self) private pure returns (uint) { if(self._unsafe_length == 0) return 0; uint b0; @@ -318,7 +331,7 @@ library RLP { } // Get the full length of an RLP item. - function _itemLength(uint memPtr) private constant returns (uint len) { + function _itemLength(uint memPtr) private pure returns (uint len) { uint b0; assembly { b0 := byte(0, mload(memPtr)) @@ -346,9 +359,9 @@ library RLP { } // Get start position and length of the data. - function _decode(RLPItem memory self) private constant returns (uint memPtr, uint len) { + function _decode(RLPItem memory self) private pure returns (uint memPtr, uint len) { if(!isData(self)) - throw; + revert(); uint b0; uint start = self._unsafe_memPtr; assembly { @@ -357,7 +370,7 @@ library RLP { if (b0 < DATA_SHORT_START) { memPtr = start; len = 1; - return; + return (memPtr, len); } if (b0 < DATA_LONG_START) { len = self._unsafe_length - 1; @@ -370,45 +383,43 @@ library RLP { len = self._unsafe_length - 1 - bLen; memPtr = start + bLen + 1; } - return; + return (memPtr, len); } // Assumes that enough memory has been allocated to store in target. - function _copyToBytes(uint btsPtr, bytes memory tgt, uint btsLen) private constant { + function _copyToBytes(uint btsPtr, bytes memory tgt, uint btsLen) private pure { // Exploiting the fact that 'tgt' was the last thing to be allocated, // we can write entire words, and just overwrite any excess. assembly { { - let i := 0 // Start at arr + 0x20 - let words := div(add(btsLen, 31), 32) - let rOffset := btsPtr - let wOffset := add(tgt, 0x20) - tag_loop: - jumpi(end, eq(i, words)) - { - let offset := mul(i, 0x20) - mstore(add(wOffset, offset), mload(add(rOffset, offset))) - i := add(i, 1) - } - jump(tag_loop) - end: - mstore(add(tgt, add(0x20, mload(tgt))), 0) + let words := div(add(btsLen, 31), 32) + let rOffset := btsPtr + let wOffset := add(tgt, 0x20) + for + { let i := 0 } // Start at arr + 0x20 + lt(i, words) + { i := add(i, 1) } + { + let offset := mul(i, 0x20) + mstore(add(wOffset, offset), mload(add(rOffset, offset))) + } + mstore(add(tgt, add(0x20, mload(tgt))), 0) } } } // Check that an RLP item is valid. - function _validate(RLPItem memory self) private constant returns (bool ret) { - // Check that RLP is well-formed. - uint b0; - uint b1; - uint memPtr = self._unsafe_memPtr; - assembly { - b0 := byte(0, mload(memPtr)) - b1 := byte(1, mload(memPtr)) - } - if(b0 == DATA_SHORT_START + 1 && b1 < DATA_SHORT_START) - return false; - return true; + function _validate(RLPItem memory self) private pure returns (bool ret) { + // Check that RLP is well-formed. + uint b0; + uint b1; + uint memPtr = self._unsafe_memPtr; + assembly { + b0 := byte(0, mload(memPtr)) + b1 := byte(1, mload(memPtr)) } + if(b0 == DATA_SHORT_START + 1 && b1 < DATA_SHORT_START) + return false; + return true; + } } \ No newline at end of file diff --git a/contracts/test/RLPReaderTest.sol b/contracts/test/RLPReaderTest.sol index 6cd7d34..5eac9c0 100644 --- a/contracts/test/RLPReaderTest.sol +++ b/contracts/test/RLPReaderTest.sol @@ -6,87 +6,87 @@ contract RLPReaderTest { using RLP for RLP.Iterator; using RLP for bytes; - function testItem(bytes rlp) constant returns (uint memPtr, uint len, bool isList, uint[] list, uint listLen) { - var item = rlp.toRLPItem(); + function testItem(bytes memory rlp) public pure returns (uint memPtr, uint len, bool isList, uint[] memory list, uint listLen) { + RLP.RLPItem memory item = rlp.toRLPItem(); return _testItem(item); } - function testItemStrict(bytes rlp) constant returns (bool res) { + function testItemStrict(bytes memory rlp) public pure returns (bool res) { res = true; rlp.toRLPItem(true); } - function testFirst(bytes rlp) constant returns (uint memPtr, uint len, byte first) { - var item = rlp.toRLPItem(); + function testFirst(bytes memory rlp) public pure returns (uint memPtr, uint len, byte first) { + RLP.RLPItem memory item = rlp.toRLPItem(); memPtr = item._unsafe_memPtr; len = item._unsafe_length; - uint b0; + byte b0; assembly { b0 := byte(0, mload(memPtr)) } - first = byte(b0); + first = b0; } - function testIsList(bytes rlp) constant returns (bool ret) { + function testIsList(bytes memory rlp) public pure returns (bool ret) { ret = rlp.toRLPItem().isList(); } - function testIsData(bytes rlp) constant returns (bool ret) { + function testIsData(bytes memory rlp) public pure returns (bool ret) { ret = rlp.toRLPItem().isData(); } - function testIsNull(bytes rlp) constant returns (bool ret) { + function testIsNull(bytes memory rlp) public pure returns (bool ret) { ret = rlp.toRLPItem().isNull(); } - function testIsEmpty(bytes rlp) constant returns (bool ret) { + function testIsEmpty(bytes memory rlp) public pure returns (bool ret) { ret = rlp.toRLPItem().isEmpty(); } - function testItems(bytes rlp) constant returns (uint) { + function testItems(bytes memory rlp) public pure returns (uint) { return rlp.toRLPItem().items(); } - function testSubItem(bytes rlp, uint index) constant returns (uint memPtr, uint len, bool isList, uint[] list, uint listLen) { - var it = rlp.toRLPItem().iterator(); + function testSubItem(bytes memory rlp, uint index) public pure returns (uint memPtr, uint len, bool isList, uint[] memory list, uint listLen) { + RLP.Iterator memory it = rlp.toRLPItem().iterator(); uint idx; while(it.hasNext() && idx < index) { it.next(); idx++; } - var si = it.next(); - return _testItem(si); + RLP.RLPItem memory si = it.next(); + return _testItem(si); } - function testToData(bytes rlp) constant returns (bytes memory bts) { + function testToData(bytes memory rlp) public pure returns (bytes memory bts) { bts = rlp.toRLPItem().toData(); } - function testToUint(bytes rlp) constant returns (uint) { + function testToUint(bytes memory rlp) public pure returns (uint) { return rlp.toRLPItem().toUint(); } - function testToInt(bytes rlp) constant returns (int) { + function testToInt(bytes memory rlp) public pure returns (int) { return rlp.toRLPItem().toInt(); } - function testToBytes32(bytes rlp) constant returns (bytes32) { + function testToBytes32(bytes memory rlp) public pure returns (bytes32) { return rlp.toRLPItem().toBytes32(); } - function testToAddress(bytes rlp) constant returns (address) { + function testToAddress(bytes memory rlp) public pure returns (address) { return rlp.toRLPItem().toAddress(); } - function testToByte(bytes rlp) constant returns (byte) { + function testToByte(bytes memory rlp) public pure returns (byte) { return rlp.toRLPItem().toByte(); } - function testToBool(bytes rlp) constant returns (bool) { + function testToBool(bytes memory rlp) public pure returns (bool) { return rlp.toRLPItem().toBool(); } - function _testItem(RLP.RLPItem item) internal constant returns (uint memPtr, uint len, bool isList, uint[] memory list, uint listLen) { + function _testItem(RLP.RLPItem memory item) internal pure returns (uint memPtr, uint len, bool isList, uint[] memory list, uint listLen) { memPtr = item._unsafe_memPtr; len = item._unsafe_length; isList = item.isList(); @@ -95,9 +95,9 @@ contract RLPReaderTest { uint i; listLen = item.items(); list = new uint[](listLen); - var it = item.iterator(); - while(it.hasNext() && i < listLen) { - var si = it.next(); + RLP.Iterator memory it = item.iterator(); + while (it.hasNext() && i < listLen) { + RLP.RLPItem memory si = it.next(); uint ptr; assembly { ptr := mload(si) diff --git a/integration_tests/rlp_test.js b/integration_tests/rlp_test.js index 0b3fb60..7f31d33 100644 --- a/integration_tests/rlp_test.js +++ b/integration_tests/rlp_test.js @@ -4,113 +4,136 @@ const util = require('./utils'); const async = require('async'); var rlpreadertest; - -const bytecode = "0x6060604052611038806100126000396000f3606060405236156100c45760e060020a6000350463024a56a481146100c657806304455e951461011e5780630902c6d714610176578063564ad142146101ce57806361cd5683146102705780636f826a7d146102c85780637b053195146103205780637b8167191461037857806395e77a05146103d0578063a49886ce1461048b578063b66e68f2146104e3578063c91813ca14610552578063d572056e146105aa578063e59b0e1414610625578063e95bd5f21461067d578063f8f1f151146106e2575b005b61073a6004808035906020019082018035906020019191908080601f0160208091040260200160405190810160405280939291908181526020018383808284375094965050505050505060006108a46108ac8361044f565b61073a6004808035906020019082018035906020019191908080601f0160208091040260200160405190810160405280939291908181526020018383808284375094965050505050505060006108a46108d98361044f565b61074e6004808035906020019082018035906020019191908080601f01602080910402602001604051908101604052809392919081815260200183838082843750949650505050505050600061094661094d8361044f565b6107606004808035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437505060408051602081810183526000808352835160a0810185526060810182815260808201839052815280830182905284518086019095528185529184018190529799509735978796508695509093508492509082906109526109078b61044f565b6107c86004808035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437509496505050505050506000610946610a498361044f565b61073a6004808035906020019082018035906020019191908080601f0160208091040260200160405190810160405280939291908181526020018383808284375094965050505050505060006108a4610a5a8361044f565b61074e6004808035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437509496505050505050506000610946610a7f8361044f565b61074e6004808035906020019082018035906020019191908080601f0160208091040260200160405190810160405280939291908181526020018383808284375094965050505050505060006109466108b18361044f565b61073a6004808035906020019082018035906020019191908080601f0160208091040260200160405190810160405280939291908181526020018383808284375094965050505050505060016109a782826040805180820182526000808252602082810182905283518085019094528184528301819052909190610d6f855b6040805180820190915260008082526020820181905282519081811415610b1c5760408051808201909152818152602081018290529250610b39565b61074e6004808035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437509496505050505050506000610946610a948361044f565b6107e56004808035906020019082018035906020019191908080601f0160208091040260200160405190810160405280939291908181526020018383808284375094965050505050505060408051808201909152600080825260208201819052908190819081610a9f8661044f565b61073a6004808035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437509496505050505050506000610946610abf8361044f565b6107606004808035906020019082018035906020019191908080601f0160208091040260200160405190810160405280939291908181526020018383808284375094965050505050505060408051602081810183526000808352835180850190945280845290830181905291829182918290610ad08761044f565b61073a6004808035906020019082018035906020019191908080601f0160208091040260200160405190810160405280939291908181526020018383808284375094965050505050505060006108a4610aee8361044f565b61080d6004808035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437509496505050505050506040805160208101909152600081526108a4610af38361044f565b61087b6004808035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437509496505050505050506000610946610b0d8361044f565b604080519115158252519081900360200190f35b60408051918252519081900360200190f35b604051808681526020018581526020018415158152602001806020018381526020018281038252848181518152602001915080519060200190602002808383829060006004602084601f0104600f02600301f150905001965050505050505060405180910390f35b60408051600160f860020a03199092168252519081900360200190f35b604080519384526020840192909252600160f860020a03191682820152519081900360600190f35b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600f02600301f150905090810190601f16801561086d5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b90505b919050565b6108c3565b6000610946825b600060006000610b61845b60006000826020015160001415610b40576109a7565b610930565b94508450846040518059106108f05750595b818152602091820281019091016040529550610c468a5b6040805160a0810190915260006060820181815260808301829052825260208201819052610bb5835b60006000826020015160001415610b50576109a7565b90506108a7565b6108b8565b92505b6109ad8361097f565b6109d3835b6040805180820190915260008082526020820181905280610bf0845b6040805180820190915260008082526020918201528151808201518151928401519201909110905b50919050565b80156109b857508882105b1561095e576109c683610963565b5060019190910190610955565b9050610a33815b60408051602081810183526000808352835160a0810185526060810182815260808201839052815280830182905284518086019095528185528483018290528551928601519294929391928391829182610a728a610930565b939e929d50909b50995090975095505050505050565b6000600060006000610cbd856108c3565b600060006000610ce3845b60208101516000146108a7565b96508615610c52576108de8a5b600060006000600060006000610d1f87610930565b6000610946826108b8565b602081015190518051909891975060001a60f860020a0295509350505050565b6000600060006000610ddd856108c3565b9050610adb816109da565b939b929a50909850965090945092505050565b610a65565b6040805160208101909152600080825280610e30846108c3565b600060006000610e9c846108c3565b506040805180820190915260208481018083529082018390529092505b5050919050565b5050515160c060009190911a1090565b5050515160c060009190911a101590565b1515610b6c57610002565b610b84845b60006000600060006000610eda866108c3565b915091506020811180610b975750806000145b15610ba157610002565b806020036101000a82510492505050919050565b1515610bc057610002565b610bdd835b600060006000836020015160001415610f4b57610b39565b8351938352929092016020820152919050565b15610c055783602001519150610c0a82610c2d565b610002565b8284526020848101829052818401908601529050610b39565b80610d8f83600001515b8051600090811a6080811015610fb157600191506109a7565b92505b610c5f8361097f565b5050505091939590929450565b8015610c6a57508484105b15610c5257610c7883610963565b915081519050808685815181101561000257505050602084810287010181905260019390930192610c49565b825160001a90508060f860020a0293505b505050919050565b1515610cc857610002565b610cd185610b71565b909350915060018214610ca457610002565b15610cf15760009250610b39565b50508151805160001a906080821480610d0a575060c082145b9250610b39565b8095505b5050505050919050565b1515610d2e5760009550610d15565b8651805160001a95509350610d4287610bc5565b840192506001876020015185010391505b818311610d1157610d6383610c2d565b90920191600101610d53565b91508315610dd55750835180610d8483610bc5565b1115610c2357610002565b14610d9957610002565b610dca828051805160009181831a9160011a90608183148015610dbc5750608082105b15610e265760009350610cb5565b1515610dd557610002565b509392505050565b1515610de857610002565b610df185610b71565b909350915060018214610e0357610002565b50815160001a6001811115610e1757610002565b80600114610e26576000610e29565b60015b9350610cb5565b1515610e3b57610002565b610e4484610b71565b9150915080604051805910610e565750595b818152602091820281019091016040529250610b3982848360006020601f83010484602085015b8284146110255760208402808301518183015260018501945050610e7d565b1515610ea757610002565b610eb084610b71565b909250905060148114610ec257610002565b50516c01000000000000000000000000900492915050565b1515610ee557610002565b8551805160001a935091506080831015610f0757909350600192508390610f43565b60b8831015610f26576020860151600183019550600019019350610f43565b50602085015181830160b51901945082900360b601925060b61982015b505050915091565b50508151805160001a906080821015610f675760009250610b39565b60b8821080610f82575060c08210158015610f82575060f882105b15610f905760019250610b39565b60c0821015610fa55760b51982019250610b39565b60f51982019250610b39565b60b8811015610fc657607e19810191506109a7565b60c0811015610fef57600183015160b76020839003016101000a9004810160b5190191506109a7565b60f88110156110045760be19810191506109a7565b6001929092015160f76020849003016101000a900490910160f51901919050565b600086516020018701525050505050505056"; + +const bytecode = "0x608060405234801561001057600080fd5b50611abf806100206000396000f3fe608060405234801561001057600080fd5b50600436106101005760003560e01c806395e77a0511610097578063d572056e11610066578063d572056e14610bce578063e59b0e1414610cfe578063e95bd5f214610dd1578063f8f1f15114610f0557610100565b806395e77a0514610838578063a49886ce1461090b578063b66e68f2146109da578063c91813ca14610afb57610100565b806361cd5683116100d357806361cd5683146104b45780636f826a7d146105c75780637b0531951461069a5780637b8167191461076957610100565b8063024a56a41461010557806304455e95146101d85780630902c6d7146102ab578063564ad1421461037a575b600080fd5b6101be6004803603602081101561011b57600080fd5b810190808035906020019064010000000081111561013857600080fd5b82018360208201111561014a57600080fd5b8035906020019184600183028401116401000000008311171561016c57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050611000565b604051808215151515815260200191505060405180910390f35b610291600480360360208110156101ee57600080fd5b810190808035906020019064010000000081111561020b57600080fd5b82018360208201111561021d57600080fd5b8035906020019184600183028401116401000000008311171561023f57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061101a565b604051808215151515815260200191505060405180910390f35b610364600480360360208110156102c157600080fd5b81019080803590602001906401000000008111156102de57600080fd5b8201836020820111156102f057600080fd5b8035906020019184600183028401116401000000008311171561031257600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050611034565b6040518082815260200191505060405180910390f35b61043d6004803603604081101561039057600080fd5b81019080803590602001906401000000008111156103ad57600080fd5b8201836020820111156103bf57600080fd5b803590602001918460018302840111640100000000831117156103e157600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019092919050505061104e565b604051808681526020018581526020018415151515815260200180602001838152602001828103825284818151815260200191508051906020019060200280838360005b8381101561049c578082015181840152602081019050610481565b50505050905001965050505050505060405180910390f35b61056d600480360360208110156104ca57600080fd5b81019080803590602001906401000000008111156104e757600080fd5b8201836020820111156104f957600080fd5b8035906020019184600183028401116401000000008311171561051b57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506110d8565b60405180827effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200191505060405180910390f35b610680600480360360208110156105dd57600080fd5b81019080803590602001906401000000008111156105fa57600080fd5b82018360208201111561060c57600080fd5b8035906020019184600183028401116401000000008311171561062e57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506110f2565b604051808215151515815260200191505060405180910390f35b610753600480360360208110156106b057600080fd5b81019080803590602001906401000000008111156106cd57600080fd5b8201836020820111156106df57600080fd5b8035906020019184600183028401116401000000008311171561070157600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061110c565b6040518082815260200191505060405180910390f35b6108226004803603602081101561077f57600080fd5b810190808035906020019064010000000081111561079c57600080fd5b8201836020820111156107ae57600080fd5b803590602001918460018302840111640100000000831117156107d057600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050611126565b6040518082815260200191505060405180910390f35b6108f16004803603602081101561084e57600080fd5b810190808035906020019064010000000081111561086b57600080fd5b82018360208201111561087d57600080fd5b8035906020019184600183028401116401000000008311171561089f57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050611140565b604051808215151515815260200191505060405180910390f35b6109c46004803603602081101561092157600080fd5b810190808035906020019064010000000081111561093e57600080fd5b82018360208201111561095057600080fd5b8035906020019184600183028401116401000000008311171561097257600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050611160565b6040518082815260200191505060405180910390f35b610a93600480360360208110156109f057600080fd5b8101908080359060200190640100000000811115610a0d57600080fd5b820183602082011115610a1f57600080fd5b80359060200191846001830284011164010000000083111715610a4157600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061117a565b60405180848152602001838152602001827effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff19168152602001935050505060405180910390f35b610bb460048036036020811015610b1157600080fd5b8101908080359060200190640100000000811115610b2e57600080fd5b820183602082011115610b4057600080fd5b80359060200191846001830284011164010000000083111715610b6257600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506111b5565b604051808215151515815260200191505060405180910390f35b610c8760048036036020811015610be457600080fd5b8101908080359060200190640100000000811115610c0157600080fd5b820183602082011115610c1357600080fd5b80359060200191846001830284011164010000000083111715610c3557600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506111cf565b604051808681526020018581526020018415151515815260200180602001838152602001828103825284818151815260200191508051906020019060200280838360005b83811015610ce6578082015181840152602081019050610ccb565b50505050905001965050505050505060405180910390f35b610db760048036036020811015610d1457600080fd5b8101908080359060200190640100000000811115610d3157600080fd5b820183602082011115610d4357600080fd5b80359060200191846001830284011164010000000083111715610d6557600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050611208565b604051808215151515815260200191505060405180910390f35b610e8a60048036036020811015610de757600080fd5b8101908080359060200190640100000000811115610e0457600080fd5b820183602082011115610e1657600080fd5b80359060200191846001830284011164010000000083111715610e3857600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050611222565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610eca578082015181840152602081019050610eaf565b50505050905090810190601f168015610ef75780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610fbe60048036036020811015610f1b57600080fd5b8101908080359060200190640100000000811115610f3857600080fd5b820183602082011115610f4a57600080fd5b80359060200191846001830284011164010000000083111715610f6c57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929050505061123c565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b600061101361100e83611256565b6112b3565b9050919050565b600061102d61102883611256565b6112e4565b9050919050565b600061104761104283611256565b611316565b9050919050565b60008060006060600061105f611a36565b61107061106b89611256565b611375565b905060005b61107e826113bb565b801561108957508781105b156110a557611097826113e5565b508080600101915050611075565b6110ad611a56565b6110b6836113e5565b90506110c181611442565b975097509750975097505050509295509295909350565b60006110eb6110e683611256565b611523565b9050919050565b600061110561110083611256565b61156c565b9050919050565b600061111f61111a83611256565b6115af565b9050919050565b600061113961113483611256565b611627565b9050919050565b60006001905061115a60018361163990919063ffffffff16565b50919050565b600061117361116e83611256565b6116ab565b9050919050565b6000806000611187611a56565b61119085611256565b905080600001519350806020015192506000845160001a905080925050509193909250565b60006111c86111c383611256565b6116c0565b9050919050565b6000806000606060006111e0611a56565b6111e987611256565b90506111f481611442565b955095509550955095505091939590929450565b600061121b61121683611256565b611728565b9050919050565b606061123561123083611256565b611738565b9050919050565b600061124f61124a83611256565b6117a8565b9050919050565b61125e611a56565b600082519050600081141561128c5760405180604001604052806000815260200160008152509150506112ae565b6000602084019050604051806040016040528082815260200183815250925050505b919050565b600080826020015114156112ca57600090506112df565b60008260000151905060c0815160001a109150505b919050565b600080826020015114156112fb5760009050611311565b60008260000151905060c0815160001a10159150505b919050565b6000611321826112b3565b61132a57600080fd5b600080611336846117ef565b8092508193505050602081111561134c57600080fd5b600081141561136057600092505050611370565b806020036101000a825104925050505b919050565b61137d611a36565b611386826112e4565b61138f57600080fd5b600061139a8361187c565b83600001510190508282600001819052508082602001818152505050919050565b60006113c5611a56565b826000015190508060200151816000015101836020015110915050919050565b6113ed611a56565b6113f6826113bb565b1561143857600082602001519050600061140f8261190e565b90508183600001818152505080836020018181525050808201846020018181525050505061143d565b600080fd5b919050565b6000806000606060008560000151945085602001519350611462866112e4565b9250821561151a576000611475876115af565b9150816040519080825280602002602001820160405280156114a65781602001602082028038833980820191505090505b5092506114b1611a36565b6114ba88611375565b90505b6114c6816113bb565b80156114d157508282105b15611517576114de611a56565b6114e7826113e5565b9050600081519050808685815181106114fc57fe5b602002602001018181525050838060010194505050506114bd565b50505b91939590929450565b600061152e826112b3565b61153757600080fd5b600080611543846117ef565b80925081935050506001811461155857600080fd5b6000825160001a9050809350505050919050565b600061157782611728565b1561158557600090506115aa565b60008083600001519050805160001a915060808214806115a5575060c082145b925050505b919050565b60006115ba826112e4565b6115c75760009050611622565b60008083600001519050805160001a915060006115e38561187c565b82019050600060018660200151840103905060005b818311611619576116088361190e565b8301925080806001019150506115f8565b80955050505050505b919050565b600061163282611316565b9050919050565b611641611a56565b611649611a56565b61165284611256565b905082156116a1576000845190508061166a8361187c565b111561167557600080fd5b80611683836000015161190e565b1461168d57600080fd5b611696826119a8565b61169f57600080fd5b505b8091505092915050565b60006116b682611316565b60001b9050919050565b60006116cb826112b3565b6116d457600080fd5b6000806116e0846117ef565b8092508193505050600181146116f557600080fd5b6000825160001a9050600181111561170c57600080fd5b6001811461171b57600061171e565b60015b9350505050919050565b6000808260200151149050919050565b6060611743826112b3565b61174c57600080fd5b600080611758846117ef565b8092508193505050806040519080825280601f01601f1916602001820160405280156117935781602001600182028038833980820191505090505b5092506117a18284836119f4565b5050919050565b60006117b3826112b3565b6117bc57600080fd5b6000806117c8846117ef565b8092508193505050601481146117dd57600080fd5b600c6101000a82510492505050919050565b6000806117fb836112b3565b61180457600080fd5b60008084600001519050805160001a9150608082101561183257809350600192508383935093505050611877565b60b8821015611850576001856020015103925060018101935061186e565b600060b7830390508060018760200151030393506001818301019450505b83839350935050505b915091565b600080826020015114156118935760009050611909565b60008083600001519050805160001a915060808210156118b857600092505050611909565b60b88210806118d4575060c082101580156118d3575060f882105b5b156118e457600192505050611909565b60c08210156118fd57600160b783030192505050611909565b600160f7830301925050505b919050565b600080825160001a9050608081101561192a57600191506119a2565b60b8811015611941576001608082030191506119a1565b60c081101561196b5760b78103806020036101000a600185015104808201600101935050506119a0565b60f881101561198257600160c0820301915061199f565b60f78103806020036101000a600185015104808201600101935050505b5b5b5b50919050565b60008060008084600001519050805160001a9250805160011a91506001608001831480156119d65750608082105b156119e757600093505050506119ef565b600193505050505b919050565b6020601f820104836020840160005b83811015611a235760208102808401518184015250600181019050611a03565b5060008551602001860152505050505050565b6040518060400160405280611a49611a70565b8152602001600081525090565b604051806040016040528060008152602001600081525090565b60405180604001604052806000815260200160008152509056fea265627a7a7231582063fcde3b0e28bb30f1c3c5f724688cf956f560e7e952c32bb52e1f51637de8ed64736f6c634300050d0032"; const ABI = [{ - "constant": true, - "inputs": [{"name": "rlp", "type": "bytes"}], - "name": "testIsData", - "outputs": [{"name": "ret", "type": "bool"}], - "type": "function" + "constant":true, + "inputs":[{"internalType":"bytes","name":"rlp","type":"bytes"}], + "name":"testFirst", + "outputs":[{"internalType":"uint256","name":"memPtr","type":"uint256"},{"internalType":"uint256","name":"len","type":"uint256"},{"internalType":"bytes1","name":"first","type":"bytes1"}], + "payable":false, + "stateMutability":"pure", + "type":"function" }, { - "constant": true, - "inputs": [{"name": "rlp", "type": "bytes"}], - "name": "testIsList", - "outputs": [{"name": "ret", "type": "bool"}], - "type": "function" + "constant":true, + "inputs":[{"internalType":"bytes","name":"rlp","type":"bytes"}], + "name":"testIsData", + "outputs":[{"internalType":"bool","name":"ret","type":"bool"}], + "payable":false, + "stateMutability":"pure", + "type":"function" }, { - "constant": true, - "inputs": [{"name": "rlp", "type": "bytes"}], - "name": "testToUint", - "outputs": [{"name": "", "type": "uint256"}], - "type": "function" + "constant":true, + "inputs":[{"internalType":"bytes","name":"rlp","type":"bytes"}], + "name":"testIsEmpty", + "outputs":[{"internalType":"bool","name":"ret","type":"bool"}], + "payable":false, + "stateMutability":"pure", + "type":"function" }, { - "constant": true, - "inputs": [{"name": "rlp", "type": "bytes"}, {"name": "index", "type": "uint256"}], - "name": "testSubItem", - "outputs": [{"name": "memPtr", "type": "uint256"}, {"name": "len", "type": "uint256"}, { - "name": "isList", - "type": "bool" - }, {"name": "list", "type": "uint256[]"}, {"name": "listLen", "type": "uint256"}], - "type": "function" + "constant":true, + "inputs":[{"internalType":"bytes","name":"rlp","type":"bytes"}], + "name":"testIsList", + "outputs":[{"internalType":"bool","name":"ret","type":"bool"}], + "payable":false, + "stateMutability":"pure", + "type":"function" }, { - "constant": true, - "inputs": [{"name": "rlp", "type": "bytes"}], - "name": "testToByte", - "outputs": [{"name": "", "type": "bytes1"}], - "type": "function" + "constant":true, + "inputs":[{"internalType":"bytes","name":"rlp","type":"bytes"}], + "name":"testIsNull", + "outputs":[{"internalType":"bool","name":"ret","type":"bool"}], + "payable":false, + "stateMutability":"pure", + "type":"function" }, { - "constant": true, - "inputs": [{"name": "rlp", "type": "bytes"}], - "name": "testIsEmpty", - "outputs": [{"name": "ret", "type": "bool"}], - "type": "function" + "constant":true, + "inputs":[{"internalType":"bytes","name":"rlp","type":"bytes"}], + "name":"testItem", + "outputs":[{"internalType":"uint256","name":"memPtr","type":"uint256"},{"internalType":"uint256","name":"len","type":"uint256"},{"internalType":"bool","name":"isList","type":"bool"},{"internalType":"uint256[]","name":"list","type":"uint256[]"},{"internalType":"uint256","name":"listLen","type":"uint256"}], + "payable":false, + "stateMutability":"pure", + "type":"function" }, { - "constant": true, - "inputs": [{"name": "rlp", "type": "bytes"}], - "name": "testItems", - "outputs": [{"name": "", "type": "uint256"}], - "type": "function" + "constant":true, + "inputs":[{"internalType":"bytes","name":"rlp","type":"bytes"}], + "name":"testItemStrict", + "outputs":[{"internalType":"bool","name":"res","type":"bool"}], + "payable":false, + "stateMutability":"pure", + "type":"function" }, { - "constant": true, - "inputs": [{"name": "rlp", "type": "bytes"}], - "name": "testToInt", - "outputs": [{"name": "", "type": "int256"}], - "type": "function" + "constant":true, + "inputs":[{"internalType":"bytes","name":"rlp","type":"bytes"}], + "name":"testItems", + "outputs":[{"internalType":"uint256","name":"","type":"uint256"}], + "payable":false,"stateMutability": + "pure", + "type":"function" }, { - "constant": true, - "inputs": [{"name": "rlp", "type": "bytes"}], - "name": "testItemStrict", - "outputs": [{"name": "res", "type": "bool"}], - "type": "function" + "constant":true, + "inputs":[{"internalType":"bytes","name":"rlp","type":"bytes"},{"internalType":"uint256","name":"index","type":"uint256"}], + "name":"testSubItem", + "outputs":[{"internalType":"uint256","name":"memPtr","type":"uint256"},{"internalType":"uint256","name":"len","type":"uint256"},{"internalType":"bool","name":"isList","type":"bool"},{"internalType":"uint256[]","name":"list","type":"uint256[]"},{"internalType":"uint256","name":"listLen","type":"uint256"}], + "payable":false, + "stateMutability":"pure", + "type":"function" }, { - "constant": true, - "inputs": [{"name": "rlp", "type": "bytes"}], - "name": "testToBytes32", - "outputs": [{"name": "", "type": "bytes32"}], - "type": "function" + "constant":true, + "inputs":[{"internalType":"bytes","name":"rlp","type":"bytes"}], + "name":"testToAddress", + "outputs":[{"internalType":"address","name":"","type":"address"}], + "payable":false, + "stateMutability":"pure", + "type":"function" }, { - "constant": true, - "inputs": [{"name": "rlp", "type": "bytes"}], - "name": "testFirst", - "outputs": [{"name": "memPtr", "type": "uint256"}, {"name": "len", "type": "uint256"}, { - "name": "first", - "type": "bytes1" - }], - "type": "function" + "constant":true, + "inputs":[{"internalType":"bytes","name":"rlp","type":"bytes"}], + "name":"testToBool", + "outputs":[{"internalType":"bool","name":"","type":"bool"}], + "payable":false, + "stateMutability":"pure", + "type":"function" }, { - "constant": true, - "inputs": [{"name": "rlp", "type": "bytes"}], - "name": "testToBool", - "outputs": [{"name": "", "type": "bool"}], - "type": "function" + "constant":true, + "inputs":[{"internalType":"bytes","name":"rlp","type":"bytes"}], + "name":"testToByte", + "outputs":[{"internalType":"bytes1","name":"","type":"bytes1"}], + "payable":false, + "stateMutability":"pure", + "type":"function" }, { - "constant": true, - "inputs": [{"name": "rlp", "type": "bytes"}], - "name": "testItem", - "outputs": [{"name": "memPtr", "type": "uint256"}, {"name": "len", "type": "uint256"}, { - "name": "isList", - "type": "bool" - }, {"name": "list", "type": "uint256[]"}, {"name": "listLen", "type": "uint256"}], - "type": "function" + "constant":true, + "inputs":[{"internalType":"bytes","name":"rlp","type":"bytes"}], + "name":"testToBytes32", + "outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}], + "payable":false, + "stateMutability":"pure", + "type":"function" }, { - "constant": true, - "inputs": [{"name": "rlp", "type": "bytes"}], - "name": "testIsNull", - "outputs": [{"name": "ret", "type": "bool"}], - "type": "function" + "constant":true, + "inputs":[{"internalType":"bytes","name":"rlp","type":"bytes"}], + "name":"testToData", + "outputs":[{"internalType":"bytes","name":"bts","type":"bytes"}], + "payable":false, + "stateMutability":"pure", + "type":"function" }, { - "constant": true, - "inputs": [{"name": "rlp", "type": "bytes"}], - "name": "testToData", - "outputs": [{"name": "bts", "type": "bytes"}], - "type": "function" + "constant":true, + "inputs":[{"internalType":"bytes","name":"rlp","type":"bytes"}], + "name":"testToInt", + "outputs":[{"internalType":"int256","name":"","type":"int256"}], + "payable":false, + "stateMutability":"pure", + "type":"function" }, { - "constant": true, - "inputs": [{"name": "rlp", "type": "bytes"}], - "name": "testToAddress", - "outputs": [{"name": "", "type": "address"}], - "type": "function" + "constant":true, + "inputs":[{"internalType":"bytes","name":"rlp","type":"bytes"}], + "name":"testToUint", + "outputs":[{"internalType":"uint256","name":"","type":"uint256"}], + "payable":false, + "stateMutability":"pure", + "type":"function" }]; describe('Codec', function () {