Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
mipsevm,contracts: reduce step arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
protolambda committed Jun 16, 2023
1 parent f9bcb58 commit d34f78a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
12 changes: 6 additions & 6 deletions contracts/src/MIPS.sol
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ contract MIPS {

function proofOffset(uint8 proofIndex) internal pure returns (uint256 offset) {
// A proof of 32 bit memory, with 32-byte leaf values, is (32-5)=27 bytes32 entries.
// And the leaf value itself needs to be encoded as well. And proof.offset == 390
offset = 390 + (uint256(proofIndex) * (28*32));
// And the leaf value itself needs to be encoded as well. And proof.offset == 358
offset = 358 + (uint256(proofIndex) * (28*32));
uint256 s = 0;
assembly { s := calldatasize() }
require(s >= (offset + 28*32), "check that there is enough calldata");
Expand Down Expand Up @@ -379,7 +379,7 @@ contract MIPS {
}

// will revert if any required input state is missing
function Step(bytes32 stateHash, bytes calldata stateData, bytes calldata proof) public returns (bytes32) {
function Step(bytes calldata stateData, bytes calldata proof) public returns (bytes32) {
State memory state;
// packed data is ~6 times smaller
assembly {
Expand All @@ -389,10 +389,10 @@ contract MIPS {
if iszero(eq(mload(0x40), mul(32, 48))) { // expected memory check
revert(0,0)
}
if iszero(eq(stateData.offset, 132)) { // 32*4+4=132 expected state data offset
if iszero(eq(stateData.offset, 100)) { // 32*3+4=100 expected state data offset
revert(0,0)
}
if iszero(eq(proof.offset, 390)) { // 132+32+226=390 expected proof offset
if iszero(eq(proof.offset, 358)) { // 100+32+226=358 expected proof offset
revert(0,0)
}
function putField(callOffset, memOffset, size) -> callOffsetOut, memOffsetOut {
Expand Down Expand Up @@ -420,7 +420,7 @@ contract MIPS {
for { let i := 0 } lt(i, 32) { i := add(i, 1) } { c, m := putField(c, m, 4) } // registers
}
if(state.exited) { // don't change state once exited
return stateHash;
return outputState();
}
state.step += 1;

Expand Down
2 changes: 1 addition & 1 deletion mipsevm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

var (
StepBytes4 = crypto.Keccak256([]byte("Step(bytes32,bytes,bytes)"))[:4]
StepBytes4 = crypto.Keccak256([]byte("Step(bytes,bytes)"))[:4]
CheatBytes4 = crypto.Keccak256([]byte("cheat(uint256,bytes32,bytes32,uint256)"))[:4]
LoadKeccak256PreimagePartBytes4 = crypto.Keccak256([]byte("loadKeccak256PreimagePart(uint256,bytes)"))[:4]
)
Expand Down
8 changes: 2 additions & 6 deletions mipsevm/witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"errors"
"fmt"

"github.com/ethereum/go-ethereum/crypto"

"github.com/ethereum-optimism/cannon/preimage"
)

Expand All @@ -28,12 +26,10 @@ func uint32ToBytes32(v uint32) []byte {
}

func (wit *StepWitness) EncodeStepInput() []byte {
stateHash := crypto.Keccak256Hash(wit.State)
var input []byte
input = append(input, StepBytes4...)
input = append(input, stateHash[:]...)
input = append(input, uint32ToBytes32(32*3)...) // state data offset in bytes
input = append(input, uint32ToBytes32(32*3+32+uint32(len(wit.State)))...) // proof data offset in bytes
input = append(input, uint32ToBytes32(32*2)...) // state data offset in bytes
input = append(input, uint32ToBytes32(32*2+32+uint32(len(wit.State)))...) // proof data offset in bytes

input = append(input, uint32ToBytes32(uint32(len(wit.State)))...) // state data length in bytes
input = append(input, wit.State[:]...)
Expand Down

0 comments on commit d34f78a

Please sign in to comment.