Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- Entropy
- Optimization enabled
- true
- Compiler version
- v0.5.1+commit.c8a2cb62
- Optimization runs
- 200
- EVM Version
- default
- Verified at
- 2024-09-26T15:31:30.670087Z
Contract source code
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.5.1; contract Lottery_interface { function get_round() public view returns (uint256); function get_phase() public view returns (uint8); // 0 - inactive / 1 - deposits phase and entropy collecting / 2 - entropy reveal phase } contract Entropy { address public owner = msg.sender; address public lottery_contract; struct provider { uint256 round; bytes32 entropy_hash; } uint256 public collateral_threshold = 0.2 ether; // Collateral for one entropy submission mapping (bytes32=>bool) public prohibited_hashes; // A mapping of already used entropy submissions mapping (address=>provider) public entropy_providers; // A mapping of active entropy submissions of the round uint256 public entropy_reward = 0; // Collected entropy reward for the current round uint256 public entropy = 0; // A number used as entropy input for the main Lottery Contract uint256 public current_round = 0; uint256 public num_providers = 0; // The number of entropy providers for the current round function() external payable { deposit_entropy_reward(); } function get_entropy() public view returns (uint256) { return entropy; } function deposit_entropy_reward() public payable { entropy_reward += msg.value; } function new_round() public only_lottery_contract { entropy_reward = address(this).balance; // All unrevealed entropy collaterals are now next round rewards current_round = Lottery_interface(lottery_contract).get_round(); // Update the round num_providers = 0; } function submit_entropy(bytes32 _entropy_hash) public payable { require(msg.value == collateral_threshold, "Collateral amount is incorrect"); require(!prohibited_hashes[_entropy_hash], "This entropy input was already used previously"); require(entropy_providers[msg.sender].round < current_round, "This address is already an entropy provider in this round"); require(Lottery_interface(lottery_contract).get_phase() == 1, "Entropy submissions are only allowed during the depositing lottery phase"); prohibited_hashes[_entropy_hash] = true; // Mark this hash as "already used" to prevent its future uses entropy_providers[msg.sender].round = current_round; entropy_providers[msg.sender].entropy_hash = _entropy_hash; num_providers++; } function reveal_entropy(uint256 _entropy_payload, uint256 _salt) public { require(entropy_providers[msg.sender].round == current_round, "The address is trying to reveal the entropy for inappropriate round"); require(sha256(abi.encodePacked(_entropy_payload, _salt)) == entropy_providers[msg.sender].entropy_hash, "Entropy values do not match the provided hash"); // require(Lottery_interface(lottery_contract).get_phase() == 2, "Entropy reveals are only allowed during the reveal phase"); entropy += _entropy_payload; msg.sender.transfer(collateral_threshold + (entropy_reward / num_providers)); } function test_hash(uint256 _entropy_payload, uint256 _salt) pure public returns (bytes32) { return sha256(abi.encodePacked(_entropy_payload, _salt)); } modifier only_owner { require(msg.sender == owner); _; } modifier only_lottery_contract { require(msg.sender == lottery_contract); _; } function set_lottery_contract(address payable _new_contract) public only_owner { lottery_contract = _new_contract; } }
Contract ABI
[{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"new_round","inputs":[],"constant":false},{"type":"function","stateMutability":"payable","payable":true,"outputs":[],"name":"deposit_entropy_reward","inputs":[],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":""}],"name":"current_round","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":""}],"name":"entropy","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":""}],"name":"lottery_contract","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":""}],"name":"get_entropy","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":""}],"name":"entropy_reward","inputs":[],"constant":true},{"type":"function","stateMutability":"pure","payable":false,"outputs":[{"type":"bytes32","name":""}],"name":"test_hash","inputs":[{"type":"uint256","name":"_entropy_payload"},{"type":"uint256","name":"_salt"}],"constant":true},{"type":"function","stateMutability":"payable","payable":true,"outputs":[],"name":"submit_entropy","inputs":[{"type":"bytes32","name":"_entropy_hash"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":""}],"name":"owner","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":""}],"name":"prohibited_hashes","inputs":[{"type":"bytes32","name":""}],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"set_lottery_contract","inputs":[{"type":"address","name":"_new_contract"}],"constant":false},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"reveal_entropy","inputs":[{"type":"uint256","name":"_entropy_payload"},{"type":"uint256","name":"_salt"}],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"round"},{"type":"bytes32","name":"entropy_hash"}],"name":"entropy_providers","inputs":[{"type":"address","name":""}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":""}],"name":"collateral_threshold","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":""}],"name":"num_providers","inputs":[],"constant":true},{"type":"fallback","stateMutability":"payable","payable":true}]
Contract Creation Code
0x608060405260008054600160a060020a031916331781556702c68af0bb14000060025560058190556006819055600781905560085534801561004057600080fd5b50610aab806100506000396000f3fe6080604052600436106100df577c0100000000000000000000000000000000000000000000000000000000600035046322028a8481146100e95780632b807d37146100df578063319c068c146100fe57806347ce07cc14610125578063499159121461013a578063658f17881461016b578063712fcb511461018057806378601f39146101955780637b4b5d51146101c55780638da5cb5b146101e257806393c05a5b146101f7578063ac9d50d214610235578063ae46cc2714610268578063c094e0e314610298578063e93a3ff3146102e4578063fea0dd1d146102f9575b6100e761030e565b005b3480156100f557600080fd5b506100e7610318565b34801561010a57600080fd5b506101136103c8565b60408051918252519081900360200190f35b34801561013157600080fd5b506101136103ce565b34801561014657600080fd5b5061014f6103d4565b60408051600160a060020a039092168252519081900360200190f35b34801561017757600080fd5b506101136103e3565b34801561018c57600080fd5b506101136103e9565b3480156101a157600080fd5b50610113600480360360408110156101b857600080fd5b50803590602001356103ef565b6100e7600480360360208110156101db57600080fd5b50356104a7565b3480156101ee57600080fd5b5061014f610797565b34801561020357600080fd5b506102216004803603602081101561021a57600080fd5b50356107a6565b604080519115158252519081900360200190f35b34801561024157600080fd5b506100e76004803603602081101561025857600080fd5b5035600160a060020a03166107bb565b34801561027457600080fd5b506100e76004803603604081101561028b57600080fd5b5080359060200135610801565b3480156102a457600080fd5b506102cb600480360360208110156102bb57600080fd5b5035600160a060020a0316610a5a565b6040805192835260208301919091528051918290030190f35b3480156102f057600080fd5b50610113610a73565b34801561030557600080fd5b50610113610a79565b6005805434019055565b600154600160a060020a0316331461032f57600080fd5b3031600555600154604080517fb9802e3e0000000000000000000000000000000000000000000000000000000081529051600160a060020a039092169163b9802e3e91600480820192602092909190829003018186803b15801561039257600080fd5b505afa1580156103a6573d6000803e3d6000fd5b505050506040513d60208110156103bc57600080fd5b50516007556000600855565b60075481565b60065481565b600154600160a060020a031681565b60065490565b60055481565b60006002838360405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061044a5780518252601f19909201916020918201910161042b565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa158015610489573d6000803e3d6000fd5b5050506040513d602081101561049e57600080fd5b50519392505050565b6002543414610500576040805160e560020a62461bcd02815260206004820152601e60248201527f436f6c6c61746572616c20616d6f756e7420697320696e636f72726563740000604482015290519081900360640190fd5b60008181526003602052604090205460ff161561058d576040805160e560020a62461bcd02815260206004820152602e60248201527f5468697320656e74726f707920696e7075742077617320616c7265616479207560448201527f7365642070726576696f75736c79000000000000000000000000000000000000606482015290519081900360840190fd5b600754336000908152600460205260409020541061061b576040805160e560020a62461bcd02815260206004820152603960248201527f54686973206164647265737320697320616c726561647920616e20656e74726f60448201527f70792070726f766964657220696e207468697320726f756e6400000000000000606482015290519081900360840190fd5b600160009054906101000a9004600160a060020a0316600160a060020a031663a5b860046040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801561068557600080fd5b505afa158015610699573d6000803e3d6000fd5b505050506040513d60208110156106af57600080fd5b505160ff16600114610757576040805160e560020a62461bcd02815260206004820152604860248201527f456e74726f7079207375626d697373696f6e7320617265206f6e6c7920616c6c60448201527f6f77656420647572696e6720746865206465706f736974696e67206c6f74746560648201527f7279207068617365000000000000000000000000000000000000000000000000608482015290519081900360a40190fd5b6000818152600360209081526040808320805460ff1916600190811790915560075433855260049093529220908155810191909155600880549091019055565b600054600160a060020a031681565b60036020526000908152604090205460ff1681565b600054600160a060020a031633146107d257600080fd5b6001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b60075433600090815260046020526040902054146108b5576040805160e560020a62461bcd02815260206004820152604360248201527f546865206164647265737320697320747279696e6720746f2072657665616c2060448201527f74686520656e74726f707920666f7220696e617070726f70726961746520726f60648201527f756e640000000000000000000000000000000000000000000000000000000000608482015290519081900360a40190fd5b6004600033600160a060020a0316600160a060020a03168152602001908152602001600020600101546002838360405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b602083106109375780518252601f199092019160209182019101610918565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa158015610976573d6000803e3d6000fd5b5050506040513d602081101561098b57600080fd5b505114610a08576040805160e560020a62461bcd02815260206004820152602d60248201527f456e74726f70792076616c75657320646f206e6f74206d61746368207468652060448201527f70726f7669646564206861736800000000000000000000000000000000000000606482015290519081900360840190fd5b600680548301905560085460055433916108fc91811515610a2557fe5b04600254019081150290604051600060405180830381858888f19350505050158015610a55573d6000803e3d6000fd5b505050565b6004602052600090815260409020805460019091015482565b60025481565b6008548156fea165627a7a7230582074247f9b11636ce01e26bbc8ae6110533e405556f0b311bcb75db8c7f174b6a50029
Deployed ByteCode
0x6080604052600436106100df577c0100000000000000000000000000000000000000000000000000000000600035046322028a8481146100e95780632b807d37146100df578063319c068c146100fe57806347ce07cc14610125578063499159121461013a578063658f17881461016b578063712fcb511461018057806378601f39146101955780637b4b5d51146101c55780638da5cb5b146101e257806393c05a5b146101f7578063ac9d50d214610235578063ae46cc2714610268578063c094e0e314610298578063e93a3ff3146102e4578063fea0dd1d146102f9575b6100e761030e565b005b3480156100f557600080fd5b506100e7610318565b34801561010a57600080fd5b506101136103c8565b60408051918252519081900360200190f35b34801561013157600080fd5b506101136103ce565b34801561014657600080fd5b5061014f6103d4565b60408051600160a060020a039092168252519081900360200190f35b34801561017757600080fd5b506101136103e3565b34801561018c57600080fd5b506101136103e9565b3480156101a157600080fd5b50610113600480360360408110156101b857600080fd5b50803590602001356103ef565b6100e7600480360360208110156101db57600080fd5b50356104a7565b3480156101ee57600080fd5b5061014f610797565b34801561020357600080fd5b506102216004803603602081101561021a57600080fd5b50356107a6565b604080519115158252519081900360200190f35b34801561024157600080fd5b506100e76004803603602081101561025857600080fd5b5035600160a060020a03166107bb565b34801561027457600080fd5b506100e76004803603604081101561028b57600080fd5b5080359060200135610801565b3480156102a457600080fd5b506102cb600480360360208110156102bb57600080fd5b5035600160a060020a0316610a5a565b6040805192835260208301919091528051918290030190f35b3480156102f057600080fd5b50610113610a73565b34801561030557600080fd5b50610113610a79565b6005805434019055565b600154600160a060020a0316331461032f57600080fd5b3031600555600154604080517fb9802e3e0000000000000000000000000000000000000000000000000000000081529051600160a060020a039092169163b9802e3e91600480820192602092909190829003018186803b15801561039257600080fd5b505afa1580156103a6573d6000803e3d6000fd5b505050506040513d60208110156103bc57600080fd5b50516007556000600855565b60075481565b60065481565b600154600160a060020a031681565b60065490565b60055481565b60006002838360405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061044a5780518252601f19909201916020918201910161042b565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa158015610489573d6000803e3d6000fd5b5050506040513d602081101561049e57600080fd5b50519392505050565b6002543414610500576040805160e560020a62461bcd02815260206004820152601e60248201527f436f6c6c61746572616c20616d6f756e7420697320696e636f72726563740000604482015290519081900360640190fd5b60008181526003602052604090205460ff161561058d576040805160e560020a62461bcd02815260206004820152602e60248201527f5468697320656e74726f707920696e7075742077617320616c7265616479207560448201527f7365642070726576696f75736c79000000000000000000000000000000000000606482015290519081900360840190fd5b600754336000908152600460205260409020541061061b576040805160e560020a62461bcd02815260206004820152603960248201527f54686973206164647265737320697320616c726561647920616e20656e74726f60448201527f70792070726f766964657220696e207468697320726f756e6400000000000000606482015290519081900360840190fd5b600160009054906101000a9004600160a060020a0316600160a060020a031663a5b860046040518163ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040160206040518083038186803b15801561068557600080fd5b505afa158015610699573d6000803e3d6000fd5b505050506040513d60208110156106af57600080fd5b505160ff16600114610757576040805160e560020a62461bcd02815260206004820152604860248201527f456e74726f7079207375626d697373696f6e7320617265206f6e6c7920616c6c60448201527f6f77656420647572696e6720746865206465706f736974696e67206c6f74746560648201527f7279207068617365000000000000000000000000000000000000000000000000608482015290519081900360a40190fd5b6000818152600360209081526040808320805460ff1916600190811790915560075433855260049093529220908155810191909155600880549091019055565b600054600160a060020a031681565b60036020526000908152604090205460ff1681565b600054600160a060020a031633146107d257600080fd5b6001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b60075433600090815260046020526040902054146108b5576040805160e560020a62461bcd02815260206004820152604360248201527f546865206164647265737320697320747279696e6720746f2072657665616c2060448201527f74686520656e74726f707920666f7220696e617070726f70726961746520726f60648201527f756e640000000000000000000000000000000000000000000000000000000000608482015290519081900360a40190fd5b6004600033600160a060020a0316600160a060020a03168152602001908152602001600020600101546002838360405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b602083106109375780518252601f199092019160209182019101610918565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa158015610976573d6000803e3d6000fd5b5050506040513d602081101561098b57600080fd5b505114610a08576040805160e560020a62461bcd02815260206004820152602d60248201527f456e74726f70792076616c75657320646f206e6f74206d61746368207468652060448201527f70726f7669646564206861736800000000000000000000000000000000000000606482015290519081900360840190fd5b600680548301905560085460055433916108fc91811515610a2557fe5b04600254019081150290604051600060405180830381858888f19350505050158015610a55573d6000803e3d6000fd5b505050565b6004602052600090815260409020805460019091015482565b60025481565b6008548156fea165627a7a7230582074247f9b11636ce01e26bbc8ae6110533e405556f0b311bcb75db8c7f174b6a50029