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

cannon: Add post-state checks (#12809)

* cannon: Add post-state assertions

* cannon: Bump MIPS64 contract version
parent 0eb090e1
......@@ -224,6 +224,23 @@ func (m *InstrumentedState) handleSyscall() error {
}
func (m *InstrumentedState) mipsStep() error {
err := m.doMipsStep()
if err != nil {
return err
}
m.assertPostStateChecks()
return err
}
func (m *InstrumentedState) assertPostStateChecks() {
activeStack := m.state.getActiveThreadStack()
if len(activeStack) == 0 {
panic("post-state active thread stack is empty")
}
}
func (m *InstrumentedState) doMipsStep() error {
if m.state.Exited {
return nil
}
......
......@@ -148,8 +148,8 @@
"sourceCodeHash": "0x9fa2d1297ad1e93b4d3c5c0fed08bedcd8f746807589f0fd3369e79347c6a027"
},
"src/cannon/MIPS64.sol": {
"initCodeHash": "0xc615a8f321f3bfb29c9459705f3012e512c463ba9ba2e1bcb6f9349f2d911d10",
"sourceCodeHash": "0x8fd0f4167d80f48010ad1241a9f6fb93576887dcc1f97be6b05adaf0086a537b"
"initCodeHash": "0x93aa8d7f9fd3c22276c0d303a3fefdf8f73cc55807b35e483bba64c92d02aaef",
"sourceCodeHash": "0x171d66c651fdad2ac9c287da92689815a5b09589945ada092179508ad2326306"
},
"src/cannon/PreimageOracle.sol": {
"initCodeHash": "0x5d7e8ae64f802bd9d760e3d52c0a620bd02405dc2c8795818db9183792ffe81c",
......
......@@ -45,7 +45,7 @@
"outputs": [
{
"internalType": "bytes32",
"name": "",
"name": "postState_",
"type": "bytes32"
}
],
......
......@@ -64,8 +64,8 @@ contract MIPS64 is ISemver {
}
/// @notice The semantic version of the MIPS64 contract.
/// @custom:semver 1.0.0-beta.3
string public constant version = "1.0.0-beta.3";
/// @custom:semver 1.0.0-beta.4
string public constant version = "1.0.0-beta.4";
/// @notice The preimage oracle contract.
IPreimageOracle internal immutable ORACLE;
......@@ -106,7 +106,39 @@ contract MIPS64 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("MIPS64: 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;
......
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