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
eb055622
Commit
eb055622
authored
Oct 10, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Begin contextualization of local keys
parent
5f2ad00c
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
250 additions
and
229 deletions
+250
-229
.gas-snapshot
packages/contracts-bedrock/.gas-snapshot
+112
-112
MIPS.sol
packages/contracts-bedrock/src/cannon/MIPS.sol
+17
-12
PreimageKeyLib.sol
packages/contracts-bedrock/src/cannon/PreimageKeyLib.sol
+11
-4
PreimageOracle.sol
packages/contracts-bedrock/src/cannon/PreimageOracle.sol
+2
-1
IPreimageOracle.sol
...ntracts-bedrock/src/cannon/interfaces/IPreimageOracle.sol
+3
-0
FaultDisputeGame.sol
packages/contracts-bedrock/src/dispute/FaultDisputeGame.sol
+7
-5
IFaultDisputeGame.sol
...acts-bedrock/src/dispute/interfaces/IFaultDisputeGame.sol
+3
-1
FaultDisputeGame.t.sol
packages/contracts-bedrock/test/FaultDisputeGame.t.sol
+8
-8
MIPS.t.sol
packages/contracts-bedrock/test/MIPS.t.sol
+83
-83
PreimageOracle.t.sol
packages/contracts-bedrock/test/PreimageOracle.t.sol
+4
-3
No files found.
packages/contracts-bedrock/.gas-snapshot
View file @
eb055622
...
...
@@ -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: 6
6041
1)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 66
7293
)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 663
97
4)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 66
7169
)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 666
46
0)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 65
3092
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 658
598
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 655
943
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 656
899
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 65
6332
)
FaultDisputeGame_Test:test_addLocalData_static_succeeds() (gas: 64
0567
)
FaultDisputeGame_Test:test_createdAt_succeeds() (gas: 10
342
)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 6
5995
1)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 66
6811
)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 663
51
4)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 66
6687
)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 666
00
0)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 65
2724
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 658
212
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 655
575
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 656
513
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 65
5964
)
FaultDisputeGame_Test:test_addLocalData_static_succeeds() (gas: 64
2642
)
FaultDisputeGame_Test:test_createdAt_succeeds() (gas: 10
409
)
FaultDisputeGame_Test:test_extraData_succeeds() (gas: 32328)
FaultDisputeGame_Test:test_gameData_succeeds() (gas: 327
55
)
FaultDisputeGame_Test:test_gameData_succeeds() (gas: 327
77
)
FaultDisputeGame_Test:test_gameType_succeeds() (gas: 8265)
FaultDisputeGame_Test:test_initialize_correctData_succeeds() (gas: 57
712
)
FaultDisputeGame_Test:test_initialize_firstOutput_reverts() (gas: 210
563
)
FaultDisputeGame_Test:test_initialize_l1HeadTooOld_reverts() (gas: 2284
01
)
FaultDisputeGame_Test:test_move_clockCorrectness_succeeds() (gas: 594
268
)
FaultDisputeGame_Test:test_initialize_correctData_succeeds() (gas: 57
646
)
FaultDisputeGame_Test:test_initialize_firstOutput_reverts() (gas: 210
650
)
FaultDisputeGame_Test:test_initialize_l1HeadTooOld_reverts() (gas: 2284
66
)
FaultDisputeGame_Test:test_move_clockCorrectness_succeeds() (gas: 594
025
)
FaultDisputeGame_Test:test_move_clockTimeExceeded_reverts() (gas: 23175)
FaultDisputeGame_Test:test_move_defendRoot_reverts() (gas: 133
66
)
FaultDisputeGame_Test:test_move_duplicateClaim_reverts() (gas: 1473
89
)
FaultDisputeGame_Test:test_move_duplicateClaimsDifferentSubgames_succeeds() (gas: 5568
85
)
FaultDisputeGame_Test:test_move_gameDepthExceeded_reverts() (gas: 5858
97
)
FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 1
1002
)
FaultDisputeGame_Test:test_move_nonExistentParent_reverts() (gas: 246
66
)
FaultDisputeGame_Test:test_move_simpleAttack_succeeds() (gas: 1519
59
)
FaultDisputeGame_Test:test_resolve_challengeContested_succeeds() (gas: 2694
13
)
FaultDisputeGame_Test:test_resolve_claimAlreadyResolved_reverts() (gas: 2723
56
)
FaultDisputeGame_Test:test_resolve_claimAtMaxDepthAlreadyResolved_reverts() (gas: 5866
72
)
FaultDisputeGame_Test:test_resolve_notInProgress_reverts() (gas: 97
32
)
FaultDisputeGame_Test:test_resolve_outOfOrderResolution_reverts() (gas: 3090
37
)
FaultDisputeGame_Test:test_resolve_rootContested_succeeds() (gas: 1390
44
)
FaultDisputeGame_Test:test_resolve_rootUncontestedButUnresolved_reverts() (gas: 1588
3
)
FaultDisputeGame_Test:test_resolve_rootUncontestedClockNotExpired_succeeds() (gas: 184
06
)
FaultDisputeGame_Test:test_resolve_rootUncontested_succeeds() (gas: 514
09
)
FaultDisputeGame_Test:test_resolve_stepReached_succeeds() (gas: 4984
7
6)
FaultDisputeGame_Test:test_resolve_teamDeathmatch_succeeds() (gas: 4433
73
)
FaultDisputeGame_Test:test_move_defendRoot_reverts() (gas: 133
00
)
FaultDisputeGame_Test:test_move_duplicateClaim_reverts() (gas: 1473
67
)
FaultDisputeGame_Test:test_move_duplicateClaimsDifferentSubgames_succeeds() (gas: 5568
31
)
FaultDisputeGame_Test:test_move_gameDepthExceeded_reverts() (gas: 5858
53
)
FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 1
0980
)
FaultDisputeGame_Test:test_move_nonExistentParent_reverts() (gas: 246
44
)
FaultDisputeGame_Test:test_move_simpleAttack_succeeds() (gas: 1519
15
)
FaultDisputeGame_Test:test_resolve_challengeContested_succeeds() (gas: 2694
32
)
FaultDisputeGame_Test:test_resolve_claimAlreadyResolved_reverts() (gas: 2723
34
)
FaultDisputeGame_Test:test_resolve_claimAtMaxDepthAlreadyResolved_reverts() (gas: 5866
06
)
FaultDisputeGame_Test:test_resolve_notInProgress_reverts() (gas: 97
54
)
FaultDisputeGame_Test:test_resolve_outOfOrderResolution_reverts() (gas: 3090
15
)
FaultDisputeGame_Test:test_resolve_rootContested_succeeds() (gas: 1390
90
)
FaultDisputeGame_Test:test_resolve_rootUncontestedButUnresolved_reverts() (gas: 1588
4
)
FaultDisputeGame_Test:test_resolve_rootUncontestedClockNotExpired_succeeds() (gas: 184
28
)
FaultDisputeGame_Test:test_resolve_rootUncontested_succeeds() (gas: 514
10
)
FaultDisputeGame_Test:test_resolve_stepReached_succeeds() (gas: 4984
0
6)
FaultDisputeGame_Test:test_resolve_teamDeathmatch_succeeds() (gas: 4433
57
)
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: 1224
20
)
MIPS_Test:test_addiSign_succeeds() (gas: 1224
11
)
MIPS_Test:test_addi_succeeds() (gas: 1226
08
)
MIPS_Test:test_addu_succeeds() (gas: 122
462
)
MIPS_Test:test_addui_succeeds() (gas: 122
670
)
MIPS_Test:test_and_succeeds() (gas: 122
481
)
MIPS_Test:test_andi_succeeds() (gas: 1224
14
)
MIPS_Test:test_beq_succeeds() (gas: 2028
01
)
MIPS_Test:test_bgez_succeeds() (gas: 1217
07
)
MIPS_Test:test_bgtz_succeeds() (gas: 1216
28
)
MIPS_Test:test_blez_succeeds() (gas: 121
584
)
MIPS_Test:test_bltz_succeeds() (gas: 1217
27
)
MIPS_Test:test_bne_succeeds() (gas: 121
793
)
MIPS_Test:test_branch_inDelaySlot_fails() (gas: 8
5999
)
MIPS_Test:test_brk_succeeds() (gas: 122
092
)
MIPS_Test:test_clo_succeeds() (gas: 1221
49
)
MIPS_Test:test_clone_succeeds() (gas: 1220
45
)
MIPS_Test:test_clz_succeeds() (gas: 1226
20
)
MIPS_Test:test_div_succeeds() (gas: 122
599
)
MIPS_Test:test_divu_succeeds() (gas: 122
584
)
MIPS_Test:test_exit_succeeds() (gas: 122
094
)
MIPS_Test:test_fcntl_succeeds() (gas: 204
273
)
MIPS_Test:test_illegal_instruction_fails() (gas: 91
462
)
MIPS_Test:test_invalid_root_fails() (gas: 4356
36
)
MIPS_Test:test_jal_nonzeroRegion_succeeds() (gas: 1207
37
)
MIPS_Test:test_jal_succeeds() (gas: 1207
26
)
MIPS_Test:test_jalr_succeeds() (gas: 1218
45
)
MIPS_Test:test_jr_succeeds() (gas: 1215
39
)
MIPS_Test:test_jump_inDelaySlot_fails() (gas: 85
367
)
MIPS_Test:test_jump_nonzeroRegion_succeeds() (gas: 120
481
)
MIPS_Test:test_jump_succeeds() (gas: 1204
11
)
MIPS_Test:test_lb_succeeds() (gas: 1276
52
)
MIPS_Test:test_lbu_succeeds() (gas: 1275
50
)
MIPS_Test:test_lh_succeeds() (gas: 127
673
)
MIPS_Test:test_lhu_succeeds() (gas: 127
590
)
MIPS_Test:test_ll_succeeds() (gas: 1278
12
)
MIPS_Test:test_lui_succeeds() (gas: 121
693
)
MIPS_Test:test_lw_succeeds() (gas: 1274
41
)
MIPS_Test:test_lwl_succeeds() (gas: 242
046
)
MIPS_Test:test_lwr_succeeds() (gas: 242
334
)
MIPS_Test:test_mfhi_succeeds() (gas: 122
054
)
MIPS_Test:test_mflo_succeeds() (gas: 122
183
)
MIPS_Test:test_mmap_succeeds() (gas: 1190
12
)
MIPS_Test:test_movn_succeeds() (gas: 203
473
)
MIPS_Test:test_movz_succeeds() (gas: 203
341
)
MIPS_Test:test_mthi_succeeds() (gas: 122
098
)
MIPS_Test:test_mtlo_succeeds() (gas: 1222
06
)
MIPS_Test:test_mul_succeeds() (gas: 121
698
)
MIPS_Test:test_mult_succeeds() (gas: 1224
02
)
MIPS_Test:test_multu_succeeds() (gas: 1224
39
)
MIPS_Test:test_nor_succeeds() (gas: 1225
31
)
MIPS_Test:test_or_succeeds() (gas: 122
488
)
MIPS_Test:test_ori_succeeds() (gas: 122
491
)
MIPS_Test:test_preimage_read_succeeds() (gas: 234
408
)
MIPS_Test:test_preimage_write_succeeds() (gas: 1270
34
)
MIPS_Test:test_prestate_exited_succeeds() (gas: 113
280
)
MIPS_Test:test_sb_succeeds() (gas: 1605
23
)
MIPS_Test:test_sc_succeeds() (gas: 1607
17
)
MIPS_Test:test_sh_succeeds() (gas: 160
560
)
MIPS_Test:test_sll_succeeds() (gas: 121
659
)
MIPS_Test:test_sllv_succeeds() (gas: 121
888
)
MIPS_Test:test_slt_succeeds() (gas: 204
668
)
MIPS_Test:test_sltu_succeeds() (gas: 1227
05
)
MIPS_Test:test_sra_succeeds() (gas: 1219
10
)
MIPS_Test:test_srav_succeeds() (gas: 122
178
)
MIPS_Test:test_srl_succeeds() (gas: 1217
41
)
MIPS_Test:test_srlv_succeeds() (gas: 1219
06
)
MIPS_Test:test_step_abi_succeeds() (gas: 584
1
7)
MIPS_Test:test_sub_succeeds() (gas: 1225
15
)
MIPS_Test:test_subu_succeeds() (gas: 1225
12
)
MIPS_Test:test_sw_succeeds() (gas: 1605
35
)
MIPS_Test:test_swl_succeeds() (gas: 160
596
)
MIPS_Test:test_swr_succeeds() (gas: 160
671
)
MIPS_Test:test_xor_succeeds() (gas: 1225
16
)
MIPS_Test:test_xori_succeeds() (gas: 122
568
)
MIPS_Test:test_add_succeeds() (gas: 1224
66
)
MIPS_Test:test_addiSign_succeeds() (gas: 1224
57
)
MIPS_Test:test_addi_succeeds() (gas: 1226
54
)
MIPS_Test:test_addu_succeeds() (gas: 122
508
)
MIPS_Test:test_addui_succeeds() (gas: 122
716
)
MIPS_Test:test_and_succeeds() (gas: 122
527
)
MIPS_Test:test_andi_succeeds() (gas: 1224
60
)
MIPS_Test:test_beq_succeeds() (gas: 2028
93
)
MIPS_Test:test_bgez_succeeds() (gas: 1217
53
)
MIPS_Test:test_bgtz_succeeds() (gas: 1216
74
)
MIPS_Test:test_blez_succeeds() (gas: 121
630
)
MIPS_Test:test_bltz_succeeds() (gas: 1217
73
)
MIPS_Test:test_bne_succeeds() (gas: 121
839
)
MIPS_Test:test_branch_inDelaySlot_fails() (gas: 8
6048
)
MIPS_Test:test_brk_succeeds() (gas: 122
143
)
MIPS_Test:test_clo_succeeds() (gas: 1221
95
)
MIPS_Test:test_clone_succeeds() (gas: 1220
96
)
MIPS_Test:test_clz_succeeds() (gas: 1226
66
)
MIPS_Test:test_div_succeeds() (gas: 122
645
)
MIPS_Test:test_divu_succeeds() (gas: 122
630
)
MIPS_Test:test_exit_succeeds() (gas: 122
145
)
MIPS_Test:test_fcntl_succeeds() (gas: 204
375
)
MIPS_Test:test_illegal_instruction_fails() (gas: 91
511
)
MIPS_Test:test_invalid_root_fails() (gas: 4356
85
)
MIPS_Test:test_jal_nonzeroRegion_succeeds() (gas: 1207
83
)
MIPS_Test:test_jal_succeeds() (gas: 1207
72
)
MIPS_Test:test_jalr_succeeds() (gas: 1218
91
)
MIPS_Test:test_jr_succeeds() (gas: 1215
85
)
MIPS_Test:test_jump_inDelaySlot_fails() (gas: 85
416
)
MIPS_Test:test_jump_nonzeroRegion_succeeds() (gas: 120
527
)
MIPS_Test:test_jump_succeeds() (gas: 1204
57
)
MIPS_Test:test_lb_succeeds() (gas: 1276
98
)
MIPS_Test:test_lbu_succeeds() (gas: 1275
96
)
MIPS_Test:test_lh_succeeds() (gas: 127
719
)
MIPS_Test:test_lhu_succeeds() (gas: 127
636
)
MIPS_Test:test_ll_succeeds() (gas: 1278
58
)
MIPS_Test:test_lui_succeeds() (gas: 121
739
)
MIPS_Test:test_lw_succeeds() (gas: 1274
87
)
MIPS_Test:test_lwl_succeeds() (gas: 242
138
)
MIPS_Test:test_lwr_succeeds() (gas: 242
426
)
MIPS_Test:test_mfhi_succeeds() (gas: 122
100
)
MIPS_Test:test_mflo_succeeds() (gas: 122
229
)
MIPS_Test:test_mmap_succeeds() (gas: 1190
63
)
MIPS_Test:test_movn_succeeds() (gas: 203
565
)
MIPS_Test:test_movz_succeeds() (gas: 203
433
)
MIPS_Test:test_mthi_succeeds() (gas: 122
144
)
MIPS_Test:test_mtlo_succeeds() (gas: 1222
52
)
MIPS_Test:test_mul_succeeds() (gas: 121
744
)
MIPS_Test:test_mult_succeeds() (gas: 1224
48
)
MIPS_Test:test_multu_succeeds() (gas: 1224
85
)
MIPS_Test:test_nor_succeeds() (gas: 1225
77
)
MIPS_Test:test_or_succeeds() (gas: 122
534
)
MIPS_Test:test_ori_succeeds() (gas: 122
537
)
MIPS_Test:test_preimage_read_succeeds() (gas: 234
549
)
MIPS_Test:test_preimage_write_succeeds() (gas: 1270
85
)
MIPS_Test:test_prestate_exited_succeeds() (gas: 113
326
)
MIPS_Test:test_sb_succeeds() (gas: 1605
69
)
MIPS_Test:test_sc_succeeds() (gas: 1607
52
)
MIPS_Test:test_sh_succeeds() (gas: 160
606
)
MIPS_Test:test_sll_succeeds() (gas: 121
705
)
MIPS_Test:test_sllv_succeeds() (gas: 121
934
)
MIPS_Test:test_slt_succeeds() (gas: 204
760
)
MIPS_Test:test_sltu_succeeds() (gas: 1227
51
)
MIPS_Test:test_sra_succeeds() (gas: 1219
56
)
MIPS_Test:test_srav_succeeds() (gas: 122
224
)
MIPS_Test:test_srl_succeeds() (gas: 1217
87
)
MIPS_Test:test_srlv_succeeds() (gas: 1219
52
)
MIPS_Test:test_step_abi_succeeds() (gas: 584
6
7)
MIPS_Test:test_sub_succeeds() (gas: 1225
61
)
MIPS_Test:test_subu_succeeds() (gas: 1225
58
)
MIPS_Test:test_sw_succeeds() (gas: 1605
81
)
MIPS_Test:test_swl_succeeds() (gas: 160
642
)
MIPS_Test:test_swr_succeeds() (gas: 160
717
)
MIPS_Test:test_xor_succeeds() (gas: 1225
62
)
MIPS_Test:test_xori_succeeds() (gas: 122
614
)
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: 75
818
)
PreimageOracle_Test:test_loadLocalData_outOfBoundsOffset_reverts() (gas: 8
803
)
PreimageOracle_Test:test_loadLocalData_onePart_succeeds() (gas: 75
905
)
PreimageOracle_Test:test_loadLocalData_outOfBoundsOffset_reverts() (gas: 8
904
)
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)
...
...
packages/contracts-bedrock/src/cannon/MIPS.sol
View file @
eb055622
...
...
@@ -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
)) {
// 1
00+32+256=388
expected proof offset
if iszero(eq(
_proof.offset, 420
)) {
// 1
32+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
...
...
packages/contracts-bedrock/src/cannon/PreimageKeyLib.sol
View file @
eb055622
...
...
@@ -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)
}
}
...
...
packages/contracts-bedrock/src/cannon/PreimageOracle.sol
View file @
eb055622
...
...
@@ -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) {
...
...
packages/contracts-bedrock/src/cannon/interfaces/IPreimageOracle.sol
View file @
eb055622
...
...
@@ -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
...
...
packages/contracts-bedrock/src/dispute/FaultDisputeGame.sol
View file @
eb055622
...
...
@@ -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(0x
4
0, data)
mstore(0x
6
0, data)
// Store the size of the data to load
// _ident > 3 ? 8 : 32
mstore(0x
6
0, shl(sub(0x05, shl(0x01, gt(_ident, 0x03))), 0x01))
mstore(0x
8
0, shl(sub(0x05, shl(0x01, gt(_ident, 0x03))), 0x01))
// Store the part offset of the data
mstore(0x
8
0, _partOffset)
mstore(0x
A
0, _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, 0x
8
4, 0x00, 0x00)) {
if iszero(call(gas(), oracle, 0x00, 0x1C, 0x
A
4, 0x00, 0x00)) {
returndatacopy(0x00, 0x00, returndatasize())
revert(0x00, returndatasize())
}
...
...
packages/contracts-bedrock/src/dispute/interfaces/IFaultDisputeGame.sol
View file @
eb055622
...
...
@@ -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
...
...
packages/contracts-bedrock/test/FaultDisputeGame.t.sol
View file @
eb055622
...
...
@@ -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));
}
...
...
packages/contracts-bedrock/test/MIPS.t.sol
View file @
eb055622
...
...
@@ -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) {
...
...
packages/contracts-bedrock/test/PreimageOracle.t.sol
View file @
eb055622
...
...
@@ -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.
...
...
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