Contract
0x328e89be1ca9e6b33fad9502d7341a6438c58ab2
1
Contract Overview
Balance:
0 MATIC
My Name Tag:
Not Available
[ Download CSV Export ]
Contract Name:
BlockhashStore
Compiler Version
v0.6.6+commit.6c089d02
Contract Source Code (Solidity)
/** *Submitted for verification at polygonscan.com on 2022-01-21 */ // SPDX-License-Identifier: MIT pragma solidity 0.6.6; /** * @title BlockhashStore * @notice This contract provides a way to access blockhashes older than * the 256 block limit imposed by the BLOCKHASH opcode. * You may assume that any blockhash stored by the contract is correct. * Note that the contract depends on the format of serialized Ethereum * blocks. If a future hardfork of Ethereum changes that format, the * logic in this contract may become incorrect and an updated version * would have to be deployed. */ contract BlockhashStore { mapping(uint => bytes32) internal s_blockhashes; /** * @notice stores blockhash of a given block, assuming it is available through BLOCKHASH * @param n the number of the block whose blockhash should be stored */ function store(uint256 n) public { bytes32 h = blockhash(n); require(h != 0x0, "blockhash(n) failed"); s_blockhashes[n] = h; } /** * @notice stores blockhash of the earliest block still available through BLOCKHASH. */ function storeEarliest() external { store(block.number - 256); } /** * @notice stores blockhash after verifying blockheader of child/subsequent block * @param n the number of the block whose blockhash should be stored * @param header the rlp-encoded blockheader of block n+1. We verify its correctness by checking * that it hashes to a stored blockhash, and then extract parentHash to get the n-th blockhash. */ function storeVerifyHeader(uint256 n, bytes memory header) public { require(keccak256(header) == s_blockhashes[n + 1], "header has unknown blockhash"); // At this point, we know that header is the correct blockheader for block n+1. // The header is an rlp-encoded list. The head item of that list is the 32-byte blockhash of the parent block. // Based on how rlp works, we know that blockheaders always have the following form: // 0xf9____a0PARENTHASH... // ^ ^ ^ // | | | // | | +--- PARENTHASH is 32 bytes. rlpenc(PARENTHASH) is 0xa || PARENTHASH. // | | // | +--- 2 bytes containing the sum of the lengths of the encoded list items // | // +--- 0xf9 because we have a list and (sum of lengths of encoded list items) fits exactly into two bytes. // // As a consequence, the PARENTHASH is always at offset 4 of the rlp-encoded block header. bytes32 parentHash; assembly { parentHash := mload(add(header, 36)) // 36 = 32 byte offset for length prefix of ABI-encoded array // + 4 byte offset of PARENTHASH (see above) } s_blockhashes[n] = parentHash; } /** * @notice gets a blockhash from the store. If no hash is known, this function reverts. * @param n the number of the block whose blockhash should be returned */ function getBlockhash(uint256 n) external view returns (bytes32) { bytes32 h = s_blockhashes[n]; require(h != 0x0, "blockhash not found in store"); return h; } }
[{"inputs":[{"internalType":"uint256","name":"n","type":"uint256"}],"name":"getBlockhash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"n","type":"uint256"}],"name":"store","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"storeEarliest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"n","type":"uint256"},{"internalType":"bytes","name":"header","type":"bytes"}],"name":"storeVerifyHeader","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
608060405234801561001057600080fd5b506103bf806100206000396000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c80636057361d1461005157806383b6d6b71461007f578063e9413d3814610089578063fadff0e1146100cb575b600080fd5b61007d6004803603602081101561006757600080fd5b8101908080359060200190929190505050610190565b005b61008761022a565b005b6100b56004803603602081101561009f57600080fd5b8101908080359060200190929190505050610239565b6040518082815260200191505060405180910390f35b61018e600480360360408110156100e157600080fd5b81019080803590602001909291908035906020019064010000000081111561010857600080fd5b82018360208201111561011a57600080fd5b8035906020019184600183028401116401000000008311171561013c57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506102d3565b005b6000814090506000801b81141561020f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260138152602001807f626c6f636b68617368286e29206661696c65640000000000000000000000000081525060200191505060405180910390fd5b80600080848152602001908152602001600020819055505050565b6102376101004303610190565b565b6000806000808481526020019081526020016000205490506000801b8114156102ca576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601c8152602001807f626c6f636b68617368206e6f7420666f756e6420696e2073746f72650000000081525060200191505060405180910390fd5b80915050919050565b60008060018401815260200190815260200160002054818051906020012014610364576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601c8152602001807f6865616465722068617320756e6b6e6f776e20626c6f636b686173680000000081525060200191505060405180910390fd5b600060248201519050806000808581526020019081526020016000208190555050505056fea2646970667358221220c419b68bf6aa54294c9e4f07d7d523dcd3d47e82fdd0d7a42b95e9eb986b346564736f6c63430006060033
Deployed ByteCode Sourcemap
557:2559:0:-:0;;;;5:9:-1;2:2;;;27:1;24;17:12;2:2;557:2559:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;12:1:-1;9;2:12;820:144:0;;;;;;15:2:-1;10:3;7:11;4:2;;;31:1;28;21:12;4:2;820:144:0;;;;;;;;;;;;;;;;;:::i;:::-;;1074:72;;;:::i;:::-;;2936:177;;;;;;15:2:-1;10:3;7:11;4:2;;;31:1;28;21:12;4:2;2936:177:0;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;1524:1227;;;;;;15:2:-1;10:3;7:11;4:2;;;31:1;28;21:12;4:2;1524:1227:0;;;;;;;;;;;;;;;;;;;27:11:-1;14;11:28;8:2;;;52:1;49;42:12;8:2;1524:1227:0;;41:9:-1;34:4;18:14;14:25;11:40;8:2;;;64:1;61;54:12;8:2;1524:1227:0;;;;;;100:9:-1;95:1;81:12;77:20;67:8;63:35;60:50;39:11;25:12;22:29;11:107;8:2;;;131:1;128;121:12;8:2;1524:1227:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;30:3:-1;22:6;14;1:33;99:1;93:3;85:6;81:16;74:27;137:4;133:9;126:4;121:3;117:14;113:30;106:37;;169:3;161:6;157:16;147:26;;1524:1227:0;;;;;;;;;;;;;;;:::i;:::-;;820:144;860:9;882:1;872:12;860:24;;904:3;899:8;;:1;:8;;891:40;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;957:1;938:13;:16;952:1;938:16;;;;;;;;;;;:20;;;;820:144;;:::o;1074:72::-;1115:25;1136:3;1121:12;:18;1115:5;:25::i;:::-;1074:72::o;2936:177::-;2992:7;3008:9;3020:13;:16;3034:1;3020:16;;;;;;;;;;;;3008:28;;3056:3;3051:8;;:1;:8;;3043:49;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;3106:1;3099:8;;;2936:177;;;:::o;1524:1227::-;1626:13;:20;1644:1;1640;:5;1626:20;;;;;;;;;;;;1615:6;1605:17;;;;;;:41;1597:82;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2467:18;2542:2;2534:6;2530:15;2524:22;2510:36;;2735:10;2716:13;:16;2730:1;2716:16;;;;;;;;;;;:29;;;;1524:1227;;;:::o
Swarm Source
ipfs://c419b68bf6aa54294c9e4f07d7d523dcd3d47e82fdd0d7a42b95e9eb986b3465
Age | Block | Fee Address | BC Fee Address | Voting Power | Jailed | Incoming |
---|