Commit eb055622 authored by clabby's avatar clabby

Begin contextualization of local keys

parent 5f2ad00c
......@@ -91,44 +91,44 @@ FaucetTest:test_nonAdmin_drip_fails() (gas: 262520)
FaucetTest:test_receive_succeeds() (gas: 17401)
FaucetTest:test_withdraw_nonAdmin_reverts() (gas: 13145)
FaucetTest:test_withdraw_succeeds() (gas: 78359)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 660411)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 667293)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 663974)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 667169)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 666460)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 653092)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 658598)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 655943)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 656899)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 656332)
FaultDisputeGame_Test:test_addLocalData_static_succeeds() (gas: 640567)
FaultDisputeGame_Test:test_createdAt_succeeds() (gas: 10342)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 659951)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 666811)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 663514)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 666687)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 666000)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 652724)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 658212)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 655575)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 656513)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 655964)
FaultDisputeGame_Test:test_addLocalData_static_succeeds() (gas: 642642)
FaultDisputeGame_Test:test_createdAt_succeeds() (gas: 10409)
FaultDisputeGame_Test:test_extraData_succeeds() (gas: 32328)
FaultDisputeGame_Test:test_gameData_succeeds() (gas: 32755)
FaultDisputeGame_Test:test_gameData_succeeds() (gas: 32777)
FaultDisputeGame_Test:test_gameType_succeeds() (gas: 8265)
FaultDisputeGame_Test:test_initialize_correctData_succeeds() (gas: 57712)
FaultDisputeGame_Test:test_initialize_firstOutput_reverts() (gas: 210563)
FaultDisputeGame_Test:test_initialize_l1HeadTooOld_reverts() (gas: 228401)
FaultDisputeGame_Test:test_move_clockCorrectness_succeeds() (gas: 594268)
FaultDisputeGame_Test:test_initialize_correctData_succeeds() (gas: 57646)
FaultDisputeGame_Test:test_initialize_firstOutput_reverts() (gas: 210650)
FaultDisputeGame_Test:test_initialize_l1HeadTooOld_reverts() (gas: 228466)
FaultDisputeGame_Test:test_move_clockCorrectness_succeeds() (gas: 594025)
FaultDisputeGame_Test:test_move_clockTimeExceeded_reverts() (gas: 23175)
FaultDisputeGame_Test:test_move_defendRoot_reverts() (gas: 13366)
FaultDisputeGame_Test:test_move_duplicateClaim_reverts() (gas: 147389)
FaultDisputeGame_Test:test_move_duplicateClaimsDifferentSubgames_succeeds() (gas: 556885)
FaultDisputeGame_Test:test_move_gameDepthExceeded_reverts() (gas: 585897)
FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 11002)
FaultDisputeGame_Test:test_move_nonExistentParent_reverts() (gas: 24666)
FaultDisputeGame_Test:test_move_simpleAttack_succeeds() (gas: 151959)
FaultDisputeGame_Test:test_resolve_challengeContested_succeeds() (gas: 269413)
FaultDisputeGame_Test:test_resolve_claimAlreadyResolved_reverts() (gas: 272356)
FaultDisputeGame_Test:test_resolve_claimAtMaxDepthAlreadyResolved_reverts() (gas: 586672)
FaultDisputeGame_Test:test_resolve_notInProgress_reverts() (gas: 9732)
FaultDisputeGame_Test:test_resolve_outOfOrderResolution_reverts() (gas: 309037)
FaultDisputeGame_Test:test_resolve_rootContested_succeeds() (gas: 139044)
FaultDisputeGame_Test:test_resolve_rootUncontestedButUnresolved_reverts() (gas: 15883)
FaultDisputeGame_Test:test_resolve_rootUncontestedClockNotExpired_succeeds() (gas: 18406)
FaultDisputeGame_Test:test_resolve_rootUncontested_succeeds() (gas: 51409)
FaultDisputeGame_Test:test_resolve_stepReached_succeeds() (gas: 498476)
FaultDisputeGame_Test:test_resolve_teamDeathmatch_succeeds() (gas: 443373)
FaultDisputeGame_Test:test_move_defendRoot_reverts() (gas: 13300)
FaultDisputeGame_Test:test_move_duplicateClaim_reverts() (gas: 147367)
FaultDisputeGame_Test:test_move_duplicateClaimsDifferentSubgames_succeeds() (gas: 556831)
FaultDisputeGame_Test:test_move_gameDepthExceeded_reverts() (gas: 585853)
FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 10980)
FaultDisputeGame_Test:test_move_nonExistentParent_reverts() (gas: 24644)
FaultDisputeGame_Test:test_move_simpleAttack_succeeds() (gas: 151915)
FaultDisputeGame_Test:test_resolve_challengeContested_succeeds() (gas: 269432)
FaultDisputeGame_Test:test_resolve_claimAlreadyResolved_reverts() (gas: 272334)
FaultDisputeGame_Test:test_resolve_claimAtMaxDepthAlreadyResolved_reverts() (gas: 586606)
FaultDisputeGame_Test:test_resolve_notInProgress_reverts() (gas: 9754)
FaultDisputeGame_Test:test_resolve_outOfOrderResolution_reverts() (gas: 309015)
FaultDisputeGame_Test:test_resolve_rootContested_succeeds() (gas: 139090)
FaultDisputeGame_Test:test_resolve_rootUncontestedButUnresolved_reverts() (gas: 15884)
FaultDisputeGame_Test:test_resolve_rootUncontestedClockNotExpired_succeeds() (gas: 18428)
FaultDisputeGame_Test:test_resolve_rootUncontested_succeeds() (gas: 51410)
FaultDisputeGame_Test:test_resolve_stepReached_succeeds() (gas: 498406)
FaultDisputeGame_Test:test_resolve_teamDeathmatch_succeeds() (gas: 443357)
FaultDisputeGame_Test:test_rootClaim_succeeds() (gas: 8232)
FeeVault_Test:test_constructor_succeeds() (gas: 18185)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 354421)
......@@ -306,81 +306,81 @@ LegacyERC20ETH_Test:test_transferFrom_doesNotExist_reverts() (gas: 12957)
LegacyERC20ETH_Test:test_transfer_doesNotExist_reverts() (gas: 10755)
LegacyMessagePasser_Test:test_passMessageToL1_succeeds() (gas: 34524)
LibPosition_Test:test_pos_correctness_succeeds() (gas: 38689)
MIPS_Test:test_add_succeeds() (gas: 122420)
MIPS_Test:test_addiSign_succeeds() (gas: 122411)
MIPS_Test:test_addi_succeeds() (gas: 122608)
MIPS_Test:test_addu_succeeds() (gas: 122462)
MIPS_Test:test_addui_succeeds() (gas: 122670)
MIPS_Test:test_and_succeeds() (gas: 122481)
MIPS_Test:test_andi_succeeds() (gas: 122414)
MIPS_Test:test_beq_succeeds() (gas: 202801)
MIPS_Test:test_bgez_succeeds() (gas: 121707)
MIPS_Test:test_bgtz_succeeds() (gas: 121628)
MIPS_Test:test_blez_succeeds() (gas: 121584)
MIPS_Test:test_bltz_succeeds() (gas: 121727)
MIPS_Test:test_bne_succeeds() (gas: 121793)
MIPS_Test:test_branch_inDelaySlot_fails() (gas: 85999)
MIPS_Test:test_brk_succeeds() (gas: 122092)
MIPS_Test:test_clo_succeeds() (gas: 122149)
MIPS_Test:test_clone_succeeds() (gas: 122045)
MIPS_Test:test_clz_succeeds() (gas: 122620)
MIPS_Test:test_div_succeeds() (gas: 122599)
MIPS_Test:test_divu_succeeds() (gas: 122584)
MIPS_Test:test_exit_succeeds() (gas: 122094)
MIPS_Test:test_fcntl_succeeds() (gas: 204273)
MIPS_Test:test_illegal_instruction_fails() (gas: 91462)
MIPS_Test:test_invalid_root_fails() (gas: 435636)
MIPS_Test:test_jal_nonzeroRegion_succeeds() (gas: 120737)
MIPS_Test:test_jal_succeeds() (gas: 120726)
MIPS_Test:test_jalr_succeeds() (gas: 121845)
MIPS_Test:test_jr_succeeds() (gas: 121539)
MIPS_Test:test_jump_inDelaySlot_fails() (gas: 85367)
MIPS_Test:test_jump_nonzeroRegion_succeeds() (gas: 120481)
MIPS_Test:test_jump_succeeds() (gas: 120411)
MIPS_Test:test_lb_succeeds() (gas: 127652)
MIPS_Test:test_lbu_succeeds() (gas: 127550)
MIPS_Test:test_lh_succeeds() (gas: 127673)
MIPS_Test:test_lhu_succeeds() (gas: 127590)
MIPS_Test:test_ll_succeeds() (gas: 127812)
MIPS_Test:test_lui_succeeds() (gas: 121693)
MIPS_Test:test_lw_succeeds() (gas: 127441)
MIPS_Test:test_lwl_succeeds() (gas: 242046)
MIPS_Test:test_lwr_succeeds() (gas: 242334)
MIPS_Test:test_mfhi_succeeds() (gas: 122054)
MIPS_Test:test_mflo_succeeds() (gas: 122183)
MIPS_Test:test_mmap_succeeds() (gas: 119012)
MIPS_Test:test_movn_succeeds() (gas: 203473)
MIPS_Test:test_movz_succeeds() (gas: 203341)
MIPS_Test:test_mthi_succeeds() (gas: 122098)
MIPS_Test:test_mtlo_succeeds() (gas: 122206)
MIPS_Test:test_mul_succeeds() (gas: 121698)
MIPS_Test:test_mult_succeeds() (gas: 122402)
MIPS_Test:test_multu_succeeds() (gas: 122439)
MIPS_Test:test_nor_succeeds() (gas: 122531)
MIPS_Test:test_or_succeeds() (gas: 122488)
MIPS_Test:test_ori_succeeds() (gas: 122491)
MIPS_Test:test_preimage_read_succeeds() (gas: 234408)
MIPS_Test:test_preimage_write_succeeds() (gas: 127034)
MIPS_Test:test_prestate_exited_succeeds() (gas: 113280)
MIPS_Test:test_sb_succeeds() (gas: 160523)
MIPS_Test:test_sc_succeeds() (gas: 160717)
MIPS_Test:test_sh_succeeds() (gas: 160560)
MIPS_Test:test_sll_succeeds() (gas: 121659)
MIPS_Test:test_sllv_succeeds() (gas: 121888)
MIPS_Test:test_slt_succeeds() (gas: 204668)
MIPS_Test:test_sltu_succeeds() (gas: 122705)
MIPS_Test:test_sra_succeeds() (gas: 121910)
MIPS_Test:test_srav_succeeds() (gas: 122178)
MIPS_Test:test_srl_succeeds() (gas: 121741)
MIPS_Test:test_srlv_succeeds() (gas: 121906)
MIPS_Test:test_step_abi_succeeds() (gas: 58417)
MIPS_Test:test_sub_succeeds() (gas: 122515)
MIPS_Test:test_subu_succeeds() (gas: 122512)
MIPS_Test:test_sw_succeeds() (gas: 160535)
MIPS_Test:test_swl_succeeds() (gas: 160596)
MIPS_Test:test_swr_succeeds() (gas: 160671)
MIPS_Test:test_xor_succeeds() (gas: 122516)
MIPS_Test:test_xori_succeeds() (gas: 122568)
MIPS_Test:test_add_succeeds() (gas: 122466)
MIPS_Test:test_addiSign_succeeds() (gas: 122457)
MIPS_Test:test_addi_succeeds() (gas: 122654)
MIPS_Test:test_addu_succeeds() (gas: 122508)
MIPS_Test:test_addui_succeeds() (gas: 122716)
MIPS_Test:test_and_succeeds() (gas: 122527)
MIPS_Test:test_andi_succeeds() (gas: 122460)
MIPS_Test:test_beq_succeeds() (gas: 202893)
MIPS_Test:test_bgez_succeeds() (gas: 121753)
MIPS_Test:test_bgtz_succeeds() (gas: 121674)
MIPS_Test:test_blez_succeeds() (gas: 121630)
MIPS_Test:test_bltz_succeeds() (gas: 121773)
MIPS_Test:test_bne_succeeds() (gas: 121839)
MIPS_Test:test_branch_inDelaySlot_fails() (gas: 86048)
MIPS_Test:test_brk_succeeds() (gas: 122143)
MIPS_Test:test_clo_succeeds() (gas: 122195)
MIPS_Test:test_clone_succeeds() (gas: 122096)
MIPS_Test:test_clz_succeeds() (gas: 122666)
MIPS_Test:test_div_succeeds() (gas: 122645)
MIPS_Test:test_divu_succeeds() (gas: 122630)
MIPS_Test:test_exit_succeeds() (gas: 122145)
MIPS_Test:test_fcntl_succeeds() (gas: 204375)
MIPS_Test:test_illegal_instruction_fails() (gas: 91511)
MIPS_Test:test_invalid_root_fails() (gas: 435685)
MIPS_Test:test_jal_nonzeroRegion_succeeds() (gas: 120783)
MIPS_Test:test_jal_succeeds() (gas: 120772)
MIPS_Test:test_jalr_succeeds() (gas: 121891)
MIPS_Test:test_jr_succeeds() (gas: 121585)
MIPS_Test:test_jump_inDelaySlot_fails() (gas: 85416)
MIPS_Test:test_jump_nonzeroRegion_succeeds() (gas: 120527)
MIPS_Test:test_jump_succeeds() (gas: 120457)
MIPS_Test:test_lb_succeeds() (gas: 127698)
MIPS_Test:test_lbu_succeeds() (gas: 127596)
MIPS_Test:test_lh_succeeds() (gas: 127719)
MIPS_Test:test_lhu_succeeds() (gas: 127636)
MIPS_Test:test_ll_succeeds() (gas: 127858)
MIPS_Test:test_lui_succeeds() (gas: 121739)
MIPS_Test:test_lw_succeeds() (gas: 127487)
MIPS_Test:test_lwl_succeeds() (gas: 242138)
MIPS_Test:test_lwr_succeeds() (gas: 242426)
MIPS_Test:test_mfhi_succeeds() (gas: 122100)
MIPS_Test:test_mflo_succeeds() (gas: 122229)
MIPS_Test:test_mmap_succeeds() (gas: 119063)
MIPS_Test:test_movn_succeeds() (gas: 203565)
MIPS_Test:test_movz_succeeds() (gas: 203433)
MIPS_Test:test_mthi_succeeds() (gas: 122144)
MIPS_Test:test_mtlo_succeeds() (gas: 122252)
MIPS_Test:test_mul_succeeds() (gas: 121744)
MIPS_Test:test_mult_succeeds() (gas: 122448)
MIPS_Test:test_multu_succeeds() (gas: 122485)
MIPS_Test:test_nor_succeeds() (gas: 122577)
MIPS_Test:test_or_succeeds() (gas: 122534)
MIPS_Test:test_ori_succeeds() (gas: 122537)
MIPS_Test:test_preimage_read_succeeds() (gas: 234549)
MIPS_Test:test_preimage_write_succeeds() (gas: 127085)
MIPS_Test:test_prestate_exited_succeeds() (gas: 113326)
MIPS_Test:test_sb_succeeds() (gas: 160569)
MIPS_Test:test_sc_succeeds() (gas: 160752)
MIPS_Test:test_sh_succeeds() (gas: 160606)
MIPS_Test:test_sll_succeeds() (gas: 121705)
MIPS_Test:test_sllv_succeeds() (gas: 121934)
MIPS_Test:test_slt_succeeds() (gas: 204760)
MIPS_Test:test_sltu_succeeds() (gas: 122751)
MIPS_Test:test_sra_succeeds() (gas: 121956)
MIPS_Test:test_srav_succeeds() (gas: 122224)
MIPS_Test:test_srl_succeeds() (gas: 121787)
MIPS_Test:test_srlv_succeeds() (gas: 121952)
MIPS_Test:test_step_abi_succeeds() (gas: 58467)
MIPS_Test:test_sub_succeeds() (gas: 122561)
MIPS_Test:test_subu_succeeds() (gas: 122558)
MIPS_Test:test_sw_succeeds() (gas: 160581)
MIPS_Test:test_swl_succeeds() (gas: 160642)
MIPS_Test:test_swr_succeeds() (gas: 160717)
MIPS_Test:test_xor_succeeds() (gas: 122562)
MIPS_Test:test_xori_succeeds() (gas: 122614)
MerkleTrie_get_Test:test_get_corruptedProof_reverts() (gas: 5733)
MerkleTrie_get_Test:test_get_extraProofElements_reverts() (gas: 58889)
MerkleTrie_get_Test:test_get_invalidDataRemainder_reverts() (gas: 35845)
......@@ -532,8 +532,8 @@ OptimistTest:test_transferFrom_soulbound_reverts() (gas: 75512)
PreimageOracle_Test:test_keccak256PreimageKey_succeeds() (gas: 319)
PreimageOracle_Test:test_loadKeccak256PreimagePart_outOfBoundsOffset_reverts() (gas: 8993)
PreimageOracle_Test:test_loadKeccak256PreimagePart_succeeds() (gas: 76076)
PreimageOracle_Test:test_loadLocalData_onePart_succeeds() (gas: 75818)
PreimageOracle_Test:test_loadLocalData_outOfBoundsOffset_reverts() (gas: 8803)
PreimageOracle_Test:test_loadLocalData_onePart_succeeds() (gas: 75905)
PreimageOracle_Test:test_loadLocalData_outOfBoundsOffset_reverts() (gas: 8904)
ProtocolVersions_Initialize_Test:test_initialize_events_succeeds() (gas: 52181)
ProtocolVersions_Initialize_Test:test_initialize_values_succeeds() (gas: 32301)
ProtocolVersions_Setters_TestFail:test_setRecommended_notOwner_reverts() (gas: 15508)
......
......@@ -141,8 +141,9 @@ contract MIPS {
}
/// @notice Handles a syscall.
/// @param _localContext The local key context for the preimage oracle.
/// @return out_ The hashed MIPS state.
function handleSyscall() internal returns (bytes32 out_) {
function handleSyscall(uint256 _localContext) internal returns (bytes32 out_) {
unchecked {
// Load state from memory
State memory state;
......@@ -202,7 +203,7 @@ contract MIPS {
bytes32 preimageKey = state.preimageKey;
// If the preimage key is a local key, localize it in the context of the caller.
if (uint8(preimageKey[0]) == 1) {
preimageKey = PreimageKeyLib.localize(preimageKey);
preimageKey = PreimageKeyLib.localize(preimageKey, _localContext);
}
(bytes32 dat, uint256 datLen) = ORACLE.readPreimage(preimageKey, state.preimageOffset);
......@@ -508,8 +509,8 @@ contract MIPS {
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.
// And the leaf value itself needs to be encoded as well. And proof.offset == 388
offset_ = 388 + (uint256(_proofIndex) * (28 * 32));
// And the leaf value itself needs to be encoded as well. And proof.offset == 420
offset_ = 420 + (uint256(_proofIndex) * (28 * 32));
uint256 s = 0;
assembly {
s := calldatasize()
......@@ -621,7 +622,11 @@ contract MIPS {
/// @notice Executes a single step of the vm.
/// Will revert if any required input state is missing.
function step(bytes calldata stateData, bytes calldata proof) public returns (bytes32) {
/// @param _stateData The encoded state witness data.
/// @param _proof The encoded proof data for leaves within the MIPS VM's memory.
/// @param _localContext The local key context for the preimage oracle. Optional, can be set as a constant
/// if the caller only requires one set of local keys.
function step(bytes calldata _stateData, bytes calldata _proof, uint256 _localContext) public returns (bytes32) {
unchecked {
State memory state;
......@@ -631,16 +636,16 @@ contract MIPS {
// expected state mem offset check
revert(0, 0)
}
if iszero(eq(mload(0x40), mul(32, 48))) {
if iszero(eq(mload(0x40), shl(5, 48))) {
// expected memory check
revert(0, 0)
}
if iszero(eq(stateData.offset, 100)) {
// 32*3+4=100 expected state data offset
if iszero(eq(_stateData.offset, 132)) {
// 32*4+4=132 expected state data offset
revert(0, 0)
}
if iszero(eq(proof.offset, 388)) {
// 100+32+256=388 expected proof offset
if iszero(eq(_proof.offset, 420)) {
// 132+32+256=420 expected proof offset
revert(0, 0)
}
......@@ -653,7 +658,7 @@ contract MIPS {
}
// Unpack state from calldata into memory
let c := stateData.offset // calldata offset
let c := _stateData.offset // calldata offset
let m := 0x80 // mem offset
c, m := putField(c, m, 32) // memRoot
c, m := putField(c, m, 32) // preimageKey
......@@ -764,7 +769,7 @@ contract MIPS {
// syscall (can read and write)
if (func == 0xC) {
return handleSyscall();
return handleSyscall(_localContext);
}
// lo and hi registers
......
......@@ -7,14 +7,15 @@ library PreimageKeyLib {
/// @notice Generates a context-specific local key for the given local data identifier.
/// @dev See `localize` for a description of the localization operation.
/// @param _ident The identifier of the local data. [0, 32) bytes in size.
/// @param _localContext The local context for the key.
/// @return key_ The context-specific local key.
function localizeIdent(uint256 _ident) internal view returns (bytes32 key_) {
function localizeIdent(uint256 _ident, uint256 _localContext) internal view returns (bytes32 key_) {
assembly {
// Set the type byte in the given identifier to `1` (Local). We only care about
// the [1, 32) bytes in this value.
key_ := or(shl(248, 1), and(_ident, not(shl(248, 0xFF))))
}
key_ = localize(key_);
key_ = localize(key_, _localContext);
}
/// @notice Localizes a given local data key for the caller's context.
......@@ -22,14 +23,20 @@ library PreimageKeyLib {
/// localize(k) = H(k .. sender) & ~(0xFF << 248) | (0x01 << 248)
/// where H is the Keccak-256 hash function.
/// @param _key The local data key to localize.
/// @param _localContext The local context for the key.
/// @return localizedKey_ The localized local data key.
function localize(bytes32 _key) internal view returns (bytes32 localizedKey_) {
function localize(bytes32 _key, uint256 _localContext) internal view returns (bytes32 localizedKey_) {
assembly {
// Grab the current free memory pointer to restore later.
let ptr := mload(0x40)
// Store the local data key and caller next to each other in memory for hashing.
mstore(0, _key)
mstore(0x20, caller())
mstore(0x40, _localContext)
// Localize the key with the above `localize` operation.
localizedKey_ := or(and(keccak256(0, 0x40), not(shl(248, 0xFF))), shl(248, 1))
localizedKey_ := or(and(keccak256(0, 0x60), not(shl(248, 0xFF))), shl(248, 1))
// Restore the free memory pointer.
mstore(0x40, ptr)
}
}
......
......@@ -34,6 +34,7 @@ contract PreimageOracle is IPreimageOracle {
/// @inheritdoc IPreimageOracle
function loadLocalData(
uint256 _ident,
uint256 _localContext,
bytes32 _word,
uint256 _size,
uint256 _partOffset
......@@ -42,7 +43,7 @@ contract PreimageOracle is IPreimageOracle {
returns (bytes32 key_)
{
// Compute the localized key from the given local identifier.
key_ = PreimageKeyLib.localizeIdent(_ident);
key_ = PreimageKeyLib.localizeIdent(_ident, _localContext);
// Revert if the given part offset is not within bounds.
if (_partOffset > _size + 8 || _size > 32) {
......
......@@ -13,6 +13,8 @@ interface IPreimageOracle {
/// @notice Loads of local data part into the preimage oracle.
/// @param _ident The identifier of the local data.
/// @param _localContext The local key context for the preimage oracle. Optional, can be set as a constant
/// if the caller only requires one set of local keys.
/// @param _word The local data word.
/// @param _size The number of bytes in `_word` to load.
/// @param _partOffset The offset of the local data part to write to the oracle.
......@@ -32,6 +34,7 @@ interface IPreimageOracle {
/// └────────────┴────────────────────────┘
function loadLocalData(
uint256 _ident,
uint256 _localContext,
bytes32 _word,
uint256 _size,
uint256 _partOffset
......
......@@ -278,7 +278,7 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
}
/// @inheritdoc IFaultDisputeGame
function addLocalData(uint256 _ident, uint256 _partOffset) external {
function addLocalData(uint256 _ident, uint256 _l2BlockNumber, uint256 _partOffset) external {
// INVARIANT: Local data can only be added if the game is currently in progress.
if (status != GameStatus.IN_PROGRESS) revert GameNotInProgress();
......@@ -289,6 +289,8 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
mstore(0x1C, loadLocalDataSelector)
// Store the `_ident` argument
mstore(0x20, _ident)
// Store the `_localContext` argument
mstore(0x40, _l2BlockNumber)
// Store the data to load
let data
switch _ident
......@@ -319,16 +321,16 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, ISemver {
// Revert with `InvalidLocalIdent()`
revert(0x1C, 0x04)
}
mstore(0x40, data)
mstore(0x60, data)
// Store the size of the data to load
// _ident > 3 ? 8 : 32
mstore(0x60, shl(sub(0x05, shl(0x01, gt(_ident, 0x03))), 0x01))
mstore(0x80, shl(sub(0x05, shl(0x01, gt(_ident, 0x03))), 0x01))
// Store the part offset of the data
mstore(0x80, _partOffset)
mstore(0xA0, _partOffset)
// Attempt to add the local data to the preimage oracle and bubble up the revert
// if it fails.
if iszero(call(gas(), oracle, 0x00, 0x1C, 0x84, 0x00, 0x00)) {
if iszero(call(gas(), oracle, 0x00, 0x1C, 0xA4, 0x00, 0x00)) {
returndatacopy(0x00, 0x00, returndatasize())
revert(0x00, returndatasize())
}
......
......@@ -70,8 +70,10 @@ interface IFaultDisputeGame is IDisputeGame {
/// @notice Posts the requested local data to the VM's `PreimageOralce`.
/// @param _ident The local identifier of the data to post.
/// @param _l2BlockNumber The L2 block number being disputed. This serves as the local context for the
/// `PreimageOracle` key.
/// @param _partOffset The offset of the data to post.
function addLocalData(uint256 _ident, uint256 _partOffset) external;
function addLocalData(uint256 _ident, uint256 _l2BlockNumber, uint256 _partOffset) external;
/// @notice Resolves the subgame rooted at the given claim index.
/// @dev This function must be called bottom-up in the DAG
......
......@@ -483,12 +483,12 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
}
/// @dev Tests that adding local data with an out of bounds identifier reverts.
function testFuzz_addLocalData_oob_reverts(uint256 _ident) public {
function testFuzz_addLocalData_oob_reverts(uint256 _ident, uint256 _localContext) public {
// [1, 5] are valid local data identifiers.
if (_ident <= 5) _ident = 0;
vm.expectRevert(InvalidLocalIdent.selector);
gameProxy.addLocalData(_ident, 0);
gameProxy.addLocalData(_ident, _localContext, 0);
}
/// @dev Tests that local data is loaded into the preimage oracle correctly.
......@@ -508,8 +508,8 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
for (uint256 i = 1; i <= 5; i++) {
uint256 expectedLen = i > 3 ? 8 : 32;
gameProxy.addLocalData(i, 0);
bytes32 key = _getKey(i);
gameProxy.addLocalData(i, 0, 0);
bytes32 key = _getKey(i, 0);
(bytes32 dat, uint256 datLen) = oracle.readPreimage(key, 0);
assertEq(dat >> 0xC0, bytes32(expectedLen));
// Account for the length prefix if i > 3 (the data stored
......@@ -519,8 +519,8 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
// total.)
assertEq(datLen, expectedLen + (i > 3 ? 8 : 0));
gameProxy.addLocalData(i, 8);
key = _getKey(i);
gameProxy.addLocalData(i, 0, 8);
key = _getKey(i, 0);
(dat, datLen) = oracle.readPreimage(key, 8);
assertEq(dat, data[i - 1]);
assertEq(datLen, expectedLen);
......@@ -528,8 +528,8 @@ contract FaultDisputeGame_Test is FaultDisputeGame_Init {
}
/// @dev Helper to get the localized key for an identifier in the context of the game proxy.
function _getKey(uint256 _ident) internal view returns (bytes32) {
bytes32 h = keccak256(abi.encode(_ident | (1 << 248), address(gameProxy)));
function _getKey(uint256 _ident, uint256 _localContext) internal view returns (bytes32) {
bytes32 h = keccak256(abi.encode(_ident | (1 << 248), address(gameProxy), _localContext));
return bytes32((uint256(h) & ~uint256(0xFF << 248)) | (1 << 248));
}
......
......@@ -39,7 +39,7 @@ contract MIPS_Test is CommonTest {
bytes memory proof =
hex"3c10bfff3610fff0341100013c08ffff3508fffd34090003010950202d420001ae020008ae11000403e000080000000000000000000000000000000000000000ad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5b4c11951957c6f8f642c4af61cd6b24640fec6dc7fc607ee8206a99e92410d3021ddb9a356815c3fac1026b6dec5df3124afbadb485c9ba5a3e3398a04b7ba85e58769b32a1beaf1ea27375a44095a0d1fb664ce2dd358e7fcbfb78c26a193440eb01ebfc9ed27500cd4dfc979272d1f0913cc9f66540d7e8005811109e1cf2d887c22bd8750d34016ac3c66b5ff102dacdd73f6b014e710b51e8022af9a1968ffd70157e48063fc33c97a050f7f640233bf646cc98d9524c6b92bcf3ab56f839867cc5f7f196b93bae1e27e6320742445d290f2263827498b54fec539f756afcefad4e508c098b9a7e1d8feb19955fb02ba9675585078710969d3440f5054e0f9dc3e7fe016e050eff260334f18a5d4fe391d82092319f5964f2e2eb7c1c3a5f8b13a49e282f609c317a833fb8d976d11517c571d1221a265d25af778ecf8923490c6ceeb450aecdc82e28293031d10c7d73bf85e57bf041a97360aa2c5d99cc1df82d9c4b87413eae2ef048f94b4d3554cea73d92b0f7af96e0271c691e2bb5c67add7c6caf302256adedf7ab114da0acfe870d449a3a489f781d659e8beccda7bce9f4e8618b6bd2f4132ce798cdc7a60e7e1460a7299e3c6342a579626d22733e50f526ec2fa19a22b31e8ed50f23cd1fdf94c9154ed3a7609a2f1ff981fe1d3b5c807b281e4683cc6d6315cf95b9ade8641defcb32372f1c126e398ef7a5a2dce0a8a7f68bb74560f8f71837c2c2ebbcbf7fffb42ae1896f13f7c7479a0b46a28b6f55540f89444f63de0378e3d121be09e06cc9ded1c20e65876d36aa0c65e9645644786b620e2dd2ad648ddfcbf4a7e5b1a3a4ecfe7f64667a3f0b7e2f4418588ed35a2458cffeb39b93d26f18d2ab13bdce6aee58e7b99359ec2dfd95a9c16dc00d6ef18b7933a6f8dc65ccb55667138776f7dea101070dc8796e3774df84f40ae0c8229d0d6069e5c8f39a7c299677a09d367fc7b05e3bc380ee652cdc72595f74c7b1043d0e1ffbab734648c838dfb0527d971b602bc216c9619ef0abf5ac974a1ed57f4050aa510dd9c74f508277b39d7973bb2dfccc5eeb0618db8cd74046ff337f0a7bf2c8e03e10f642c1886798d71806ab1e888d9e5ee87d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertNotEq(postState, bytes32(0));
}
......@@ -59,7 +59,7 @@ contract MIPS_Test is CommonTest {
expect.registers[17] = state.registers[17];
expect.registers[18] = state.registers[18];
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -79,7 +79,7 @@ contract MIPS_Test is CommonTest {
expect.registers[17] = state.registers[17];
expect.registers[18] = state.registers[18];
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -99,7 +99,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = state.registers[17] + imm;
expect.registers[17] = state.registers[17];
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -119,7 +119,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = 0;
expect.registers[17] = state.registers[17];
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -139,7 +139,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = state.registers[17] + imm;
expect.registers[17] = state.registers[17];
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -159,7 +159,7 @@ contract MIPS_Test is CommonTest {
expect.registers[17] = state.registers[17];
expect.registers[18] = state.registers[18];
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -179,7 +179,7 @@ contract MIPS_Test is CommonTest {
expect.registers[17] = state.registers[17];
expect.registers[18] = state.registers[18];
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -199,7 +199,7 @@ contract MIPS_Test is CommonTest {
expect.registers[17] = state.registers[17];
expect.registers[18] = state.registers[18];
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -219,7 +219,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = state.registers[17] & imm;
expect.registers[17] = state.registers[17];
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -239,7 +239,7 @@ contract MIPS_Test is CommonTest {
expect.registers[17] = state.registers[17];
expect.registers[18] = state.registers[18];
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -259,7 +259,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = state.registers[17] | imm;
expect.registers[17] = state.registers[17];
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -279,7 +279,7 @@ contract MIPS_Test is CommonTest {
expect.registers[17] = state.registers[17];
expect.registers[18] = state.registers[18];
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -299,7 +299,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = state.registers[17] ^ imm;
expect.registers[17] = state.registers[17];
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -319,7 +319,7 @@ contract MIPS_Test is CommonTest {
expect.registers[17] = state.registers[17];
expect.registers[18] = state.registers[18];
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -338,7 +338,7 @@ contract MIPS_Test is CommonTest {
expect.registers[17] = state.registers[17];
expect.registers[18] = state.registers[18];
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
// swap and check again
......@@ -348,7 +348,7 @@ contract MIPS_Test is CommonTest {
expect.registers[17] = state.registers[17];
expect.registers[18] = state.registers[18];
expect.registers[8] = 0; // t0
postState = mips.step(encodeState(state), proof);
postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -368,7 +368,7 @@ contract MIPS_Test is CommonTest {
expect.registers[17] = state.registers[17];
expect.registers[18] = state.registers[18];
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -388,7 +388,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = 0x12; // t0
expect.registers[9] = t1;
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -410,7 +410,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = 0x12_23; // t0
expect.registers[9] = t1;
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -432,7 +432,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = val; // t0
expect.registers[9] = t1;
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -452,7 +452,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = 0x12; // t0
expect.registers[9] = t1;
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -472,7 +472,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = 0x12_23; // t0
expect.registers[9] = t1;
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -491,7 +491,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = 0x12_34_56_78; // t0
expect.registers[9] = t1;
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
// test unaligned address
......@@ -499,7 +499,7 @@ contract MIPS_Test is CommonTest {
(state.memRoot, proof) = ffi.getCannonMemoryProof(0, insn, t1 + 4, 0x12_34_56_78);
expect.memRoot = state.memRoot;
expect.registers[8] = 0x34_56_78_dd; // t0
postState = mips.step(encodeState(state), proof);
postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -518,7 +518,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = 0xaa_bb_cc_12; // t0
expect.registers[9] = t1;
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
// test unaligned address
......@@ -526,7 +526,7 @@ contract MIPS_Test is CommonTest {
(state.memRoot, proof) = ffi.getCannonMemoryProof(0, insn, t1 + 4, 0x12_34_56_78);
expect.memRoot = state.memRoot;
expect.registers[8] = 0xaa_bb_12_34; // t0
postState = mips.step(encodeState(state), proof);
postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -546,7 +546,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = state.registers[8];
expect.registers[9] = state.registers[9];
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -565,7 +565,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = state.registers[8];
expect.registers[9] = state.registers[9];
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -584,7 +584,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = state.registers[8];
expect.registers[9] = state.registers[9];
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -603,7 +603,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = state.registers[8];
expect.registers[9] = state.registers[9];
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -622,7 +622,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = state.registers[8];
expect.registers[9] = state.registers[9];
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -644,7 +644,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = val; // t0
expect.registers[9] = t1;
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -663,7 +663,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = 0x1;
expect.registers[9] = state.registers[9];
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -684,13 +684,13 @@ contract MIPS_Test is CommonTest {
expect.registers[9] = state.registers[9];
expect.registers[10] = state.registers[10];
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
state.registers[10] = 0x0; // t2
expect.registers[10] = 0x0; // t2
expect.registers[8] = state.registers[8];
postState = mips.step(encodeState(state), proof);
postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -711,13 +711,13 @@ contract MIPS_Test is CommonTest {
expect.registers[9] = state.registers[9];
expect.registers[10] = state.registers[10];
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
state.registers[10] = 0x1; // t2
expect.registers[10] = 0x1; // t2
expect.registers[8] = state.registers[8];
postState = mips.step(encodeState(state), proof);
postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -734,7 +734,7 @@ contract MIPS_Test is CommonTest {
expect.lo = state.lo;
expect.registers[8] = state.lo;
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -751,7 +751,7 @@ contract MIPS_Test is CommonTest {
expect.hi = state.hi;
expect.registers[8] = state.hi;
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -768,7 +768,7 @@ contract MIPS_Test is CommonTest {
expect.hi = state.registers[8];
expect.registers[8] = state.registers[8];
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -785,7 +785,7 @@ contract MIPS_Test is CommonTest {
expect.lo = state.registers[8];
expect.registers[8] = state.registers[8];
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -804,7 +804,7 @@ contract MIPS_Test is CommonTest {
expect.registers[9] = 5;
expect.registers[10] = 2;
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -825,7 +825,7 @@ contract MIPS_Test is CommonTest {
expect.hi = 0x6;
bytes memory enc = encodeState(state);
bytes32 postState = mips.step(enc, proof);
bytes32 postState = mips.step(enc, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -846,7 +846,7 @@ contract MIPS_Test is CommonTest {
expect.hi = 0x6;
bytes memory enc = encodeState(state);
bytes32 postState = mips.step(enc, proof);
bytes32 postState = mips.step(enc, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -867,7 +867,7 @@ contract MIPS_Test is CommonTest {
expect.hi = 1;
bytes memory enc = encodeState(state);
bytes32 postState = mips.step(enc, proof);
bytes32 postState = mips.step(enc, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -888,7 +888,7 @@ contract MIPS_Test is CommonTest {
expect.hi = 1;
bytes memory enc = encodeState(state);
bytes32 postState = mips.step(enc, proof);
bytes32 postState = mips.step(enc, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -907,14 +907,14 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = 0xdeadbeef;
expect.registers[9] = 0xdeadbeef;
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
// branch not taken
state.registers[8] = 0xaa;
expect.registers[8] = 0xaa;
expect.nextPC = state.nextPC + 4;
postState = mips.step(encodeState(state), proof);
postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -933,7 +933,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = 0xdeadbeef;
expect.registers[9] = 0xaa;
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -950,7 +950,7 @@ contract MIPS_Test is CommonTest {
expect.step = state.step + 1;
expect.registers[8] = 0;
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -968,7 +968,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = 1;
bytes memory enc = encodeState(state);
bytes32 postState = mips.step(enc, proof);
bytes32 postState = mips.step(enc, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -985,7 +985,7 @@ contract MIPS_Test is CommonTest {
expect.step = state.step + 1;
expect.registers[8] = 0xF0_00_00_00;
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1002,7 +1002,7 @@ contract MIPS_Test is CommonTest {
expect.step = state.step + 1;
expect.registers[8] = 0x00_00_00_01;
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1017,7 +1017,7 @@ contract MIPS_Test is CommonTest {
expect.nextPC = label << 2;
expect.step = state.step + 1;
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1034,7 +1034,7 @@ contract MIPS_Test is CommonTest {
expect.step = state.step + 1;
bytes memory witness = encodeState(state);
bytes32 postState = mips.step(witness, proof);
bytes32 postState = mips.step(witness, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1050,7 +1050,7 @@ contract MIPS_Test is CommonTest {
expect.step = state.step + 1;
expect.registers[31] = state.pc + 8; // ra
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1067,7 +1067,7 @@ contract MIPS_Test is CommonTest {
expect.step = state.step + 1;
expect.registers[31] = state.pc + 8; // ra
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1084,7 +1084,7 @@ contract MIPS_Test is CommonTest {
expect.step = state.step + 1;
expect.registers[8] = tgt;
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1102,7 +1102,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = tgt;
expect.registers[9] = state.pc + 8; // t1
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1121,7 +1121,7 @@ contract MIPS_Test is CommonTest {
expect.registers[9] = state.registers[9];
bytes memory enc = encodeState(state);
bytes32 postState = mips.step(enc, proof);
bytes32 postState = mips.step(enc, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1140,7 +1140,7 @@ contract MIPS_Test is CommonTest {
expect.registers[9] = state.registers[9];
bytes memory enc = encodeState(state);
bytes32 postState = mips.step(enc, proof);
bytes32 postState = mips.step(enc, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1159,7 +1159,7 @@ contract MIPS_Test is CommonTest {
expect.registers[9] = state.registers[9];
bytes memory enc = encodeState(state);
bytes32 postState = mips.step(enc, proof);
bytes32 postState = mips.step(enc, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1179,7 +1179,7 @@ contract MIPS_Test is CommonTest {
expect.registers[10] = state.registers[10];
bytes memory enc = encodeState(state);
bytes32 postState = mips.step(enc, proof);
bytes32 postState = mips.step(enc, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1199,7 +1199,7 @@ contract MIPS_Test is CommonTest {
expect.registers[10] = state.registers[10];
bytes memory enc = encodeState(state);
bytes32 postState = mips.step(enc, proof);
bytes32 postState = mips.step(enc, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1219,7 +1219,7 @@ contract MIPS_Test is CommonTest {
expect.registers[10] = state.registers[10];
bytes memory enc = encodeState(state);
bytes32 postState = mips.step(enc, proof);
bytes32 postState = mips.step(enc, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1235,7 +1235,7 @@ contract MIPS_Test is CommonTest {
expect.step = state.step + 1;
expect.registers[8] = 0x00_04_00_00; // t0
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1252,7 +1252,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = 8; // t0
expect.registers[9] = state.registers[9];
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1269,7 +1269,7 @@ contract MIPS_Test is CommonTest {
expect.registers[8] = 16; // t0
expect.registers[9] = state.registers[9];
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1306,7 +1306,7 @@ contract MIPS_Test is CommonTest {
bytes32 word = bytes32(uint256(0xdeadbeef) << 224);
uint8 size = 4;
uint8 partOffset = 8;
oracle.loadLocalData(uint256(state.preimageKey), word, size, partOffset);
oracle.loadLocalData(uint256(state.preimageKey), 0, word, size, partOffset);
MIPS.State memory expect = state;
expect.preimageOffset += 4;
......@@ -1318,7 +1318,7 @@ contract MIPS_Test is CommonTest {
// recompute merkle root of written pre-image
(expect.memRoot,) = ffi.getCannonMemoryProof(pc, insn, a1, 0xdeadbeef);
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1360,7 +1360,7 @@ contract MIPS_Test is CommonTest {
expect.registers[2] = 4; // return
expect.registers[7] = 0; // errno
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1387,7 +1387,7 @@ contract MIPS_Test is CommonTest {
expect.registers[4] = 0x0; // a0
expect.registers[5] = 4095; // a1
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1406,7 +1406,7 @@ contract MIPS_Test is CommonTest {
expect.registers[2] = 0x40000000;
expect.registers[4] = state.registers[4]; // registers unchanged
bytes32 postState = mips.step(encodedState, proof);
bytes32 postState = mips.step(encodedState, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1423,7 +1423,7 @@ contract MIPS_Test is CommonTest {
expect.registers[2] = 1;
bytes memory enc = encodeState(state);
bytes32 postState = mips.step(enc, proof);
bytes32 postState = mips.step(enc, proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1443,7 +1443,7 @@ contract MIPS_Test is CommonTest {
expect.exited = true;
expect.exitCode = uint8(state.registers[4]);
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1462,14 +1462,14 @@ contract MIPS_Test is CommonTest {
expect.registers[2] = 0;
expect.registers[5] = state.registers[5];
bytes32 postState = mips.step(encodeState(state), proof);
bytes32 postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
// assert O_WRONLY
state.registers[4] = 0x1; // a0
expect.registers[4] = state.registers[4];
expect.registers[2] = 1;
postState = mips.step(encodeState(state), proof);
postState = mips.step(encodeState(state), proof, 0);
assertEq(postState, outputState(expect), "unexpected post state");
}
......@@ -1479,7 +1479,7 @@ contract MIPS_Test is CommonTest {
state.exited = true;
bytes memory enc = encodeState(state);
bytes32 postState = mips.step(enc, proof);
bytes32 postState = mips.step(enc, proof, 0);
assertEq(postState, outputState(state), "unexpected post state");
}
......@@ -1494,7 +1494,7 @@ contract MIPS_Test is CommonTest {
state.memRoot = memRoot;
bytes memory encodedState = encodeState(state);
vm.expectRevert("invalid instruction");
mips.step(encodedState, proof);
mips.step(encodedState, proof, 0);
}
function test_invalid_root_fails() external {
......@@ -1508,7 +1508,7 @@ contract MIPS_Test is CommonTest {
proof[i] = 0x0;
}
vm.expectRevert(hex"000000000000000000000000000000000000000000000000000000000badf00d");
mips.step(encodeState(state), proof);
mips.step(encodeState(state), proof, 0);
}
function test_jump_inDelaySlot_fails() external {
......@@ -1518,7 +1518,7 @@ contract MIPS_Test is CommonTest {
state.nextPC = 0xa;
vm.expectRevert("jump in delay slot");
mips.step(encodeState(state), proof);
mips.step(encodeState(state), proof, 0);
}
function test_branch_inDelaySlot_fails() external {
......@@ -1530,7 +1530,7 @@ contract MIPS_Test is CommonTest {
state.nextPC = 0xa;
vm.expectRevert("branch in delay slot");
mips.step(encodeState(state), proof);
mips.step(encodeState(state), proof, 0);
}
function encodeState(MIPS.State memory state) internal pure returns (bytes memory) {
......
......@@ -32,7 +32,7 @@ contract PreimageOracle_Test is Test {
uint8 partOffset = 0;
// Load the local data into the preimage oracle under the test contract's context.
bytes32 contextKey = oracle.loadLocalData(ident, word, size, partOffset);
bytes32 contextKey = oracle.loadLocalData(ident, 0, word, size, partOffset);
// Validate that the pre-image part is set
bool ok = oracle.preimagePartOk(contextKey, partOffset);
......@@ -50,6 +50,7 @@ contract PreimageOracle_Test is Test {
/// @notice Tests that context-specific data [0, 32] bytes in length can be loaded correctly.
function testFuzz_loadLocalData_varyingLength_succeeds(
uint256 ident,
uint256 localContext,
bytes32 word,
uint256 size,
uint256 partOffset
......@@ -62,7 +63,7 @@ contract PreimageOracle_Test is Test {
partOffset = bound(partOffset, 0, size + 8);
// Load the local data into the preimage oracle under the test contract's context.
bytes32 contextKey = oracle.loadLocalData(ident, word, uint8(size), uint8(partOffset));
bytes32 contextKey = oracle.loadLocalData(ident, localContext, word, uint8(size), uint8(partOffset));
// Validate that the first local data part is set
bool ok = oracle.preimagePartOk(contextKey, partOffset);
......@@ -112,7 +113,7 @@ contract PreimageOracle_Test is Test {
uint256 offset = preimage.length + 9;
vm.expectRevert(PartOffsetOOB.selector);
oracle.loadLocalData(1, preimage, 32, offset);
oracle.loadLocalData(1, 0, preimage, 32, offset);
}
/// @notice Tests that a pre-image cannot be set with an out-of-bounds offset.
......
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