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
33690dab
Commit
33690dab
authored
Jul 24, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify `loadLocalData` to work with the program
parent
d1460d95
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
111 additions
and
106 deletions
+111
-106
faultdisputegame.go
op-bindings/bindings/faultdisputegame.go
+14
-14
faultdisputegame_more.go
op-bindings/bindings/faultdisputegame_more.go
+1
-1
preimageoracle.go
op-bindings/bindings/preimageoracle.go
+14
-14
preimageoracle_more.go
op-bindings/bindings/preimageoracle_more.go
+2
-2
.gas-snapshot
packages/contracts-bedrock/.gas-snapshot
+32
-32
PreimageOracle.sol
packages/contracts-bedrock/src/cannon/PreimageOracle.sol
+19
-16
FaultDisputeGame.sol
packages/contracts-bedrock/src/dispute/FaultDisputeGame.sol
+6
-6
IBigStepper.sol
.../contracts-bedrock/src/dispute/interfaces/IBigStepper.sol
+2
-1
IFaultDisputeGame.sol
...acts-bedrock/src/dispute/interfaces/IFaultDisputeGame.sol
+2
-1
PreimageOracle.t.sol
packages/contracts-bedrock/test/PreimageOracle.t.sol
+19
-19
No files found.
op-bindings/bindings/faultdisputegame.go
View file @
33690dab
This diff is collapsed.
Click to expand it.
op-bindings/bindings/faultdisputegame_more.go
View file @
33690dab
This diff is collapsed.
Click to expand it.
op-bindings/bindings/preimageoracle.go
View file @
33690dab
This diff is collapsed.
Click to expand it.
op-bindings/bindings/preimageoracle_more.go
View file @
33690dab
This diff is collapsed.
Click to expand it.
packages/contracts-bedrock/.gas-snapshot
View file @
33690dab
...
...
@@ -85,36 +85,36 @@ 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: 50
2209
)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 508
98
9)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 505
730
)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 508
88
7)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 50
8226
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 500
974
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 507
75
4)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 504
495
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 505
65
2)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 504
991
)
FaultDisputeGame_Test:test_extraData_succeeds() (gas: 174
49
)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 50
1957
)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 508
75
9)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 505
478
)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 508
65
7)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 50
7974
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 500
722
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 507
52
4)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 504
243
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 505
42
2)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 504
739
)
FaultDisputeGame_Test:test_extraData_succeeds() (gas: 174
04
)
FaultDisputeGame_Test:test_gameData_succeeds() (gas: 17939)
FaultDisputeGame_Test:test_gameStart_succeeds() (gas: 10
293
)
FaultDisputeGame_Test:test_gameType_succeeds() (gas: 82
38
)
FaultDisputeGame_Test:test_initialRootClaimData_succeeds() (gas: 176
69
)
FaultDisputeGame_Test:test_move_clockCorrectness_succeeds() (gas: 419
317
)
FaultDisputeGame_Test:test_move_clockTimeExceeded_reverts() (gas: 26
399
)
FaultDisputeGame_Test:test_move_defendRoot_reverts() (gas: 133
38
)
FaultDisputeGame_Test:test_move_duplicateClaim_reverts() (gas: 104
076
)
FaultDisputeGame_Test:test_move_gameDepthExceeded_reverts() (gas: 411
414
)
FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 1
0968
)
FaultDisputeGame_Test:test_move_nonExistentParent_reverts() (gas: 246
33
)
FaultDisputeGame_Test:test_move_simpleAttack_succeeds() (gas: 1081
78
)
FaultDisputeGame_Test:test_resolve_challengeContested_succeeds() (gas: 226
490
)
FaultDisputeGame_Test:test_resolve_notInProgress_reverts() (gas: 9
702
)
FaultDisputeGame_Test:test_resolve_rootContested_succeeds() (gas: 11064
3
)
FaultDisputeGame_Test:test_resolve_rootUncontestedClockNotExpired_succeeds() (gas: 214
82
)
FaultDisputeGame_Test:test_resolve_rootUncontested_succeeds() (gas: 27
311
)
FaultDisputeGame_Test:test_resolve_teamDeathmatch_succeeds() (gas: 398
794
)
FaultDisputeGame_Test:test_rootClaim_succeeds() (gas: 82
03
)
FaultDisputeGame_Test:test_gameStart_succeeds() (gas: 10
315
)
FaultDisputeGame_Test:test_gameType_succeeds() (gas: 82
60
)
FaultDisputeGame_Test:test_initialRootClaimData_succeeds() (gas: 176
24
)
FaultDisputeGame_Test:test_move_clockCorrectness_succeeds() (gas: 419
180
)
FaultDisputeGame_Test:test_move_clockTimeExceeded_reverts() (gas: 26
421
)
FaultDisputeGame_Test:test_move_defendRoot_reverts() (gas: 133
60
)
FaultDisputeGame_Test:test_move_duplicateClaim_reverts() (gas: 104
120
)
FaultDisputeGame_Test:test_move_gameDepthExceeded_reverts() (gas: 411
546
)
FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 1
1012
)
FaultDisputeGame_Test:test_move_nonExistentParent_reverts() (gas: 246
77
)
FaultDisputeGame_Test:test_move_simpleAttack_succeeds() (gas: 1081
10
)
FaultDisputeGame_Test:test_resolve_challengeContested_succeeds() (gas: 226
511
)
FaultDisputeGame_Test:test_resolve_notInProgress_reverts() (gas: 9
657
)
FaultDisputeGame_Test:test_resolve_rootContested_succeeds() (gas: 11064
2
)
FaultDisputeGame_Test:test_resolve_rootUncontestedClockNotExpired_succeeds() (gas: 214
37
)
FaultDisputeGame_Test:test_resolve_rootUncontested_succeeds() (gas: 27
288
)
FaultDisputeGame_Test:test_resolve_teamDeathmatch_succeeds() (gas: 398
859
)
FaultDisputeGame_Test:test_rootClaim_succeeds() (gas: 82
25
)
FeeVault_Test:test_constructor_succeeds() (gas: 18185)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 352113)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_1() (gas: 2950320)
...
...
@@ -436,9 +436,9 @@ OptimistTest:test_tokenIdOfAddress_returnsOwnerID_succeeds() (gas: 63730)
OptimistTest:test_tokenURI_returnsCorrectTokenURI_succeeds() (gas: 195908)
OptimistTest:test_transferFrom_soulbound_reverts() (gas: 75512)
PreimageOracle_Test:test_keccak256PreimageKey_succeeds() (gas: 420)
PreimageOracle_Test:test_loadKeccak256PreimagePart_outOfBoundsOffset_reverts() (gas: 88
42
)
PreimageOracle_Test:test_loadKeccak256PreimagePart_succeeds() (gas: 76
496
)
PreimageOracle_Test:test_loadLocalData_onePart_succeeds() (gas: 76
266
)
PreimageOracle_Test:test_loadKeccak256PreimagePart_outOfBoundsOffset_reverts() (gas: 88
64
)
PreimageOracle_Test:test_loadKeccak256PreimagePart_succeeds() (gas: 76
518
)
PreimageOracle_Test:test_loadLocalData_onePart_succeeds() (gas: 76
339
)
ProxyAdmin_Test:test_chugsplashChangeProxyAdmin_succeeds() (gas: 35586)
ProxyAdmin_Test:test_chugsplashGetProxyAdmin_succeeds() (gas: 15675)
ProxyAdmin_Test:test_chugsplashGetProxyImplementation_succeeds() (gas: 51084)
...
...
packages/contracts-bedrock/src/cannon/PreimageOracle.sol
View file @
33690dab
...
...
@@ -74,31 +74,34 @@ contract PreimageOracle {
function loadLocalData(
uint256 _ident,
bytes32 _word,
uint8 _size
uint256 _size,
uint256 _partOffset
) external returns (bytes32 key_) {
// Compute the localized key from the given local identifier.
key_ = PreimageKeyLib.localizeIdent(_ident);
// Load both parts of the local data word into storage for future
// reads.
bytes32 part1;
assembly {
// The first part is prepended with an 8 byte length prefix and contains
// the first 24 bytes of the passed word.
part1 := or(shl(192, _size), shr(64, _word))
// Revert if the given part offset is not within bounds.
if (_partOffset > _size + 8 || _size > 32) {
revert("part offset must be within bounds");
}
// Store the first part with offset 0.
preimagePartOk[key_][0] = true;
preimageParts[key_][0] = part1;
// Prepare the local data part at the given offset
bytes32 part;
assembly {
// Clean the memory in [0x20, 0x40)
mstore(0x20, 0x00)
// Store the full local data in scratch space.
mstore(0x00, shl(192, _size))
mstore(0x08, _word)
// If the size is greater than 24, we need to store a second part as well.
if (_size > 24) {
bytes32 part2 = _word << 192;
preimagePartOk[key_][32] = true;
preimageParts[key_][32] = part2;
// Prepare the local data part at the requested offset.
part := mload(_partOffset)
}
// Store the first part with `_partOffset`.
preimagePartOk[key_][_partOffset] = true;
preimageParts[key_][_partOffset] = part;
// Assign the length of the preimage at the localized key.
preimageLengths[key_] = _size;
}
...
...
packages/contracts-bedrock/src/dispute/FaultDisputeGame.sol
View file @
33690dab
...
...
@@ -252,34 +252,34 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
}
/// @inheritdoc IFaultDisputeGame
function addLocalData(uint256 _ident) external {
function addLocalData(uint256 _ident
, uint256 _partOffset
) external {
// INVARIANT: Local data can only be added if the game is currently in progress.
if (status != GameStatus.IN_PROGRESS) revert GameNotInProgress();
IPreimageOracle oracle = VM.oracle();
if (_ident == 1) {
// Load the L1 head hash into the game's local context in the preimage oracle.
oracle.loadLocalData(_ident, Hash.unwrap(l1Head), 32);
oracle.loadLocalData(_ident, Hash.unwrap(l1Head), 32
, _partOffset
);
} else if (_ident == 2) {
// Load the earliest output root that commits to the passed L2 block number
// into the game's local context in the preimage oracle.
Types.OutputProposal memory proposal = L2_OUTPUT_ORACLE.getL2OutputAfter(
l2BlockNumber()
);
oracle.loadLocalData(_ident, proposal.outputRoot, 32);
oracle.loadLocalData(_ident, proposal.outputRoot, 32
, _partOffset
);
} else if (_ident == 3) {
// Load the root claim into the game's local context in the preimage oracle.
oracle.loadLocalData(_ident, Claim.unwrap(rootClaim()), 32);
oracle.loadLocalData(_ident, Claim.unwrap(rootClaim()), 32
, _partOffset
);
} else if (_ident == 4) {
// Load the L2 block number into the game's local context in the preimage oracle.
// The L2 block number is stored as a big-endian uint64 in the upper 8 bytes of the
// passed word.
oracle.loadLocalData(_ident, bytes32(l2BlockNumber() << 192), 8);
oracle.loadLocalData(_ident, bytes32(l2BlockNumber() << 192), 8
, _partOffset
);
} else if (_ident == 5) {
// Load the chain ID into the game's local context in the preimage oracle.
// The chain ID is stored as a big-endian uint64 in the upper 8 bytes of the
// passed word.
oracle.loadLocalData(_ident, bytes32(block.chainid << 192), 8);
oracle.loadLocalData(_ident, bytes32(block.chainid << 192), 8
, _partOffset
);
}
}
...
...
packages/contracts-bedrock/src/dispute/interfaces/IBigStepper.sol
View file @
33690dab
...
...
@@ -42,6 +42,7 @@ interface IPreimageOracle {
function loadLocalData(
uint256 _ident,
bytes32 _word,
uint8 _size
uint256 _size,
uint256 _partOffset
) external returns (bytes32 key_);
}
packages/contracts-bedrock/src/dispute/interfaces/IFaultDisputeGame.sol
View file @
33690dab
...
...
@@ -55,7 +55,8 @@ 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.
function addLocalData(uint256 _ident) external;
/// @param _partOffset The offset of the data to post.
function addLocalData(uint256 _ident, uint256 _partOffset) external;
/// @notice Returns the L1 block hash at the time of the game's creation.
function l1Head() external view returns (Hash l1Head_);
...
...
packages/contracts-bedrock/test/PreimageOracle.t.sol
View file @
33690dab
...
...
@@ -29,17 +29,18 @@ contract PreimageOracle_Test is Test {
uint256 ident = 1;
bytes32 word = bytes32(uint256(0xdeadbeef) << 224);
uint8 size = 4;
uint8 partOffset = 0;
// Load the local data into the preimage oracle under the test contract's context.
bytes32 contextKey = oracle.loadLocalData(ident, word, size);
bytes32 contextKey = oracle.loadLocalData(ident, word, size
, partOffset
);
// Validate that the pre-image part is set
bool ok = oracle.preimagePartOk(contextKey,
0
);
bool ok = oracle.preimagePartOk(contextKey,
partOffset
);
assertTrue(ok);
// Validate the local data part
bytes32 expectedPart = 0x0000000000000004deadbeef0000000000000000000000000000000000000000;
assertEq(oracle.preimageParts(contextKey,
0
), expectedPart);
assertEq(oracle.preimageParts(contextKey,
partOffset
), expectedPart);
// Validate the local data length
uint256 length = oracle.preimageLengths(contextKey);
...
...
@@ -50,32 +51,31 @@ contract PreimageOracle_Test is Test {
function testFuzz_loadLocalData_varyingLength_succeeds(
uint256 ident,
bytes32 word,
uint256 size
uint256 size,
uint256 partOffset
) public {
// Bound the size to [0, 32]
size = bound(size, 0, 32);
// Bound the part offset to [0, size + 8]
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));
bytes32 contextKey = oracle.loadLocalData(ident, word, uint8(size)
, uint8(partOffset)
);
// Validate that the first local data part is set
bool ok = oracle.preimagePartOk(contextKey,
0
);
bool ok = oracle.preimagePartOk(contextKey,
partOffset
);
assertTrue(ok);
// Validate the first local data part
bytes32 expectedPart1 = bytes32((size << 192) | (uint256(word) >> 64));
assertEq(oracle.preimageParts(contextKey, 0), expectedPart1);
// If the size is > 24, validate the second part. Otherwise, ensure
// that the second part is not set.
ok = oracle.preimagePartOk(contextKey, 32);
if (size > 24) {
assertTrue(ok);
// Validate the second local data part
bytes32 expectedPart2 = word << 192;
assertEq(oracle.preimageParts(contextKey, 32), expectedPart2);
} else {
assertFalse(ok);
bytes32 expectedPart;
assembly {
mstore(0x20, 0x00)
mstore(0x00, shl(192, size))
mstore(0x08, word)
expectedPart := mload(partOffset)
}
assertEq(oracle.preimageParts(contextKey, partOffset), expectedPart);
// Validate the local data length
uint256 length = oracle.preimageLengths(contextKey);
...
...
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