Skip to content

Commit

Permalink
MIPS2.sol MT-FPVM Implementation (#11036)
Browse files Browse the repository at this point in the history
* cannon: MIPS2 MT-FPVM contract

Add a smart contract implementing the multi-threaded Cannon

* Update packages/contracts-bedrock/src/cannon/libraries/MIPSSyscalls.sol

Co-authored-by: mbaxter <meredith@oplabs.co>

* cannon: Use common constant for BRK_START

* cannon: Define new constant FUTEX_EMPTY_ADDR

* cannon: Add SYS_ERROR_SIGNAL constant, fix futex wait ret val

* dedup syscall handling; rename timeout

* fix sys_clone bug

* use handler functions in onWaitComplete

* fix nits

* fix ETIMEDOUT constant

* remove leftover console import

* traverse right if left is empty on futex_wake syscall

* Update packages/contracts-bedrock/test/cannon/MIPS2.t.sol

Co-authored-by: mbaxter <meredith@oplabs.co>

* fix traverseRight updates at popThread

* exit syscall is exit_group if last thread

* simplify wakeup logic; traverse fully before any other operation

* remove dup logic for wakeup traversal end

* fuzz thread.exited in wakeup tests

* update semver-lock; abi snapshots

* implement unused syscalls

* rebase; fix clone args

* update semver-lock

* handle munmap

* add comment on unimplemented syscalls

* add mising snapshots

---------

Co-authored-by: mbaxter <meredith@oplabs.co>
  • Loading branch information
Inphi and mbaxter authored Jul 29, 2024
1 parent 55b3e49 commit d837696
Show file tree
Hide file tree
Showing 13 changed files with 3,150 additions and 81 deletions.
8 changes: 6 additions & 2 deletions packages/contracts-bedrock/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@
"sourceCodeHash": "0x3ff4a3f21202478935412d47fd5ef7f94a170402ddc50e5c062013ce5544c83f"
},
"src/cannon/MIPS.sol": {
"initCodeHash": "0xe2cfbfa5d8587a6c3cf52686e29fb0d07e2764af0ef728825529f42ebdeacb5d",
"sourceCodeHash": "0x231f42a05f0c8e5784eb112518afca0bb16a3689f317ce021b8390a0aa70377b"
"initCodeHash": "0x644a4167210bee38884419c2af618f3cf9533f959bda41aad3cfed4b6f325b1b",
"sourceCodeHash": "0xe28a16aad04ebcadba631a1920cac6e492c18f0d866836610be22779f3f04bfc"
},
"src/cannon/MIPS2.sol": {
"initCodeHash": "0xdcd3bd4bbf8c119ca2d8a435da322ecc5c55a9e2a308789064bf19105933aa6c",
"sourceCodeHash": "0xa1406c94c785b094432aed8af2e1c5b42644e2a0878d48f89b488138e079ee66"
},
"src/cannon/PreimageOracle.sol": {
"initCodeHash": "0xe5db668fe41436f53995e910488c7c140766ba8745e19743773ebab508efd090",
Expand Down
13 changes: 0 additions & 13 deletions packages/contracts-bedrock/snapshots/abi/MIPS.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "BRK_START",
"outputs": [
{
"internalType": "uint32",
"name": "",
"type": "uint32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "oracle",
Expand Down
55 changes: 55 additions & 0 deletions packages/contracts-bedrock/snapshots/abi/MIPS2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[
{
"inputs": [
{
"internalType": "contract IPreimageOracle",
"name": "_oracle",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [
{
"internalType": "bytes",
"name": "_stateData",
"type": "bytes"
},
{
"internalType": "bytes",
"name": "_proof",
"type": "bytes"
},
{
"internalType": "bytes32",
"name": "_localContext",
"type": "bytes32"
}
],
"name": "step",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "version",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
}
]

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
28 changes: 13 additions & 15 deletions packages/contracts-bedrock/src/cannon/MIPS.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ contract MIPS is ISemver {
uint32[32] registers;
}

/// @notice Start of the data segment.
uint32 public constant BRK_START = 0x40000000;

/// @notice The semantic version of the MIPS contract.
/// @custom:semver 1.0.1
string public constant version = "1.1.0-beta.5";
Expand Down Expand Up @@ -143,7 +140,7 @@ contract MIPS is ISemver {
}

// Load the syscall numbers and args from the registers
(uint32 syscall_no, uint32 a0, uint32 a1, uint32 a2) = sys.getSyscallArgs(state.registers);
(uint32 syscall_no, uint32 a0, uint32 a1, uint32 a2,) = sys.getSyscallArgs(state.registers);

uint32 v0 = 0;
uint32 v1 = 0;
Expand All @@ -152,7 +149,7 @@ contract MIPS is ISemver {
(v0, v1, state.heap) = sys.handleSysMmap(a0, a1, state.heap);
} else if (syscall_no == sys.SYS_BRK) {
// brk: Returns a fixed address for the program break at 0x40000000
v0 = BRK_START;
v0 = sys.BRK_START;
} else if (syscall_no == sys.SYS_CLONE) {
// clone (not supported) returns 1
v0 = 1;
Expand All @@ -162,17 +159,18 @@ contract MIPS is ISemver {
state.exitCode = uint8(a0);
return outputState();
} else if (syscall_no == sys.SYS_READ) {
(v0, v1, state.preimageOffset, state.memRoot) = sys.handleSysRead({
_a0: a0,
_a1: a1,
_a2: a2,
_preimageKey: state.preimageKey,
_preimageOffset: state.preimageOffset,
_localContext: _localContext,
_oracle: ORACLE,
_proofOffset: MIPSMemory.memoryProofOffset(STEP_PROOF_OFFSET, 1),
_memRoot: state.memRoot
sys.SysReadParams memory args = sys.SysReadParams({
a0: a0,
a1: a1,
a2: a2,
preimageKey: state.preimageKey,
preimageOffset: state.preimageOffset,
localContext: _localContext,
oracle: ORACLE,
proofOffset: MIPSMemory.memoryProofOffset(STEP_PROOF_OFFSET, 1),
memRoot: state.memRoot
});
(v0, v1, state.preimageOffset, state.memRoot) = sys.handleSysRead(args);
} else if (syscall_no == sys.SYS_WRITE) {
(v0, v1, state.preimageKey, state.preimageOffset) = sys.handleSysWrite({
_a0: a0,
Expand Down
Loading

0 comments on commit d837696

Please sign in to comment.