Skip to content

Commit

Permalink
Move State struct definition to test
Browse files Browse the repository at this point in the history
  • Loading branch information
pcw109550 committed Feb 19, 2024
1 parent 6ee8a31 commit a0ce152
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
17 changes: 0 additions & 17 deletions rvsol/src/RISCV.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,6 @@ pragma solidity ^0.8.13;
import {IPreimageOracle} from "@optimism/src/cannon/interfaces/IPreimageOracle.sol";

contract RISCV {
/// @notice Stores the VM state.
/// Total state size: 32 + 32 + 8 * 2 + 1 * 2 + 8 * 3 + 32 * 8 = 362 bytes
/// Note that struct is not used for step execution and used only for testing
// Struct size may be larger than total state size due to memory layouts
struct State {
bytes32 memRoot;
bytes32 preimageKey;
uint64 preimageOffset;
uint64 pc;
uint8 exitCode;
bool exited;
uint64 step;
uint64 heap;
uint64 loadReservation;
uint64[32] registers;
}

IPreimageOracle public preimageOracle;

constructor(IPreimageOracle _preimageOracle) {
Expand Down
21 changes: 19 additions & 2 deletions rvsol/test/RISCV.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ import {RISCV} from "src/RISCV.sol";
import {PreimageOracle} from "@optimism/src/cannon/PreimageOracle.sol";

contract RISCV_Test is Test {
/// @notice Stores the VM state.
/// Total state size: 32 + 32 + 8 * 2 + 1 * 2 + 8 * 3 + 32 * 8 = 362 bytes
/// Note that struct is not used for step execution and used only for testing
// Struct size may be larger than total state size due to memory layouts
struct State {
bytes32 memRoot;
bytes32 preimageKey;
uint64 preimageOffset;
uint64 pc;
uint8 exitCode;
bool exited;
uint64 step;
uint64 heap;
uint64 loadReservation;
uint64[32] registers;
}

RISCV internal riscv;
PreimageOracle internal oracle;

Expand All @@ -20,7 +37,7 @@ contract RISCV_Test is Test {
// state and proof from first step of `simple` binary
uint64[32] memory registers;
registers[2] = 0x1000000000000000;
RISCV.State memory state = RISCV.State({
State memory state = State({
memRoot: hex"f0df7f266aed88bde90ed121f0de6865f3fa88bf67d3a4657dad876038393b2c",
preimageKey: bytes32(0),
preimageOffset: 0,
Expand All @@ -38,7 +55,7 @@ contract RISCV_Test is Test {
assertTrue(postState != bytes32(0));
}

function encodeState(RISCV.State memory state) internal pure returns (bytes memory) {
function encodeState(State memory state) internal pure returns (bytes memory) {
bytes memory registers;
for (uint256 i = 0; i < state.registers.length; i++) {
registers = bytes.concat(registers, abi.encodePacked(state.registers[i]));
Expand Down

0 comments on commit a0ce152

Please sign in to comment.