Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
063e52ac
Commit
063e52ac
authored
Jul 20, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: Upgrade `MIPS.sol` solc version
parent
6020e6b7
Changes
9
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
720 additions
and
713 deletions
+720
-713
mips.go
op-bindings/bindings/mips.go
+1
-1
mips_more.go
op-bindings/bindings/mips_more.go
+1
-1
MIPS.sol
packages/contracts-bedrock/src/cannon/MIPS.sol
+683
-663
PreimageKeyLib.sol
packages/contracts-bedrock/src/cannon/PreimageKeyLib.sol
+1
-1
PreimageOracle.sol
packages/contracts-bedrock/src/cannon/PreimageOracle.sol
+6
-29
IPreimageOracle.sol
...ntracts-bedrock/src/cannon/interfaces/IPreimageOracle.sol
+24
-5
IBigStepper.sol
.../contracts-bedrock/src/dispute/interfaces/IBigStepper.sol
+2
-11
AssetReceiver.sol
packages/contracts-bedrock/src/periphery/AssetReceiver.sol
+1
-0
PreimageOracle.t.sol
packages/contracts-bedrock/test/PreimageOracle.t.sol
+1
-2
No files found.
op-bindings/bindings/mips.go
View file @
063e52ac
This diff is collapsed.
Click to expand it.
op-bindings/bindings/mips_more.go
View file @
063e52ac
This diff is collapsed.
Click to expand it.
packages/contracts-bedrock/src/cannon/MIPS.sol
View file @
063e52ac
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
pragma solidity 0.
7.6
;
pragma solidity 0.
8.15
;
import { IPreimageOracle } from "./interfaces/IPreimageOracle.sol";
import { IPreimageOracle } from "./interfaces/IPreimageOracle.sol";
import { PreimageKeyLib } from "./PreimageKeyLib.sol";
import { PreimageKeyLib } from "./PreimageKeyLib.sol";
...
@@ -20,7 +20,6 @@ import { PreimageKeyLib } from "./PreimageKeyLib.sol";
...
@@ -20,7 +20,6 @@ import { PreimageKeyLib } from "./PreimageKeyLib.sol";
/// @dev https://github.com/golang/go/blob/master/src/syscall/zerrors_linux_mips.go
/// @dev https://github.com/golang/go/blob/master/src/syscall/zerrors_linux_mips.go
/// MIPS linux kernel errors used by Go runtime
/// MIPS linux kernel errors used by Go runtime
contract MIPS {
contract MIPS {
/// @notice Stores the VM state.
/// @notice Stores the VM state.
/// Total state size: 32 + 32 + 6 * 4 + 1 + 1 + 8 + 32 * 4 = 226 bytes
/// Total state size: 32 + 32 + 6 * 4 + 1 + 1 + 8 + 32 * 4 = 226 bytes
/// If nextPC != pc + 4, then the VM is executing a branch/jump delay slot.
/// If nextPC != pc + 4, then the VM is executing a branch/jump delay slot.
...
@@ -58,11 +57,13 @@ contract MIPS {
...
@@ -58,11 +57,13 @@ contract MIPS {
/// @notice Extends the value leftwards with its most significant bit (sign extension).
/// @notice Extends the value leftwards with its most significant bit (sign extension).
function SE(uint32 _dat, uint32 _idx) internal pure returns (uint32) {
function SE(uint32 _dat, uint32 _idx) internal pure returns (uint32) {
unchecked {
bool isSigned = (_dat >> (_idx - 1)) != 0;
bool isSigned = (_dat >> (_idx - 1)) != 0;
uint256 signed = ((1 << (32 - _idx)) - 1) << _idx;
uint256 signed = ((1 << (32 - _idx)) - 1) << _idx;
uint256 mask = (1 << _idx) - 1;
uint256 mask = (1 << _idx) - 1;
return uint32(_dat & mask | (isSigned ? signed : 0));
return uint32(_dat & mask | (isSigned ? signed : 0));
}
}
}
/// @notice Computes the hash of the MIPS state.
/// @notice Computes the hash of the MIPS state.
/// @return out_ The hash of the MIPS state.
/// @return out_ The hash of the MIPS state.
...
@@ -110,11 +111,11 @@ contract MIPS {
...
@@ -110,11 +111,11 @@ contract MIPS {
// Compute the hash of the resulting MIPS state
// Compute the hash of the resulting MIPS state
out_ := keccak256(start, sub(to, start))
out_ := keccak256(start, sub(to, start))
}
}
return out_;
}
}
/// @notice Handles a syscall.
/// @notice Handles a syscall.
function handleSyscall() internal returns (bytes32 out_) {
function handleSyscall() internal returns (bytes32 out_) {
unchecked {
// Load state from memory
// Load state from memory
State memory state;
State memory state;
assembly {
assembly {
...
@@ -270,6 +271,7 @@ contract MIPS {
...
@@ -270,6 +271,7 @@ contract MIPS {
out_ = outputState();
out_ = outputState();
}
}
}
/// @notice Handles a branch instruction, updating the MIPS state PC where needed.
/// @notice Handles a branch instruction, updating the MIPS state PC where needed.
/// @param _opcode The opcode of the branch instruction.
/// @param _opcode The opcode of the branch instruction.
...
@@ -278,6 +280,7 @@ contract MIPS {
...
@@ -278,6 +280,7 @@ contract MIPS {
/// @param _rs The register to be compared with the branch register.
/// @param _rs The register to be compared with the branch register.
/// @return out_ The hashed MIPS state.
/// @return out_ The hashed MIPS state.
function handleBranch(uint32 _opcode, uint32 _insn, uint32 _rtReg, uint32 _rs) internal returns (bytes32 out_) {
function handleBranch(uint32 _opcode, uint32 _insn, uint32 _rtReg, uint32 _rs) internal returns (bytes32 out_) {
unchecked {
// Load state from memory
// Load state from memory
State memory state;
State memory state;
assembly {
assembly {
...
@@ -328,6 +331,7 @@ contract MIPS {
...
@@ -328,6 +331,7 @@ contract MIPS {
// Return the hash of the resulting state
// Return the hash of the resulting state
out_ = outputState();
out_ = outputState();
}
}
}
/// @notice Handles HI and LO register instructions.
/// @notice Handles HI and LO register instructions.
/// @param _func The function code of the instruction.
/// @param _func The function code of the instruction.
...
@@ -336,6 +340,7 @@ contract MIPS {
...
@@ -336,6 +340,7 @@ contract MIPS {
/// @param _storeReg The register to store the result in.
/// @param _storeReg The register to store the result in.
/// @return out_ The hash of the resulting MIPS state.
/// @return out_ The hash of the resulting MIPS state.
function handleHiLo(uint32 _func, uint32 _rs, uint32 _rt, uint32 _storeReg) internal returns (bytes32 out_) {
function handleHiLo(uint32 _func, uint32 _rs, uint32 _rt, uint32 _storeReg) internal returns (bytes32 out_) {
unchecked {
// Load state from memory
// Load state from memory
State memory state;
State memory state;
assembly {
assembly {
...
@@ -399,12 +404,14 @@ contract MIPS {
...
@@ -399,12 +404,14 @@ contract MIPS {
// Return the hash of the resulting state
// Return the hash of the resulting state
out_ = outputState();
out_ = outputState();
}
}
}
/// @notice Handles a jump instruction, updating the MIPS state PC where needed.
/// @notice Handles a jump instruction, updating the MIPS state PC where needed.
/// @param _linkReg The register to store the link to the instruction after the delay slot instruction.
/// @param _linkReg The register to store the link to the instruction after the delay slot instruction.
/// @param _dest The destination to jump to.
/// @param _dest The destination to jump to.
/// @return out_ The hashed MIPS state.
/// @return out_ The hashed MIPS state.
function handleJump(uint32 _linkReg, uint32 _dest) internal returns (bytes32 out_) {
function handleJump(uint32 _linkReg, uint32 _dest) internal returns (bytes32 out_) {
unchecked {
// Load state from memory.
// Load state from memory.
State memory state;
State memory state;
assembly {
assembly {
...
@@ -424,6 +431,7 @@ contract MIPS {
...
@@ -424,6 +431,7 @@ contract MIPS {
// Return the hash of the resulting state.
// Return the hash of the resulting state.
out_ = outputState();
out_ = outputState();
}
}
}
/// @notice Handles a storing a value into a register.
/// @notice Handles a storing a value into a register.
/// @param _storeReg The register to store the value into.
/// @param _storeReg The register to store the value into.
...
@@ -431,6 +439,7 @@ contract MIPS {
...
@@ -431,6 +439,7 @@ contract MIPS {
/// @param _conditional Whether or not the store is conditional.
/// @param _conditional Whether or not the store is conditional.
/// @return out_ The hashed MIPS state.
/// @return out_ The hashed MIPS state.
function handleRd(uint32 _storeReg, uint32 _val, bool _conditional) internal returns (bytes32 out_) {
function handleRd(uint32 _storeReg, uint32 _val, bool _conditional) internal returns (bytes32 out_) {
unchecked {
// Load state from memory.
// Load state from memory.
State memory state;
State memory state;
assembly {
assembly {
...
@@ -452,11 +461,13 @@ contract MIPS {
...
@@ -452,11 +461,13 @@ contract MIPS {
// Return the hash of the resulting state.
// Return the hash of the resulting state.
out_ = outputState();
out_ = outputState();
}
}
}
/// @notice Computes the offset of the proof in the calldata.
/// @notice Computes the offset of the proof in the calldata.
/// @param _proofIndex The index of the proof in the calldata.
/// @param _proofIndex The index of the proof in the calldata.
/// @return offset_ The offset of the proof in the calldata.
/// @return offset_ The offset of the proof in the calldata.
function proofOffset(uint8 _proofIndex) internal pure returns (uint256 offset_) {
function proofOffset(uint8 _proofIndex) internal pure returns (uint256 offset_) {
unchecked {
// 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 == 358
// And the leaf value itself needs to be encoded as well. And proof.offset == 358
offset_ = 358 + (uint256(_proofIndex) * (28 * 32));
offset_ = 358 + (uint256(_proofIndex) * (28 * 32));
...
@@ -465,12 +476,14 @@ contract MIPS {
...
@@ -465,12 +476,14 @@ contract MIPS {
require(s >= (offset_ + 28 * 32), "check that there is enough calldata");
require(s >= (offset_ + 28 * 32), "check that there is enough calldata");
return offset_;
return offset_;
}
}
}
/// @notice Reads a 32-bit value from memory.
/// @notice Reads a 32-bit value from memory.
/// @param _addr The address to read from.
/// @param _addr The address to read from.
/// @param _proofIndex The index of the proof in the calldata.
/// @param _proofIndex The index of the proof in the calldata.
/// @return out_ The hashed MIPS state.
/// @return out_ The hashed MIPS state.
function readMem(uint32 _addr, uint8 _proofIndex) internal pure returns (uint32 out_) {
function readMem(uint32 _addr, uint8 _proofIndex) internal pure returns (uint32 out_) {
unchecked {
// Compute the offset of the proof in the calldata.
// Compute the offset of the proof in the calldata.
uint256 offset = proofOffset(_proofIndex);
uint256 offset = proofOffset(_proofIndex);
...
@@ -520,6 +533,7 @@ contract MIPS {
...
@@ -520,6 +533,7 @@ contract MIPS {
out_ := and(shr(shamt, leaf), 0xFFffFFff)
out_ := and(shr(shamt, leaf), 0xFFffFFff)
}
}
}
}
}
/// @notice Writes a 32-bit value to memory.
/// @notice Writes a 32-bit value to memory.
/// This function first overwrites the part of the leaf.
/// This function first overwrites the part of the leaf.
...
@@ -528,6 +542,7 @@ contract MIPS {
...
@@ -528,6 +542,7 @@ contract MIPS {
/// @param _proofIndex The index of the proof in the calldata.
/// @param _proofIndex The index of the proof in the calldata.
/// @param _val The value to write.
/// @param _val The value to write.
function writeMem(uint32 _addr, uint8 _proofIndex, uint32 _val) internal pure {
function writeMem(uint32 _addr, uint8 _proofIndex, uint32 _val) internal pure {
unchecked {
// Compute the offset of the proof in the calldata.
// Compute the offset of the proof in the calldata.
uint256 offset = proofOffset(_proofIndex);
uint256 offset = proofOffset(_proofIndex);
...
@@ -571,10 +586,12 @@ contract MIPS {
...
@@ -571,10 +586,12 @@ contract MIPS {
mstore(0x80, node)
mstore(0x80, node)
}
}
}
}
}
/// @notice Executes a single step of the vm.
/// @notice Executes a single step of the vm.
/// Will revert if any required input state is missing.
/// Will revert if any required input state is missing.
function step(bytes calldata stateData, bytes calldata proof) public returns (bytes32) {
function step(bytes calldata stateData, bytes calldata proof) public returns (bytes32) {
unchecked {
State memory state;
State memory state;
// Packed calldata is ~6 times smaller than state size
// Packed calldata is ~6 times smaller than state size
...
@@ -734,9 +751,11 @@ contract MIPS {
...
@@ -734,9 +751,11 @@ contract MIPS {
// write back the value to destination register
// write back the value to destination register
return handleRd(rdReg, val, true);
return handleRd(rdReg, val, true);
}
}
}
/// @notice Execute an instruction.
/// @notice Execute an instruction.
function execute(uint32 insn, uint32 rs, uint32 rt, uint32 mem) internal pure returns (uint32) {
function execute(uint32 insn, uint32 rs, uint32 rt, uint32 mem) internal pure returns (uint32) {
unchecked {
uint32 opcode = insn >> 26; // 6-bits
uint32 opcode = insn >> 26; // 6-bits
uint32 func = insn & 0x3f; // 6-bits
uint32 func = insn & 0x3f; // 6-bits
// TODO(CLI-4136): deref the immed into a register
// TODO(CLI-4136): deref the immed into a register
...
@@ -921,4 +940,5 @@ contract MIPS {
...
@@ -921,4 +940,5 @@ contract MIPS {
revert("invalid instruction");
revert("invalid instruction");
}
}
}
}
}
packages/contracts-bedrock/src/cannon/PreimageKeyLib.sol
View file @
063e52ac
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
pragma solidity
^0.7.6
;
pragma solidity
0.8.15
;
/// @title PreimageKeyLib
/// @title PreimageKeyLib
/// @notice Shared utilities for localizing local keys in the preimage oracle.
/// @notice Shared utilities for localizing local keys in the preimage oracle.
...
...
packages/contracts-bedrock/src/cannon/PreimageOracle.sol
View file @
063e52ac
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
pragma solidity 0.
7.6
;
pragma solidity 0.
8.15
;
import { IPreimageOracle } from "./interfaces/IPreimageOracle.sol";
import { PreimageKeyLib } from "./PreimageKeyLib.sol";
import { PreimageKeyLib } from "./PreimageKeyLib.sol";
/// @title PreimageOracle
/// @title PreimageOracle
/// @notice A contract for storing permissioned pre-images.
/// @notice A contract for storing permissioned pre-images.
contract PreimageOracle {
contract PreimageOracle
is IPreimageOracle
{
/// @notice Mapping of pre-image keys to pre-image lengths.
/// @notice Mapping of pre-image keys to pre-image lengths.
mapping(bytes32 => uint256) public preimageLengths;
mapping(bytes32 => uint256) public preimageLengths;
/// @notice Mapping of pre-image keys to pre-image parts.
/// @notice Mapping of pre-image keys to pre-image parts.
...
@@ -13,11 +14,7 @@ contract PreimageOracle {
...
@@ -13,11 +14,7 @@ contract PreimageOracle {
/// @notice Mapping of pre-image keys to pre-image part offsets.
/// @notice Mapping of pre-image keys to pre-image part offsets.
mapping(bytes32 => mapping(uint256 => bool)) public preimagePartOk;
mapping(bytes32 => mapping(uint256 => bool)) public preimagePartOk;
/// @notice Reads a pre-image from the oracle.
/// @inheritdoc IPreimageOracle
/// @param _key The key of the pre-image to read.
/// @param _offset The offset of the pre-image to read.
/// @return dat_ The pre-image data.
/// @return datLen_ The length of the pre-image data.
function readPreimage(bytes32 _key, uint256 _offset)
function readPreimage(bytes32 _key, uint256 _offset)
external
external
view
view
...
@@ -53,24 +50,7 @@ contract PreimageOracle {
...
@@ -53,24 +50,7 @@ contract PreimageOracle {
preimageLengths[key] = size;
preimageLengths[key] = size;
}
}
/// @notice Loads a word of local data into the preimage oracle in two separate parts.
/// @inheritdoc IPreimageOracle
/// @param _ident The identifier of the local data.
/// @param _word The local data word.
/// @param _size The number of bytes in `_word` to load.
/// @dev The local data parts are loaded into the preimage oracle under the context
/// of the caller - no other account can write to the caller's context
/// specific data.
///
/// There are 5 local data identifiers:
/// ┌────────────┬────────────────────────┐
/// │ Identifier │ Data │
/// ├────────────┼────────────────────────┤
/// │ 1 │ L1 Head Hash (bytes32) │
/// │ 2 │ Output Root (bytes32) │
/// │ 3 │ Root Claim (bytes32) │
/// │ 4 │ L2 Block Number (u64) │
/// │ 5 │ Chain ID (u64) │
/// └────────────┴────────────────────────┘
function loadLocalData(
function loadLocalData(
uint256 _ident,
uint256 _ident,
bytes32 _word,
bytes32 _word,
...
@@ -106,10 +86,7 @@ contract PreimageOracle {
...
@@ -106,10 +86,7 @@ contract PreimageOracle {
preimageLengths[key_] = _size;
preimageLengths[key_] = _size;
}
}
/// @notice Prepares a pre-image to be read by keccak256 key, starting at
/// @inheritdoc IPreimageOracle
/// the given offset and up to 32 bytes (clipped at pre-image length, if out of data).
/// @param _partOffset The offset of the pre-image to read.
/// @param _preimage The preimage data.
function loadKeccak256PreimagePart(uint256 _partOffset, bytes calldata _preimage) external {
function loadKeccak256PreimagePart(uint256 _partOffset, bytes calldata _preimage) external {
uint256 size;
uint256 size;
bytes32 key;
bytes32 key;
...
...
packages/contracts-bedrock/src/cannon/interfaces/IPreimageOracle.sol
View file @
063e52ac
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
pragma solidity 0.
7.6
;
pragma solidity 0.
8.15
;
/// @title IPreimageOracle
/// @title IPreimageOracle
/// @notice Interface for a preimage oracle.
/// @notice Interface for a preimage oracle.
...
@@ -14,10 +14,29 @@ interface IPreimageOracle {
...
@@ -14,10 +14,29 @@ interface IPreimageOracle {
view
view
returns (bytes32 dat_, uint256 datLen_);
returns (bytes32 dat_, uint256 datLen_);
/// @notice Computes and returns the key for a pre-image.
/// @notice Loads a word of local data into the preimage oracle in two separate parts.
/// @param _preimage The pre-image.
/// @param _ident The identifier of the local data.
/// @return key_ The pre-image key.
/// @param _word The local data word.
function computePreimageKey(bytes calldata _preimage) external pure returns (bytes32 key_);
/// @param _size The number of bytes in `_word` to load.
/// @dev The local data parts are loaded into the preimage oracle under the context
/// of the caller - no other account can write to the caller's context
/// specific data.
///
/// There are 5 local data identifiers:
/// ┌────────────┬────────────────────────┐
/// │ Identifier │ Data │
/// ├────────────┼────────────────────────┤
/// │ 1 │ L1 Head Hash (bytes32) │
/// │ 2 │ Output Root (bytes32) │
/// │ 3 │ Root Claim (bytes32) │
/// │ 4 │ L2 Block Number (u64) │
/// │ 5 │ Chain ID (u64) │
/// └────────────┴────────────────────────┘
function loadLocalData(
uint256 _ident,
bytes32 _word,
uint8 _size
) external returns (bytes32 key_);
/// @notice Prepares a preimage to be read by keccak256 key, starting at
/// @notice Prepares a preimage to be read by keccak256 key, starting at
/// the given offset and up to 32 bytes (clipped at preimage length, if out of data).
/// the given offset and up to 32 bytes (clipped at preimage length, if out of data).
...
...
packages/contracts-bedrock/src/dispute/interfaces/IBigStepper.sol
View file @
063e52ac
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;
pragma solidity ^0.8.15;
import { IPreimageOracle } from "../../cannon/interfaces/IPreimageOracle.sol";
/// @title IBigStepper
/// @title IBigStepper
/// @notice An interface for a contract with a state transition function that
/// @notice An interface for a contract with a state transition function that
/// will accept a pre state and return a post state.
/// will accept a pre state and return a post state.
...
@@ -35,14 +37,3 @@ interface IBigStepper {
...
@@ -35,14 +37,3 @@ interface IBigStepper {
/// @notice Returns the preimage oracle used by the stepper.
/// @notice Returns the preimage oracle used by the stepper.
function oracle() external view returns (IPreimageOracle oracle_);
function oracle() external view returns (IPreimageOracle oracle_);
}
}
/// @notice Temporary interface for the `IPreimageOracle`. Remove once we've upgraded
/// the cannon contracts to a newer version of solc.
interface IPreimageOracle {
function loadLocalData(
uint256 _ident,
bytes32 _word,
uint256 _size,
uint256 _partOffset
) external returns (bytes32 key_);
}
packages/contracts-bedrock/src/periphery/AssetReceiver.sol
View file @
063e52ac
...
@@ -64,6 +64,7 @@ contract AssetReceiver is Transactor {
...
@@ -64,6 +64,7 @@ contract AssetReceiver is Transactor {
function withdrawETH(address payable _to, uint256 _amount) public onlyOwner {
function withdrawETH(address payable _to, uint256 _amount) public onlyOwner {
// slither-disable-next-line reentrancy-unlimited-gas
// slither-disable-next-line reentrancy-unlimited-gas
(bool success, ) = _to.call{ value: _amount }("");
(bool success, ) = _to.call{ value: _amount }("");
success; // Suppress warning; We ignore the low-level call result.
emit WithdrewETH(msg.sender, _to, _amount);
emit WithdrewETH(msg.sender, _to, _amount);
}
}
...
...
packages/contracts-bedrock/test/PreimageOracle.t.sol
View file @
063e52ac
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
pragma solidity 0.7.6;
pragma solidity 0.8.15;
pragma abicoder v2;
import { Test } from "forge-std/Test.sol";
import { Test } from "forge-std/Test.sol";
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment