Open luziusmeisser opened 3 years ago
Here is a test case that reverts under solidity 0.8 when used with RLPEncode.sol, but runs fine under solidity 0.7:
pragma solidity >=0.8.0;
import "./RLPEncode.sol";
contract Test {
function test() public view returns (bytes32) { address test = 0x29Fe8914e76da5cE2d90De98a64d0055f199d06D; bytes memory id = toBytes(uint32(uint160(test))); return calculateTransactionHash(13, id, test, 0, id); }
function calculateTransactionHash(uint128 sequence, bytes memory id, address to, uint value, bytes memory data) public pure returns (bytes32){ bytes[] memory all = new bytes; all[0] = toBytes(sequence); // sequence number instead of nonce all[1] = id; // contract id instead of gas price all[2] = toBytes(21000); // gas limit all[3] = abi.encodePacked(to); all[4] = toBytes(value); all[5] = data; all[6] = toBytes(1); all[7] = toBytes(0); for (uint i = 0; i<8; i++){ all[i] = RLPEncode.encodeBytes(all[i]); } all[8] = all[7]; return keccak256(RLPEncode.encodeList(all)); }
function toBytes(uint number) internal pure returns (bytes memory){ uint len = 0; uint temp = 1; while (number >= temp){ temp = temp << 8; len++; } temp = number; bytes memory data = new bytes(len); for (uint i = len; i>0; i--) { data[i-1] = bytes1(uint8(temp)); temp = temp >> 8; } return data; }
}
It looks like this library reverts when used with solidity 0.8.
One library that still works is this one: https://github.com/bakaoh/solidity-rlp-encode/blob/master/contracts/RLPEncode.sol