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
Show 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)
...
@@ -85,36 +85,36 @@ FaucetTest:test_nonAdmin_drip_fails() (gas: 262520)
FaucetTest:test_receive_succeeds() (gas: 17401)
FaucetTest:test_receive_succeeds() (gas: 17401)
FaucetTest:test_withdraw_nonAdmin_reverts() (gas: 13145)
FaucetTest:test_withdraw_nonAdmin_reverts() (gas: 13145)
FaucetTest:test_withdraw_succeeds() (gas: 78359)
FaucetTest:test_withdraw_succeeds() (gas: 78359)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 50
2209
)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 50
1957
)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 508
98
9)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 508
75
9)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 505
730
)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 505
478
)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 508
88
7)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 508
65
7)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 50
8226
)
FaultDisputeGame_ResolvesCorrectly_CorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 50
7974
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 500
974
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot1:test_resolvesCorrectly_succeeds() (gas: 500
722
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 507
75
4)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot2:test_resolvesCorrectly_succeeds() (gas: 507
52
4)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 504
495
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot3:test_resolvesCorrectly_succeeds() (gas: 504
243
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 505
65
2)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot4:test_resolvesCorrectly_succeeds() (gas: 505
42
2)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 504
991
)
FaultDisputeGame_ResolvesCorrectly_IncorrectRoot5:test_resolvesCorrectly_succeeds() (gas: 504
739
)
FaultDisputeGame_Test:test_extraData_succeeds() (gas: 174
49
)
FaultDisputeGame_Test:test_extraData_succeeds() (gas: 174
04
)
FaultDisputeGame_Test:test_gameData_succeeds() (gas: 17939)
FaultDisputeGame_Test:test_gameData_succeeds() (gas: 17939)
FaultDisputeGame_Test:test_gameStart_succeeds() (gas: 10
293
)
FaultDisputeGame_Test:test_gameStart_succeeds() (gas: 10
315
)
FaultDisputeGame_Test:test_gameType_succeeds() (gas: 82
38
)
FaultDisputeGame_Test:test_gameType_succeeds() (gas: 82
60
)
FaultDisputeGame_Test:test_initialRootClaimData_succeeds() (gas: 176
69
)
FaultDisputeGame_Test:test_initialRootClaimData_succeeds() (gas: 176
24
)
FaultDisputeGame_Test:test_move_clockCorrectness_succeeds() (gas: 419
317
)
FaultDisputeGame_Test:test_move_clockCorrectness_succeeds() (gas: 419
180
)
FaultDisputeGame_Test:test_move_clockTimeExceeded_reverts() (gas: 26
399
)
FaultDisputeGame_Test:test_move_clockTimeExceeded_reverts() (gas: 26
421
)
FaultDisputeGame_Test:test_move_defendRoot_reverts() (gas: 133
38
)
FaultDisputeGame_Test:test_move_defendRoot_reverts() (gas: 133
60
)
FaultDisputeGame_Test:test_move_duplicateClaim_reverts() (gas: 104
076
)
FaultDisputeGame_Test:test_move_duplicateClaim_reverts() (gas: 104
120
)
FaultDisputeGame_Test:test_move_gameDepthExceeded_reverts() (gas: 411
414
)
FaultDisputeGame_Test:test_move_gameDepthExceeded_reverts() (gas: 411
546
)
FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 1
0968
)
FaultDisputeGame_Test:test_move_gameNotInProgress_reverts() (gas: 1
1012
)
FaultDisputeGame_Test:test_move_nonExistentParent_reverts() (gas: 246
33
)
FaultDisputeGame_Test:test_move_nonExistentParent_reverts() (gas: 246
77
)
FaultDisputeGame_Test:test_move_simpleAttack_succeeds() (gas: 1081
78
)
FaultDisputeGame_Test:test_move_simpleAttack_succeeds() (gas: 1081
10
)
FaultDisputeGame_Test:test_resolve_challengeContested_succeeds() (gas: 226
490
)
FaultDisputeGame_Test:test_resolve_challengeContested_succeeds() (gas: 226
511
)
FaultDisputeGame_Test:test_resolve_notInProgress_reverts() (gas: 9
702
)
FaultDisputeGame_Test:test_resolve_notInProgress_reverts() (gas: 9
657
)
FaultDisputeGame_Test:test_resolve_rootContested_succeeds() (gas: 11064
3
)
FaultDisputeGame_Test:test_resolve_rootContested_succeeds() (gas: 11064
2
)
FaultDisputeGame_Test:test_resolve_rootUncontestedClockNotExpired_succeeds() (gas: 214
82
)
FaultDisputeGame_Test:test_resolve_rootUncontestedClockNotExpired_succeeds() (gas: 214
37
)
FaultDisputeGame_Test:test_resolve_rootUncontested_succeeds() (gas: 27
311
)
FaultDisputeGame_Test:test_resolve_rootUncontested_succeeds() (gas: 27
288
)
FaultDisputeGame_Test:test_resolve_teamDeathmatch_succeeds() (gas: 398
794
)
FaultDisputeGame_Test:test_resolve_teamDeathmatch_succeeds() (gas: 398
859
)
FaultDisputeGame_Test:test_rootClaim_succeeds() (gas: 82
03
)
FaultDisputeGame_Test:test_rootClaim_succeeds() (gas: 82
25
)
FeeVault_Test:test_constructor_succeeds() (gas: 18185)
FeeVault_Test:test_constructor_succeeds() (gas: 18185)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 352113)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_0() (gas: 352113)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_1() (gas: 2950320)
GasBenchMark_L1CrossDomainMessenger:test_sendMessage_benchmark_1() (gas: 2950320)
...
@@ -436,9 +436,9 @@ OptimistTest:test_tokenIdOfAddress_returnsOwnerID_succeeds() (gas: 63730)
...
@@ -436,9 +436,9 @@ OptimistTest:test_tokenIdOfAddress_returnsOwnerID_succeeds() (gas: 63730)
OptimistTest:test_tokenURI_returnsCorrectTokenURI_succeeds() (gas: 195908)
OptimistTest:test_tokenURI_returnsCorrectTokenURI_succeeds() (gas: 195908)
OptimistTest:test_transferFrom_soulbound_reverts() (gas: 75512)
OptimistTest:test_transferFrom_soulbound_reverts() (gas: 75512)
PreimageOracle_Test:test_keccak256PreimageKey_succeeds() (gas: 420)
PreimageOracle_Test:test_keccak256PreimageKey_succeeds() (gas: 420)
PreimageOracle_Test:test_loadKeccak256PreimagePart_outOfBoundsOffset_reverts() (gas: 88
42
)
PreimageOracle_Test:test_loadKeccak256PreimagePart_outOfBoundsOffset_reverts() (gas: 88
64
)
PreimageOracle_Test:test_loadKeccak256PreimagePart_succeeds() (gas: 76
496
)
PreimageOracle_Test:test_loadKeccak256PreimagePart_succeeds() (gas: 76
518
)
PreimageOracle_Test:test_loadLocalData_onePart_succeeds() (gas: 76
266
)
PreimageOracle_Test:test_loadLocalData_onePart_succeeds() (gas: 76
339
)
ProxyAdmin_Test:test_chugsplashChangeProxyAdmin_succeeds() (gas: 35586)
ProxyAdmin_Test:test_chugsplashChangeProxyAdmin_succeeds() (gas: 35586)
ProxyAdmin_Test:test_chugsplashGetProxyAdmin_succeeds() (gas: 15675)
ProxyAdmin_Test:test_chugsplashGetProxyAdmin_succeeds() (gas: 15675)
ProxyAdmin_Test:test_chugsplashGetProxyImplementation_succeeds() (gas: 51084)
ProxyAdmin_Test:test_chugsplashGetProxyImplementation_succeeds() (gas: 51084)
...
...
packages/contracts-bedrock/src/cannon/PreimageOracle.sol
View file @
33690dab
...
@@ -74,31 +74,34 @@ contract PreimageOracle {
...
@@ -74,31 +74,34 @@ contract PreimageOracle {
function loadLocalData(
function loadLocalData(
uint256 _ident,
uint256 _ident,
bytes32 _word,
bytes32 _word,
uint8 _size
uint256 _size,
uint256 _partOffset
) external returns (bytes32 key_) {
) external returns (bytes32 key_) {
// Compute the localized key from the given local identifier.
// Compute the localized key from the given local identifier.
key_ = PreimageKeyLib.localizeIdent(_ident);
key_ = PreimageKeyLib.localizeIdent(_ident);
// Load both parts of the local data word into storage for future
// Revert if the given part offset is not within bounds.
// reads.
if (_partOffset > _size + 8 || _size > 32) {
bytes32 part1;
revert("part offset must be within bounds");
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))
}
}
// Store the first part with offset 0.
// Prepare the local data part at the given offset
preimagePartOk[key_][0] = true;
bytes32 part;
preimageParts[key_][0] = part1;
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.
// Prepare the local data part at the requested offset.
if (_size > 24) {
part := mload(_partOffset)
bytes32 part2 = _word << 192;
preimagePartOk[key_][32] = true;
preimageParts[key_][32] = part2;
}
}
// Store the first part with `_partOffset`.
preimagePartOk[key_][_partOffset] = true;
preimageParts[key_][_partOffset] = part;
// Assign the length of the preimage at the localized key.
// Assign the length of the preimage at the localized key.
preimageLengths[key_] = _size;
preimageLengths[key_] = _size;
}
}
...
...
packages/contracts-bedrock/src/dispute/FaultDisputeGame.sol
View file @
33690dab
...
@@ -252,34 +252,34 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
...
@@ -252,34 +252,34 @@ contract FaultDisputeGame is IFaultDisputeGame, Clone, Semver {
}
}
/// @inheritdoc IFaultDisputeGame
/// @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.
// INVARIANT: Local data can only be added if the game is currently in progress.
if (status != GameStatus.IN_PROGRESS) revert GameNotInProgress();
if (status != GameStatus.IN_PROGRESS) revert GameNotInProgress();
IPreimageOracle oracle = VM.oracle();
IPreimageOracle oracle = VM.oracle();
if (_ident == 1) {
if (_ident == 1) {
// Load the L1 head hash into the game's local context in the preimage oracle.
// 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) {
} else if (_ident == 2) {
// Load the earliest output root that commits to the passed L2 block number
// Load the earliest output root that commits to the passed L2 block number
// into the game's local context in the preimage oracle.
// into the game's local context in the preimage oracle.
Types.OutputProposal memory proposal = L2_OUTPUT_ORACLE.getL2OutputAfter(
Types.OutputProposal memory proposal = L2_OUTPUT_ORACLE.getL2OutputAfter(
l2BlockNumber()
l2BlockNumber()
);
);
oracle.loadLocalData(_ident, proposal.outputRoot, 32);
oracle.loadLocalData(_ident, proposal.outputRoot, 32
, _partOffset
);
} else if (_ident == 3) {
} else if (_ident == 3) {
// Load the root claim into the game's local context in the preimage oracle.
// 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) {
} else if (_ident == 4) {
// Load the L2 block number into the game's local context in the preimage oracle.
// 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
// The L2 block number is stored as a big-endian uint64 in the upper 8 bytes of the
// passed word.
// passed word.
oracle.loadLocalData(_ident, bytes32(l2BlockNumber() << 192), 8);
oracle.loadLocalData(_ident, bytes32(l2BlockNumber() << 192), 8
, _partOffset
);
} else if (_ident == 5) {
} else if (_ident == 5) {
// Load the chain ID into the game's local context in the preimage oracle.
// 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
// The chain ID is stored as a big-endian uint64 in the upper 8 bytes of the
// passed word.
// 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 {
...
@@ -42,6 +42,7 @@ interface IPreimageOracle {
function loadLocalData(
function loadLocalData(
uint256 _ident,
uint256 _ident,
bytes32 _word,
bytes32 _word,
uint8 _size
uint256 _size,
uint256 _partOffset
) external returns (bytes32 key_);
) external returns (bytes32 key_);
}
}
packages/contracts-bedrock/src/dispute/interfaces/IFaultDisputeGame.sol
View file @
33690dab
...
@@ -55,7 +55,8 @@ interface IFaultDisputeGame is IDisputeGame {
...
@@ -55,7 +55,8 @@ interface IFaultDisputeGame is IDisputeGame {
/// @notice Posts the requested local data to the VM's `PreimageOralce`.
/// @notice Posts the requested local data to the VM's `PreimageOralce`.
/// @param _ident The local identifier of the data to post.
/// @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.
/// @notice Returns the L1 block hash at the time of the game's creation.
function l1Head() external view returns (Hash l1Head_);
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 {
...
@@ -29,17 +29,18 @@ contract PreimageOracle_Test is Test {
uint256 ident = 1;
uint256 ident = 1;
bytes32 word = bytes32(uint256(0xdeadbeef) << 224);
bytes32 word = bytes32(uint256(0xdeadbeef) << 224);
uint8 size = 4;
uint8 size = 4;
uint8 partOffset = 0;
// Load the local data into the preimage oracle under the test contract's context.
// 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
// Validate that the pre-image part is set
bool ok = oracle.preimagePartOk(contextKey,
0
);
bool ok = oracle.preimagePartOk(contextKey,
partOffset
);
assertTrue(ok);
assertTrue(ok);
// Validate the local data part
// Validate the local data part
bytes32 expectedPart = 0x0000000000000004deadbeef0000000000000000000000000000000000000000;
bytes32 expectedPart = 0x0000000000000004deadbeef0000000000000000000000000000000000000000;
assertEq(oracle.preimageParts(contextKey,
0
), expectedPart);
assertEq(oracle.preimageParts(contextKey,
partOffset
), expectedPart);
// Validate the local data length
// Validate the local data length
uint256 length = oracle.preimageLengths(contextKey);
uint256 length = oracle.preimageLengths(contextKey);
...
@@ -50,32 +51,31 @@ contract PreimageOracle_Test is Test {
...
@@ -50,32 +51,31 @@ contract PreimageOracle_Test is Test {
function testFuzz_loadLocalData_varyingLength_succeeds(
function testFuzz_loadLocalData_varyingLength_succeeds(
uint256 ident,
uint256 ident,
bytes32 word,
bytes32 word,
uint256 size
uint256 size,
uint256 partOffset
) public {
) public {
// Bound the size to [0, 32]
// Bound the size to [0, 32]
size = bound(size, 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.
// 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
// Validate that the first local data part is set
bool ok = oracle.preimagePartOk(contextKey,
0
);
bool ok = oracle.preimagePartOk(contextKey,
partOffset
);
assertTrue(ok);
assertTrue(ok);
// Validate the first local data part
// Validate the first local data part
bytes32 expectedPart1 = bytes32((size << 192) | (uint256(word) >> 64));
bytes32 expectedPart;
assertEq(oracle.preimageParts(contextKey, 0), expectedPart1);
assembly {
mstore(0x20, 0x00)
// If the size is > 24, validate the second part. Otherwise, ensure
mstore(0x00, shl(192, size))
// that the second part is not set.
mstore(0x08, word)
ok = oracle.preimagePartOk(contextKey, 32);
if (size > 24) {
expectedPart := mload(partOffset)
assertTrue(ok);
// Validate the second local data part
bytes32 expectedPart2 = word << 192;
assertEq(oracle.preimageParts(contextKey, 32), expectedPart2);
} else {
assertFalse(ok);
}
}
assertEq(oracle.preimageParts(contextKey, partOffset), expectedPart);
// Validate the local data length
// Validate the local data length
uint256 length = oracle.preimageLengths(contextKey);
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