Commit ba74f8a8 authored by mbaxter's avatar mbaxter Committed by GitHub

cannon: Port step post-checks to MIPS2.sol (#12815)

parent 56624482
......@@ -45,7 +45,7 @@
"outputs": [
{
"internalType": "bytes32",
"name": "",
"name": "postState_",
"type": "bytes32"
}
],
......
......@@ -144,8 +144,8 @@
"sourceCodeHash": "0xd8467700c80b3e62fa37193dc6513bac35282094b686b50e162e157f704dde00"
},
"src/cannon/MIPS2.sol": {
"initCodeHash": "0xaedf0d0b0e94a0c5e7d987331d2fdba84230f5704a6ca33677e70cde7051b17e",
"sourceCodeHash": "0x9fa2d1297ad1e93b4d3c5c0fed08bedcd8f746807589f0fd3369e79347c6a027"
"initCodeHash": "0xc38c76ab3aad78c81ca01b3235b402614972d6604b22fda1e870f1bf47be1194",
"sourceCodeHash": "0x3d38b1924669d1bde756f1306601c764a6d31f428ac72667a3dd194b3388210d"
},
"src/cannon/MIPS64.sol": {
"initCodeHash": "0x93aa8d7f9fd3c22276c0d303a3fefdf8f73cc55807b35e483bba64c92d02aaef",
......
......@@ -60,8 +60,8 @@ contract MIPS2 is ISemver {
}
/// @notice The semantic version of the MIPS2 contract.
/// @custom:semver 1.0.0-beta.21
string public constant version = "1.0.0-beta.21";
/// @custom:semver 1.0.0-beta.22
string public constant version = "1.0.0-beta.22";
/// @notice The preimage oracle contract.
IPreimageOracle internal immutable ORACLE;
......@@ -102,7 +102,39 @@ contract MIPS2 is ISemver {
/// the current thread stack.
/// @param _localContext The local key context for the preimage oracle. Optional, can be set as a constant
/// if the caller only requires one set of local keys.
function step(bytes calldata _stateData, bytes calldata _proof, bytes32 _localContext) public returns (bytes32) {
/// @return postState_ The hash of the post state witness after the state transition.
function step(
bytes calldata _stateData,
bytes calldata _proof,
bytes32 _localContext
)
public
returns (bytes32 postState_)
{
postState_ = doStep(_stateData, _proof, _localContext);
assertPostStateChecks();
}
function assertPostStateChecks() internal pure {
State memory state;
assembly {
state := STATE_MEM_OFFSET
}
bytes32 activeStack = state.traverseRight ? state.rightThreadStack : state.leftThreadStack;
if (activeStack == EMPTY_THREAD_ROOT) {
revert("MIPS2: post-state active thread stack is empty");
}
}
function doStep(
bytes calldata _stateData,
bytes calldata _proof,
bytes32 _localContext
)
internal
returns (bytes32)
{
unchecked {
State memory state;
ThreadState memory thread;
......
......@@ -46,7 +46,13 @@ interface IMIPS2 is ISemver {
error InvalidRMWInstruction();
function oracle() external view returns (IPreimageOracle oracle_);
function step(bytes memory _stateData, bytes memory _proof, bytes32 _localContext) external returns (bytes32);
function step(
bytes memory _stateData,
bytes memory _proof,
bytes32 _localContext
)
external
returns (bytes32 postState_);
function __constructor__(IPreimageOracle _oracle) external;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment