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.17+commit.d19bba13
- Optimization runs
- 200
- EVM Version
- default
- Verified at
- 2024-09-26T15:31:26.886602Z
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 = 0xc6355B64cd7C7552BF555599645B91858f3c37fE;
struct provider
{
uint256 round;
bytes32 entropy_hash;
}
uint256 public collateral_threshold = 100000 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);
_;
}
}
Contract ABI
[{"type":"fallback","stateMutability":"payable","payable":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"collateral_threshold","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"current_round","inputs":[],"constant":true},{"type":"function","stateMutability":"payable","payable":true,"outputs":[],"name":"deposit_entropy_reward","inputs":[],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"entropy","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"round","internalType":"uint256"},{"type":"bytes32","name":"entropy_hash","internalType":"bytes32"}],"name":"entropy_providers","inputs":[{"type":"address","name":"","internalType":"address"}],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"entropy_reward","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"get_entropy","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"lottery_contract","inputs":[],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"new_round","inputs":[],"constant":false},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"num_providers","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[],"constant":true},{"type":"function","stateMutability":"view","payable":false,"outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"prohibited_hashes","inputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"constant":true},{"type":"function","stateMutability":"nonpayable","payable":false,"outputs":[],"name":"reveal_entropy","inputs":[{"type":"uint256","name":"_entropy_payload","internalType":"uint256"},{"type":"uint256","name":"_salt","internalType":"uint256"}],"constant":false},{"type":"function","stateMutability":"payable","payable":true,"outputs":[],"name":"submit_entropy","inputs":[{"type":"bytes32","name":"_entropy_hash","internalType":"bytes32"}],"constant":false},{"type":"function","stateMutability":"pure","payable":false,"outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"test_hash","inputs":[{"type":"uint256","name":"_entropy_payload","internalType":"uint256"},{"type":"uint256","name":"_salt","internalType":"uint256"}],"constant":true}]
Contract Creation Code
0x6080604052600080546001600160a01b0319908116331782556001805490911673c6355b64cd7c7552bf555599645b91858f3c37fe17905569152d02c7e14af680000060025560058190556006819055600781905560085534801561006357600080fd5b50610a94806100736000396000f3fe6080604052600436106100e85760003560e01c806378601f391161008a578063ae46cc2711610059578063ae46cc271461023e578063c094e0e31461026e578063e93a3ff3146102ba578063fea0dd1d146102cf576100e8565b806378601f391461019e5780637b4b5d51146101ce5780638da5cb5b146101eb57806393c05a5b14610200576100e8565b806347ce07cc116100c657806347ce07cc1461012e5780634991591214610143578063658f178814610174578063712fcb5114610189576100e8565b806322028a84146100f25780632b807d37146100e8578063319c068c14610107575b6100f06102e4565b005b3480156100fe57600080fd5b506100f06102ee565b34801561011357600080fd5b5061011c610384565b60408051918252519081900360200190f35b34801561013a57600080fd5b5061011c61038a565b34801561014f57600080fd5b50610158610390565b604080516001600160a01b039092168252519081900360200190f35b34801561018057600080fd5b5061011c61039f565b34801561019557600080fd5b5061011c6103a5565b3480156101aa57600080fd5b5061011c600480360360408110156101c157600080fd5b50803590602001356103ab565b6100f0600480360360208110156101e457600080fd5b5035610463565b3480156101f757600080fd5b50610158610651565b34801561020c57600080fd5b5061022a6004803603602081101561022357600080fd5b5035610660565b604080519115158252519081900360200190f35b34801561024a57600080fd5b506100f06004803603604081101561026157600080fd5b5080359060200135610675565b34801561027a57600080fd5b506102a16004803603602081101561029157600080fd5b50356001600160a01b03166108e3565b6040805192835260208301919091528051918290030190f35b3480156102c657600080fd5b5061011c6108fc565b3480156102db57600080fd5b5061011c610902565b6005805434019055565b6001546001600160a01b0316331461030557600080fd5b4760055560015460408051635cc0171f60e11b815290516001600160a01b039092169163b9802e3e91600480820192602092909190829003018186803b15801561034e57600080fd5b505afa158015610362573d6000803e3d6000fd5b505050506040513d602081101561037857600080fd5b50516007556000600855565b60075481565b60065481565b6001546001600160a01b031681565b60065490565b60055481565b60006002838360405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b602083106104065780518252601f1990920191602091820191016103e7565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa158015610445573d6000803e3d6000fd5b5050506040513d602081101561045a57600080fd5b50519392505050565b60025434146104b9576040805162461bcd60e51b815260206004820152601e60248201527f436f6c6c61746572616c20616d6f756e7420697320696e636f72726563740000604482015290519081900360640190fd5b60008181526003602052604090205460ff16156105075760405162461bcd60e51b815260040180806020018281038252602e8152602001806109fa602e913960400191505060405180910390fd5b60075433600090815260046020526040902054106105565760405162461bcd60e51b81526004018080602001828103825260398152602001806109096039913960400191505060405180910390fd5b600160009054906101000a90046001600160a01b03166001600160a01b031663a5b860046040518163ffffffff1660e01b815260040160206040518083038186803b1580156105a457600080fd5b505afa1580156105b8573d6000803e3d6000fd5b505050506040513d60208110156105ce57600080fd5b505160ff166001146106115760405162461bcd60e51b81526004018080602001828103825260488152602001806109b26048913960600191505060405180910390fd5b6000818152600360209081526040808320805460ff1916600190811790915560075433855260049093529220908155810191909155600880549091019055565b6000546001600160a01b031681565b60036020526000908152604090205460ff1681565b60075433600090815260046020526040902054146106c45760405162461bcd60e51b815260040180806020018281038252604381526020018061096f6043913960600191505060405180910390fd5b60046000336001600160a01b03166001600160a01b03168152602001908152602001600020600101546002838360405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b602083106107465780518252601f199092019160209182019101610727565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa158015610785573d6000803e3d6000fd5b5050506040513d602081101561079a57600080fd5b5051146107d85760405162461bcd60e51b815260040180806020018281038252602d815260200180610942602d913960400191505060405180910390fd5b600160009054906101000a90046001600160a01b03166001600160a01b031663a5b860046040518163ffffffff1660e01b815260040160206040518083038186803b15801561082657600080fd5b505afa15801561083a573d6000803e3d6000fd5b505050506040513d602081101561085057600080fd5b505160ff166002146108935760405162461bcd60e51b8152600401808060200182810382526038815260200180610a286038913960400191505060405180910390fd5b600680548301905560085460055433916108fc91816108ae57fe5b04600254019081150290604051600060405180830381858888f193505050501580156108de573d6000803e3d6000fd5b505050565b6004602052600090815260409020805460019091015482565b60025481565b6008548156fe54686973206164647265737320697320616c726561647920616e20656e74726f70792070726f766964657220696e207468697320726f756e64456e74726f70792076616c75657320646f206e6f74206d61746368207468652070726f76696465642068617368546865206164647265737320697320747279696e6720746f2072657665616c2074686520656e74726f707920666f7220696e617070726f70726961746520726f756e64456e74726f7079207375626d697373696f6e7320617265206f6e6c7920616c6c6f77656420647572696e6720746865206465706f736974696e67206c6f74746572792070686173655468697320656e74726f707920696e7075742077617320616c726561647920757365642070726576696f75736c79456e74726f70792072657665616c7320617265206f6e6c7920616c6c6f77656420647572696e67207468652072657665616c207068617365a265627a7a723158206b52cd3daf8b44f6f752da9cdcc935d8b744e9ca93a2e7fcdce5539f0b3a396e64736f6c63430005110032
Deployed ByteCode
0x6080604052600436106100e85760003560e01c806378601f391161008a578063ae46cc2711610059578063ae46cc271461023e578063c094e0e31461026e578063e93a3ff3146102ba578063fea0dd1d146102cf576100e8565b806378601f391461019e5780637b4b5d51146101ce5780638da5cb5b146101eb57806393c05a5b14610200576100e8565b806347ce07cc116100c657806347ce07cc1461012e5780634991591214610143578063658f178814610174578063712fcb5114610189576100e8565b806322028a84146100f25780632b807d37146100e8578063319c068c14610107575b6100f06102e4565b005b3480156100fe57600080fd5b506100f06102ee565b34801561011357600080fd5b5061011c610384565b60408051918252519081900360200190f35b34801561013a57600080fd5b5061011c61038a565b34801561014f57600080fd5b50610158610390565b604080516001600160a01b039092168252519081900360200190f35b34801561018057600080fd5b5061011c61039f565b34801561019557600080fd5b5061011c6103a5565b3480156101aa57600080fd5b5061011c600480360360408110156101c157600080fd5b50803590602001356103ab565b6100f0600480360360208110156101e457600080fd5b5035610463565b3480156101f757600080fd5b50610158610651565b34801561020c57600080fd5b5061022a6004803603602081101561022357600080fd5b5035610660565b604080519115158252519081900360200190f35b34801561024a57600080fd5b506100f06004803603604081101561026157600080fd5b5080359060200135610675565b34801561027a57600080fd5b506102a16004803603602081101561029157600080fd5b50356001600160a01b03166108e3565b6040805192835260208301919091528051918290030190f35b3480156102c657600080fd5b5061011c6108fc565b3480156102db57600080fd5b5061011c610902565b6005805434019055565b6001546001600160a01b0316331461030557600080fd5b4760055560015460408051635cc0171f60e11b815290516001600160a01b039092169163b9802e3e91600480820192602092909190829003018186803b15801561034e57600080fd5b505afa158015610362573d6000803e3d6000fd5b505050506040513d602081101561037857600080fd5b50516007556000600855565b60075481565b60065481565b6001546001600160a01b031681565b60065490565b60055481565b60006002838360405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b602083106104065780518252601f1990920191602091820191016103e7565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa158015610445573d6000803e3d6000fd5b5050506040513d602081101561045a57600080fd5b50519392505050565b60025434146104b9576040805162461bcd60e51b815260206004820152601e60248201527f436f6c6c61746572616c20616d6f756e7420697320696e636f72726563740000604482015290519081900360640190fd5b60008181526003602052604090205460ff16156105075760405162461bcd60e51b815260040180806020018281038252602e8152602001806109fa602e913960400191505060405180910390fd5b60075433600090815260046020526040902054106105565760405162461bcd60e51b81526004018080602001828103825260398152602001806109096039913960400191505060405180910390fd5b600160009054906101000a90046001600160a01b03166001600160a01b031663a5b860046040518163ffffffff1660e01b815260040160206040518083038186803b1580156105a457600080fd5b505afa1580156105b8573d6000803e3d6000fd5b505050506040513d60208110156105ce57600080fd5b505160ff166001146106115760405162461bcd60e51b81526004018080602001828103825260488152602001806109b26048913960600191505060405180910390fd5b6000818152600360209081526040808320805460ff1916600190811790915560075433855260049093529220908155810191909155600880549091019055565b6000546001600160a01b031681565b60036020526000908152604090205460ff1681565b60075433600090815260046020526040902054146106c45760405162461bcd60e51b815260040180806020018281038252604381526020018061096f6043913960600191505060405180910390fd5b60046000336001600160a01b03166001600160a01b03168152602001908152602001600020600101546002838360405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b602083106107465780518252601f199092019160209182019101610727565b51815160209384036101000a60001901801990921691161790526040519190930194509192505080830381855afa158015610785573d6000803e3d6000fd5b5050506040513d602081101561079a57600080fd5b5051146107d85760405162461bcd60e51b815260040180806020018281038252602d815260200180610942602d913960400191505060405180910390fd5b600160009054906101000a90046001600160a01b03166001600160a01b031663a5b860046040518163ffffffff1660e01b815260040160206040518083038186803b15801561082657600080fd5b505afa15801561083a573d6000803e3d6000fd5b505050506040513d602081101561085057600080fd5b505160ff166002146108935760405162461bcd60e51b8152600401808060200182810382526038815260200180610a286038913960400191505060405180910390fd5b600680548301905560085460055433916108fc91816108ae57fe5b04600254019081150290604051600060405180830381858888f193505050501580156108de573d6000803e3d6000fd5b505050565b6004602052600090815260409020805460019091015482565b60025481565b6008548156fe54686973206164647265737320697320616c726561647920616e20656e74726f70792070726f766964657220696e207468697320726f756e64456e74726f70792076616c75657320646f206e6f74206d61746368207468652070726f76696465642068617368546865206164647265737320697320747279696e6720746f2072657665616c2074686520656e74726f707920666f7220696e617070726f70726961746520726f756e64456e74726f7079207375626d697373696f6e7320617265206f6e6c7920616c6c6f77656420647572696e6720746865206465706f736974696e67206c6f74746572792070686173655468697320656e74726f707920696e7075742077617320616c726561647920757365642070726576696f75736c79456e74726f70792072657665616c7320617265206f6e6c7920616c6c6f77656420647572696e67207468652072657665616c207068617365a265627a7a723158206b52cd3daf8b44f6f752da9cdcc935d8b744e9ca93a2e7fcdce5539f0b3a396e64736f6c63430005110032