Transactions
Token Transfers
Tokens
Internal Transactions
Coin Balance History
Logs
Code
Read Contract
Write Contract
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- StateConnector
- Optimization enabled
- false
- Compiler version
- v0.7.6+commit.7338295f
- EVM Version
- default
- Verified at
- 2022-02-17T01:56:36.687118Z
Contract source code
// (c) 2021, Flare Networks Limited. All rights reserved. // Please see the file LICENSE for licensing terms. // SPDX-License-Identifier: MIT pragma solidity 0.7.6; contract StateConnector { //==================================================================== // Data Structures //==================================================================== address public constant SIGNAL_COINBASE = address(0x000000000000000000000000000000000000dEaD); // Signalling block.coinbase value uint256 public constant BUFFER_TIMESTAMP_OFFSET = 1636070400 seconds; // November 5th, 2021 uint256 public constant BUFFER_WINDOW = 90 seconds; // Amount of time a buffer is active before cycling to the next one uint256 public constant TOTAL_STORED_BUFFERS = 3; // {Requests, Votes, Reveals} uint256 public constant TOTAL_STORED_PROOFS = (1 weeks)/BUFFER_WINDOW; // Store a proof for one week //======================= // VOTING DATA STRUCTURES //======================= struct Vote { // Struct for Vote in round 'R' bytes32 maskedMerkleHash; // Masked hash of the merkle tree that contains valid requests from round 'R-1' bytes32 committedRandom; // Hash of random value that masks 'maskedMerkleHash' above bytes32 revealedRandom; // Reveal of 'committedRandom' from round 'R-1' Votes struct, used in 'R-2' request voting } struct Buffers { Vote[TOTAL_STORED_BUFFERS] votes; // {Requests, Votes, Reveals} uint256 latestVote; // The latest buffer number that this account has voted on, used for determining relevant votes } mapping(address => Buffers) public buffers; //============================= // MERKLE PROOF DATA STRUCTURES //============================= uint256 public totalBuffers; // The total number of buffers that have elapsed over time such that the latest buffer // has been proven using finaliseRound() bytes32[TOTAL_STORED_PROOFS] public merkleRoots; // The proven merkle roots for each buffer number, // accessed using: bufferNumber % TOTAL_STORED_PROOFS // within one week of proving the merkle root. //==================================================================== // Events //==================================================================== event AttestationRequest( uint256 timestamp, bytes data ); event RoundFinalised( uint256 bufferNumber, bytes32 merkleHash ); //==================================================================== // Constructor //==================================================================== constructor() { } //==================================================================== // Functions //==================================================================== function requestAttestations( bytes calldata data ) external { emit AttestationRequest(block.timestamp, data); } function submitAttestation( uint256 bufferNumber, bytes32 maskedMerkleHash, bytes32 committedRandom, bytes32 revealedRandom ) external returns ( bool _isInitialBufferSlot ) { require(bufferNumber == (block.timestamp - BUFFER_TIMESTAMP_OFFSET) / BUFFER_WINDOW); buffers[msg.sender].latestVote = bufferNumber; buffers[msg.sender].votes[bufferNumber % TOTAL_STORED_BUFFERS] = Vote( maskedMerkleHash, committedRandom, revealedRandom ); // Determine if this is the first attestation submitted in a new buffer round. // If so, the golang code will automatically finalise the previous round using finaliseRound() if (bufferNumber > totalBuffers) { return true; } return false; } function getAttestation( uint256 bufferNumber ) external view returns ( bytes32 _unmaskedMerkleHash ) { require(bufferNumber > 1); uint256 prevBufferNumber = bufferNumber - 1; require(buffers[msg.sender].latestVote >= prevBufferNumber); bytes32 revealedRandom = buffers[msg.sender].votes[prevBufferNumber % TOTAL_STORED_BUFFERS].revealedRandom; bytes32 committedRandom = buffers[msg.sender].votes[(prevBufferNumber-1) % TOTAL_STORED_BUFFERS].committedRandom; require(committedRandom == keccak256(abi.encodePacked(revealedRandom))); bytes32 maskedMerkleHash = buffers[msg.sender].votes[(prevBufferNumber-1) % TOTAL_STORED_BUFFERS].maskedMerkleHash; return (maskedMerkleHash ^ revealedRandom); } function finaliseRound( uint256 bufferNumber, bytes32 merkleHash ) external { require(bufferNumber > 1); require(bufferNumber == (block.timestamp - BUFFER_TIMESTAMP_OFFSET) / BUFFER_WINDOW); require(bufferNumber > totalBuffers); // The following region can only be called from the golang code if (msg.sender == block.coinbase && block.coinbase == SIGNAL_COINBASE) { totalBuffers = bufferNumber; merkleRoots[(bufferNumber-1) % TOTAL_STORED_PROOFS] = merkleHash; emit RoundFinalised(bufferNumber, merkleHash); } } }
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[]},{"type":"event","name":"AttestationRequest","inputs":[{"type":"uint256","name":"timestamp","internalType":"uint256","indexed":false},{"type":"bytes","name":"data","internalType":"bytes","indexed":false}],"anonymous":false},{"type":"event","name":"RoundFinalised","inputs":[{"type":"uint256","name":"bufferNumber","internalType":"uint256","indexed":false},{"type":"bytes32","name":"merkleHash","internalType":"bytes32","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"BUFFER_TIMESTAMP_OFFSET","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"BUFFER_WINDOW","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"SIGNAL_COINBASE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"TOTAL_STORED_BUFFERS","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"TOTAL_STORED_PROOFS","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"latestVote","internalType":"uint256"}],"name":"buffers","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"finaliseRound","inputs":[{"type":"uint256","name":"bufferNumber","internalType":"uint256"},{"type":"bytes32","name":"merkleHash","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"_unmaskedMerkleHash","internalType":"bytes32"}],"name":"getAttestation","inputs":[{"type":"uint256","name":"bufferNumber","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"merkleRoots","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"requestAttestations","inputs":[{"type":"bytes","name":"data","internalType":"bytes"}]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"_isInitialBufferSlot","internalType":"bool"}],"name":"submitAttestation","inputs":[{"type":"uint256","name":"bufferNumber","internalType":"uint256"},{"type":"bytes32","name":"maskedMerkleHash","internalType":"bytes32"},{"type":"bytes32","name":"committedRandom","internalType":"bytes32"},{"type":"bytes32","name":"revealedRandom","internalType":"bytes32"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalBuffers","inputs":[]}]
Contract Creation Code
0x608060405234801561001057600080fd5b50610887806100206000396000f3fe608060405234801561001057600080fd5b50600436106100b45760003560e01c8063cfd1fdad11610071578063cfd1fdad14610205578063eaebf6d314610267578063ec7424a01461029f578063f417c9d8146102bd578063f5f59a4a146102db578063f64b6fda146102f9576100b4565b806329be4db2146100b95780634b8a125f146100fb5780635f8c940d1461011957806371c5ecb11461013757806371e24574146101795780637ff6faa6146101d1575b600080fd5b6100e5600480360360208110156100cf57600080fd5b8101908080359060200190929190505050610372565b6040518082815260200191505060405180910390f35b610103610543565b6040518082815260200191505060405180910390f35b61012161054b565b6040518082815260200191505060405180910390f35b6101636004803603602081101561014d57600080fd5b8101908080359060200190929190505050610550565b6040518082815260200191505060405180910390f35b6101bb6004803603602081101561018f57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061056c565b6040518082815260200191505060405180910390f35b6101d961058a565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61024f6004803603608081101561021b57600080fd5b8101908080359060200190929190803590602001909291908035906020019092919080359060200190929190505050610590565b60405180821515815260200191505060405180910390f35b61029d6004803603604081101561027d57600080fd5b8101908080359060200190929190803590602001909291905050506106aa565b005b6102a76107c6565b6040518082815260200191505060405180910390f35b6102c56107cc565b6040518082815260200191505060405180910390f35b6102e36107dd565b6040518082815260200191505060405180910390f35b6103706004803603602081101561030f57600080fd5b810190808035906020019064010000000081111561032c57600080fd5b82018360208201111561033e57600080fd5b8035906020019184600183028401116401000000008311171561036057600080fd5b90919293919293905050506107e2565b005b60006001821161038157600080fd5b6000600183039050806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206009015410156103d757600080fd5b60008060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000016003838161042457fe5b066003811061042f57fe5b6003020160020154905060008060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000016003600185038161048957fe5b066003811061049457fe5b6003020160010154905081604051602001808281526020019150506040516020818303038152906040528051906020012081146104d057600080fd5b60008060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000016003600186038161052057fe5b066003811061052b57fe5b60030201600001549050828118945050505050919050565b636184740081565b600381565b600281611a40811061056157600080fd5b016000915090505481565b60006020528060005260406000206000915090508060090154905081565b61dead81565b6000605a63618474004203816105a257fe5b0485146105ae57600080fd5b846000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600901819055506040518060600160405280858152602001848152602001838152506000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000016003878161065a57fe5b066003811061066557fe5b6003020160008201518160000155602082015181600101556040820151816002015590505060015485111561069d57600190506106a2565b600090505b949350505050565b600182116106b757600080fd5b605a63618474004203816106c757fe5b0482146106d357600080fd5b60015482116106e157600080fd5b4173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16148015610749575061dead73ffffffffffffffffffffffffffffffffffffffff164173ffffffffffffffffffffffffffffffffffffffff16145b156107c25781600181905550806002605a62093a808161076557fe5b04600185038161077157fe5b06611a40811061077d57fe5b01819055507f8ffd19aa79a62d0764e560d21b1245698310783be781d7d80b38233d4d7d288c8282604051808381526020018281526020019250505060405180910390a15b5050565b60015481565b605a62093a80816107d957fe5b0481565b605a81565b7f5a4fad455fbfa0bb0f22d912bbfa4ef3d0887bb6933bffaf0f1f3e9fe1a12ca142838360405180848152602001806020018281038252848482818152602001925080828437600081840152601f19601f82011690508083019250505094505050505060405180910390a1505056fea2646970667358221220008d02cfa440bd897c5af6d5d43c0461f9c63abe938999fe6ba2f4efd6c3c21064736f6c63430007060033
Deployed ByteCode
0x608060405234801561001057600080fd5b50600436106100b45760003560e01c8063cfd1fdad11610071578063cfd1fdad14610205578063eaebf6d314610267578063ec7424a01461029f578063f417c9d8146102bd578063f5f59a4a146102db578063f64b6fda146102f9576100b4565b806329be4db2146100b95780634b8a125f146100fb5780635f8c940d1461011957806371c5ecb11461013757806371e24574146101795780637ff6faa6146101d1575b600080fd5b6100e5600480360360208110156100cf57600080fd5b8101908080359060200190929190505050610372565b6040518082815260200191505060405180910390f35b610103610543565b6040518082815260200191505060405180910390f35b61012161054b565b6040518082815260200191505060405180910390f35b6101636004803603602081101561014d57600080fd5b8101908080359060200190929190505050610550565b6040518082815260200191505060405180910390f35b6101bb6004803603602081101561018f57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061056c565b6040518082815260200191505060405180910390f35b6101d961058a565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61024f6004803603608081101561021b57600080fd5b8101908080359060200190929190803590602001909291908035906020019092919080359060200190929190505050610590565b60405180821515815260200191505060405180910390f35b61029d6004803603604081101561027d57600080fd5b8101908080359060200190929190803590602001909291905050506106aa565b005b6102a76107c6565b6040518082815260200191505060405180910390f35b6102c56107cc565b6040518082815260200191505060405180910390f35b6102e36107dd565b6040518082815260200191505060405180910390f35b6103706004803603602081101561030f57600080fd5b810190808035906020019064010000000081111561032c57600080fd5b82018360208201111561033e57600080fd5b8035906020019184600183028401116401000000008311171561036057600080fd5b90919293919293905050506107e2565b005b60006001821161038157600080fd5b6000600183039050806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206009015410156103d757600080fd5b60008060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000016003838161042457fe5b066003811061042f57fe5b6003020160020154905060008060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000016003600185038161048957fe5b066003811061049457fe5b6003020160010154905081604051602001808281526020019150506040516020818303038152906040528051906020012081146104d057600080fd5b60008060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000016003600186038161052057fe5b066003811061052b57fe5b60030201600001549050828118945050505050919050565b636184740081565b600381565b600281611a40811061056157600080fd5b016000915090505481565b60006020528060005260406000206000915090508060090154905081565b61dead81565b6000605a63618474004203816105a257fe5b0485146105ae57600080fd5b846000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600901819055506040518060600160405280858152602001848152602001838152506000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000016003878161065a57fe5b066003811061066557fe5b6003020160008201518160000155602082015181600101556040820151816002015590505060015485111561069d57600190506106a2565b600090505b949350505050565b600182116106b757600080fd5b605a63618474004203816106c757fe5b0482146106d357600080fd5b60015482116106e157600080fd5b4173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16148015610749575061dead73ffffffffffffffffffffffffffffffffffffffff164173ffffffffffffffffffffffffffffffffffffffff16145b156107c25781600181905550806002605a62093a808161076557fe5b04600185038161077157fe5b06611a40811061077d57fe5b01819055507f8ffd19aa79a62d0764e560d21b1245698310783be781d7d80b38233d4d7d288c8282604051808381526020018281526020019250505060405180910390a15b5050565b60015481565b605a62093a80816107d957fe5b0481565b605a81565b7f5a4fad455fbfa0bb0f22d912bbfa4ef3d0887bb6933bffaf0f1f3e9fe1a12ca142838360405180848152602001806020018281038252848482818152602001925080828437600081840152601f19601f82011690508083019250505094505050505060405180910390a1505056fea2646970667358221220008d02cfa440bd897c5af6d5d43c0461f9c63abe938999fe6ba2f4efd6c3c21064736f6c63430007060033