-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add initial StateTransitioner & FraudProver #156
Changes from all commits
148bc00
0c7a2c4
38f7842
f9c0736
b172f26
ce7221b
ea7f844
a35a34d
548a209
40ed3a3
94fc0c5
7704cf7
1a62772
bbca98f
9936120
73fae93
5c1e834
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,30 +11,12 @@ import {SafetyChecker} from "./SafetyChecker.sol"; | |
* of all chain storage. | ||
*/ | ||
contract FullStateManager is StateManager { | ||
// Add Safety Checker contract | ||
SafetyChecker safetyChecker; | ||
// for testing: if true, then do not perform safety checking on init code or deployed bytecode | ||
bool overrideSafetyChecker; | ||
|
||
address ZERO_ADDRESS = 0x0000000000000000000000000000000000000000; | ||
|
||
mapping(address=>mapping(bytes32=>bytes32)) ovmContractStorage; | ||
mapping(address=>uint) ovmContractNonces; | ||
mapping(address=>address) ovmCodeContracts; | ||
|
||
/** | ||
* @notice Construct a new FullStateManager with a specified safety checker. | ||
* @param _opcodeWhitelistMask A bit mask representing which opcodes are whitelisted or not for our safety checker | ||
* @param _overrideSafetyChecker Set to true to disable safety checking (WARNING: Only do this in test environments) | ||
*/ | ||
constructor(uint256 _opcodeWhitelistMask, bool _overrideSafetyChecker) public { | ||
// Set override safety checker flag | ||
overrideSafetyChecker = _overrideSafetyChecker; | ||
// Set the safety checker address -- NOTE: `msg.sender` is used as EM address because we assume | ||
// the FullStateManager is deployed by the ExecutionManager | ||
safetyChecker = new SafetyChecker(_opcodeWhitelistMask, msg.sender); | ||
} | ||
|
||
|
||
/********** | ||
* Storage * | ||
|
@@ -104,7 +86,7 @@ contract FullStateManager is StateManager { | |
* @param _ovmContractAddress The address of the OVM contract we'd like to associate with some code. | ||
* @param _codeContractAddress The address of the code contract that's been deployed. | ||
*/ | ||
function associateCodeContract(address _ovmContractAddress, address _codeContractAddress) external { | ||
function associateCodeContract(address _ovmContractAddress, address _codeContractAddress) public { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be authenticated? Would expect only the Fraud Verifier to be able to populate these associations. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, whoops, I see that this isn't the PSM. Will just resurface the nit/bikeshed that |
||
ovmCodeContracts[_ovmContractAddress] = _codeContractAddress; | ||
} | ||
|
||
|
@@ -150,39 +132,4 @@ contract FullStateManager is StateManager { | |
_codeContractHash = keccak256(codeContractBytecode); | ||
return _codeContractHash; | ||
} | ||
|
||
/** | ||
* @notice Deploys a code contract, and then registers it to the state | ||
* @param _newOvmContractAddress The contract address to deploy the new contract to | ||
* @param _ovmContractInitcode The bytecode of the contract to be deployed | ||
* @return the codeContractAddress. | ||
*/ | ||
function deployContract( | ||
address _newOvmContractAddress, | ||
bytes memory _ovmContractInitcode | ||
) public returns(address codeContractAddress) { | ||
// Safety check the initcode, unless the overrideSafetyChecker flag is set to true | ||
if (!overrideSafetyChecker && !safetyChecker.isBytecodeSafe(_ovmContractInitcode)) { | ||
// Contract initcode is not pure. | ||
return ZERO_ADDRESS; | ||
} | ||
|
||
// Deploy a new contract with this _ovmContractInitCode | ||
assembly { | ||
// Set our codeContractAddress to the address returned by our CREATE operation | ||
codeContractAddress := create(0, add(_ovmContractInitcode, 0x20), mload(_ovmContractInitcode)) | ||
// Make sure that the CREATE was successful (actually deployed something) | ||
if iszero(extcodesize(codeContractAddress)) { | ||
revert(0, 0) | ||
} | ||
} | ||
|
||
// Safety check the runtime bytecode, unless the overrideSafetyChecker flag is set to true | ||
bytes memory codeContractBytecode = getCodeContractBytecode(codeContractAddress); | ||
if (!overrideSafetyChecker && !safetyChecker.isBytecodeSafe(codeContractBytecode)) { | ||
// Contract runtime bytecode is not pure. | ||
return ZERO_ADDRESS; | ||
} | ||
return codeContractAddress; | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
import {StateTransitioner} from "./StateTransitioner.sol"; | ||
|
||
/** | ||
* @title FraudVerifier | ||
* @notice The contract which is able to delete invalid state roots. | ||
*/ | ||
contract FraudVerifier { | ||
mapping(uint=>StateTransitioner) stateTransitioners; | ||
|
||
function initNewStateTransitioner(uint _preStateTransitionIndex) public returns(bool) { | ||
// TODO: | ||
// Create a new state transitioner for some specific pre-state transition index (assuming one hasn't already been made). | ||
// Note that the invalid state root that we are verifying is at _preStateTransitionIndex+1. | ||
// Add it to the stateTransitioners mapping! -- stateTransitioners[_preStateTransitionIndex] = newStateTransitioner; | ||
return true; | ||
} | ||
|
||
|
||
function verifyFraud(uint _transitionIndex) public returns(bool) { | ||
// TODO: | ||
// Simply verify that the state transitioner has completed, and that the state root | ||
// at _preStateTransitionIndex+1 is not equal to the state root which was committed for that index. | ||
return true; | ||
} | ||
Comment on lines
+21
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that in the current contracts I believe that the |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this function meant to be atomically called before
executeTransaction
? If so, might be able to move that logic there in a future PR. If not atomic, do we need to authenticate that it's coming from the fraud prover?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i totally agree we might as well put it into
executeTransaction(..)
itself