You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
eip: <to be assigned>
title: Practical Randomness via Dual Contract
author: Yao-Chieh Hu (@yhuag) <yhuag@connect.ust.hk>, Ting-Ting Lee (@tina1998612) <tleeae@connect.ust.hk>
status: Draft
type: Standards Track
category: ERC
created: 2019-02-17
Simple Summary
A proposal for achieving "nearly" non-predictable randomness via two smart contracts.
Abstract
There are two smart contracts: Main.sol and Randomness.sol.
Main.sol generates a random number by submitting a main_seed to Randomness.sol, which is derived from msg.data, msg.sender, and an arbitrary number salt. Randomness.sol takes in main_seed to mix with its rand_seed inside a random function that is embedded with a func_seed. During each round of the random number generation, the rand_seed is updated according to main_seed.
Correctness
Since that we only expose the Main.sol code, the Randomness.sol code remains invisible. The security level escalates from known-plaintext attack to ciphertext-only attack. Any attempt towards the Randomeness.col can only change the state of it without making it a feasible "key-value" pair in any time of future.
Though we are free to get the private rand_seed in the Randomness.sol (I wrote a tutorial for that if interested), it could be hard to retrieve the func_seed inside the random function.
The Randomness.sol's random function has been made as owner only via OpenZeppelin's Ownable.sol, so it makes it harder for submitting an external attempt for trials.
Disclaimer
Please think twice before using it on some profitable projects. I am really looking forward to any comment and suggestion. Thanks. :)
Specification
Main.sol
pragma solidity ^0.4.25;
import { Ownable } from "./openzeppelin-solidity/contracts/ownership/Ownable.sol";
import { Randomness } from "./Randomness.sol";
contract Main is Ownable {
Randomness randomnessContract;
// ... SOME CRAZY LOGICS
// Random Function (free to use it any where)
function _random(uint256 _salt) internal returns (uint256) {
return uint256(randomnessContract.rand(
keccak256(
abi.encodePacked(
msg.data,
msg.sender,
_salt
)
)
));
}
}
Randomness.sol
THIS SHOULD BE HIDDEN FROM THE PUBLIC
pragma solidity ^0.4.25;
import { Ownable } from "./openzeppelin-solidity/contracts/ownership/Ownable.sol";
contract Randomness is Ownable {
bytes32 private rand_seed = "hحَi";
function rand(bytes32 key) public onlyOwner returns (bytes32) {
rand_seed ^= key;
// That super wierd string below is the func_seed
return keccak256(abi.encodePacked(key, rand_seed, "台灣きन्दी한حَNo.1 :) "));
}
}
What if we add a private seed to the contract? The resulting random number can be computed with a passed variable and the privately stored seed as inputs. However, this approach does not consider the impossibility to store private data inside a public network. Despite Ethereum having a concept of private memory in smart contracts, this storage can still be read by anyone running an Ethereum node. Reading private or internal state can be achieved by web3.eth.getStorageAt. Therefore, it merely increases the effort for someone trying to predict the randomness.
-->
Please think twice before using it on some profitable projects.
There has been no activity on this issue for two months. It will be closed in a week if no further activity occurs. If you would like to move this EIP forward, please respond to any outstanding feedback or add a comment indicating that you have addressed all required feedback and are ready for a review.
This issue was closed due to inactivity. If you are still pursuing it, feel free to reopen it and respond to any feedback or request a review in a comment.
Simple Summary
A proposal for achieving "nearly" non-predictable randomness via two smart contracts.
Abstract
There are two smart contracts:
Main.sol
andRandomness.sol
.Main.sol
generates a random number by submitting a main_seed toRandomness.sol
, which is derived frommsg.data
,msg.sender
, and an arbitrary numbersalt
.Randomness.sol
takes in main_seed to mix with its rand_seed inside a random function that is embedded with a func_seed. During each round of the random number generation, the rand_seed is updated according to main_seed.Correctness
Since that we only expose the
Main.sol
code, theRandomness.sol
code remains invisible. The security level escalates from known-plaintext attack to ciphertext-only attack. Any attempt towards theRandomeness.col
can only change the state of it without making it a feasible "key-value" pair in any time of future.Though we are free to get the private rand_seed in the
Randomness.sol
(I wrote a tutorial for that if interested), it could be hard to retrieve the func_seed inside the random function.The
Randomness.sol
's random function has been made as owner only via OpenZeppelin'sOwnable.sol
, so it makes it harder for submitting an external attempt for trials.Disclaimer
Please think twice before using it on some profitable projects. I am really looking forward to any comment and suggestion. Thanks. :)
Specification
Main.sol
Randomness.sol
Copyright
Copyright and related rights waived via MIT.
The text was updated successfully, but these errors were encountered: