Commit d34f78a0 authored by protolambda's avatar protolambda

mipsevm,contracts: reduce step arguments

parent f9bcb588
...@@ -310,8 +310,8 @@ contract MIPS { ...@@ -310,8 +310,8 @@ contract MIPS {
function proofOffset(uint8 proofIndex) internal pure returns (uint256 offset) { 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. // 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 // And the leaf value itself needs to be encoded as well. And proof.offset == 358
offset = 390 + (uint256(proofIndex) * (28*32)); offset = 358 + (uint256(proofIndex) * (28*32));
uint256 s = 0; uint256 s = 0;
assembly { s := calldatasize() } assembly { s := calldatasize() }
require(s >= (offset + 28*32), "check that there is enough calldata"); require(s >= (offset + 28*32), "check that there is enough calldata");
...@@ -379,7 +379,7 @@ contract MIPS { ...@@ -379,7 +379,7 @@ contract MIPS {
} }
// will revert if any required input state is missing // 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; State memory state;
// packed data is ~6 times smaller // packed data is ~6 times smaller
assembly { assembly {
...@@ -389,10 +389,10 @@ contract MIPS { ...@@ -389,10 +389,10 @@ contract MIPS {
if iszero(eq(mload(0x40), mul(32, 48))) { // expected memory check if iszero(eq(mload(0x40), mul(32, 48))) { // expected memory check
revert(0,0) 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) 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) revert(0,0)
} }
function putField(callOffset, memOffset, size) -> callOffsetOut, memOffsetOut { function putField(callOffset, memOffset, size) -> callOffsetOut, memOffsetOut {
...@@ -420,7 +420,7 @@ contract MIPS { ...@@ -420,7 +420,7 @@ contract MIPS {
for { let i := 0 } lt(i, 32) { i := add(i, 1) } { c, m := putField(c, m, 4) } // registers 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 if(state.exited) { // don't change state once exited
return stateHash; return outputState();
} }
state.step += 1; state.step += 1;
......
...@@ -21,7 +21,7 @@ import ( ...@@ -21,7 +21,7 @@ import (
) )
var ( 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] CheatBytes4 = crypto.Keccak256([]byte("cheat(uint256,bytes32,bytes32,uint256)"))[:4]
LoadKeccak256PreimagePartBytes4 = crypto.Keccak256([]byte("loadKeccak256PreimagePart(uint256,bytes)"))[:4] LoadKeccak256PreimagePartBytes4 = crypto.Keccak256([]byte("loadKeccak256PreimagePart(uint256,bytes)"))[:4]
) )
......
...@@ -5,8 +5,6 @@ import ( ...@@ -5,8 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum-optimism/cannon/preimage" "github.com/ethereum-optimism/cannon/preimage"
) )
...@@ -28,12 +26,10 @@ func uint32ToBytes32(v uint32) []byte { ...@@ -28,12 +26,10 @@ func uint32ToBytes32(v uint32) []byte {
} }
func (wit *StepWitness) EncodeStepInput() []byte { func (wit *StepWitness) EncodeStepInput() []byte {
stateHash := crypto.Keccak256Hash(wit.State)
var input []byte var input []byte
input = append(input, StepBytes4...) input = append(input, StepBytes4...)
input = append(input, stateHash[:]...) input = append(input, uint32ToBytes32(32*2)...) // state data offset in bytes
input = append(input, uint32ToBytes32(32*3)...) // 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(32*3+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, uint32ToBytes32(uint32(len(wit.State)))...) // state data length in bytes
input = append(input, wit.State[:]...) input = append(input, wit.State[:]...)
......
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