Skip to content

Commit

Permalink
MIPS2 port
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby committed Aug 9, 2024
1 parent c880c01 commit 21d6ff5
Show file tree
Hide file tree
Showing 6 changed files with 2,252 additions and 2,220 deletions.
33 changes: 33 additions & 0 deletions packages/contracts-bedrock/scripts/go-ffi/differential-testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,39 @@ func DiffTestUtils() {
}
insnProof = mem.MerkleProof(uint64(pc))

output := struct {
MemRoot common.Hash
Proof []byte
}{
MemRoot: mem.MerkleRoot(),
Proof: append(insnProof[:], memProof[:]...),
}
packed, err := cannonMemoryProofArgs.Pack(&output)
checkErr(err, "Error encoding output")
fmt.Print(hexutil.Encode(packed[32:]))
case "cannonMemoryProofDoubleWord":
// <pc, insn, [memAddr, memValue]>
mem := memory.NewMemory()
if len(args) != 3 && len(args) != 5 {
panic("Error: cannonMemoryProofWithProof requires 2 or 4 arguments")
}
pc, err := strconv.ParseUint(args[1], 10, 64)
checkErr(err, "Error decoding addr")
insn, err := strconv.ParseUint(args[2], 10, 32)
checkErr(err, "Error decoding insn")
mem.SetMemory(uint64(pc), uint32(insn))

var insnProof, memProof [1920]byte
if len(args) == 5 {
memAddr, err := strconv.ParseUint(args[3], 10, 64)
checkErr(err, "Error decoding memAddr")
memValue, err := strconv.ParseUint(args[4], 10, 64)
checkErr(err, "Error decoding memValue")
mem.SetDoubleWord(uint64(memAddr), uint64(memValue))
memProof = mem.MerkleProof(uint64(memAddr))
}
insnProof = mem.MerkleProof(uint64(pc))

output := struct {
MemRoot common.Hash
Proof []byte
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-bedrock/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@
"sourceCodeHash": "0xbd549332b7575b575dc3d1e2e4b03b347a8b3757d6bafc36e69a8311878f018e"
},
"src/cannon/MIPS2.sol": {
"initCodeHash": "0x19c1d081a5c86f44896a3d61f5033fefcf8a1cd3fb94121db8b414099f231d9e",
"sourceCodeHash": "0x12848e0b5e30a51f503f21d6e0b480194781960005d04c46afb3742180b1466c"
"initCodeHash": "0x47bac0d5d2f8f341664e8dbe4804eba6b3c0e5abbdab93caee45ce25629804d1",
"sourceCodeHash": "0x12abe148bd6d909d16df876d4f390fe77f22a433238655c4a27c67ab1bbdd81b"
},
"src/cannon/PreimageOracle.sol": {
"initCodeHash": "0xe5db668fe41436f53995e910488c7c140766ba8745e19743773ebab508efd090",
Expand Down
10 changes: 5 additions & 5 deletions packages/contracts-bedrock/src/cannon/MIPS2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ contract MIPS2 is ISemver {
uint256 internal constant THREAD_PROOF_OFFSET = 356;

// The offset of the start of proof calldata (_memProof.offset) in the step() function
uint256 internal constant MEM_PROOF_OFFSET = THREAD_PROOF_OFFSET + 166 + 32;
uint256 internal constant MEM_PROOF_OFFSET = THREAD_PROOF_OFFSET + 322 + 32;

// The empty thread root - keccak256(bytes32(0) ++ bytes32(0))
bytes32 internal constant EMPTY_THREAD_ROOT = hex"ad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5";
Expand Down Expand Up @@ -187,7 +187,7 @@ contract MIPS2 is ISemver {
// timeout! Allow execution
return onWaitComplete(state, thread, true);
} else {
uint32 mem = MIPSMemory.readMem(
uint64 mem = MIPSMemory.readMemDoubleword(
state.memRoot,
thread.futexAddr & 0xFFFFFFFFFFFFFFF8,
MIPSMemory.memoryProofOffset(MEM_PROOF_OFFSET, 1)
Expand Down Expand Up @@ -694,7 +694,7 @@ contract MIPS2 is ISemver {
s := calldatasize()
}
// verify we have enough calldata
require(s >= (THREAD_PROOF_OFFSET + 166), "insufficient calldata for thread witness");
require(s >= (THREAD_PROOF_OFFSET + 322), "insufficient calldata for thread witness");

unchecked {
assembly {
Expand Down Expand Up @@ -730,9 +730,9 @@ contract MIPS2 is ISemver {
uint256 s = 0;
assembly {
s := calldatasize()
innerThreadRoot_ := calldataload(add(THREAD_PROOF_OFFSET, 166))
innerThreadRoot_ := calldataload(add(THREAD_PROOF_OFFSET, 322))
}
// verify we have enough calldata
require(s >= (THREAD_PROOF_OFFSET + 198), "insufficient calldata for thread witness"); // 166 + 32
require(s >= (THREAD_PROOF_OFFSET + 322), "insufficient calldata for thread witness"); // 356 + 32
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ library MIPSInstructions {
uint64 _fun
)
internal
pure
returns (bytes32 newMemRoot_)
{
unchecked {
Expand Down Expand Up @@ -182,6 +183,7 @@ library MIPSInstructions {
uint64 _mem
)
internal
pure
returns (uint64 out_)
{
unchecked {
Expand Down
Loading

0 comments on commit 21d6ff5

Please sign in to comment.