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
713ad666
Commit
713ad666
authored
Jul 20, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add preimage oracle tests
parent
41dff4ad
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
80 additions
and
22 deletions
+80
-22
faultdisputegame.go
op-bindings/bindings/faultdisputegame.go
+1
-1
faultdisputegame_more.go
op-bindings/bindings/faultdisputegame_more.go
+1
-1
preimageoracle.go
op-bindings/bindings/preimageoracle.go
+3
-3
PreimageOracle.sol
packages/contracts-bedrock/src/cannon/PreimageOracle.sol
+16
-16
IBigStepper.sol
.../contracts-bedrock/src/dispute/interfaces/IBigStepper.sol
+1
-1
PreimageOracle.t.sol
packages/contracts-bedrock/test/PreimageOracle.t.sol
+58
-0
No files found.
op-bindings/bindings/faultdisputegame.go
View file @
713ad666
This diff is collapsed.
Click to expand it.
op-bindings/bindings/faultdisputegame_more.go
View file @
713ad666
This diff is collapsed.
Click to expand it.
op-bindings/bindings/preimageoracle.go
View file @
713ad666
...
@@ -383,21 +383,21 @@ func (_PreimageOracle *PreimageOracleTransactorSession) LoadKeccak256PreimagePar
...
@@ -383,21 +383,21 @@ func (_PreimageOracle *PreimageOracleTransactorSession) LoadKeccak256PreimagePar
// LoadLocalData is a paid mutator transaction binding the contract method 0xe52f0937.
// LoadLocalData is a paid mutator transaction binding the contract method 0xe52f0937.
//
//
// Solidity: function loadLocalData(uint256 _ident, bytes32 _word, uint8 _size) returns()
// Solidity: function loadLocalData(uint256 _ident, bytes32 _word, uint8 _size) returns(
bytes32 key_
)
func
(
_PreimageOracle
*
PreimageOracleTransactor
)
LoadLocalData
(
opts
*
bind
.
TransactOpts
,
_ident
*
big
.
Int
,
_word
[
32
]
byte
,
_size
uint8
)
(
*
types
.
Transaction
,
error
)
{
func
(
_PreimageOracle
*
PreimageOracleTransactor
)
LoadLocalData
(
opts
*
bind
.
TransactOpts
,
_ident
*
big
.
Int
,
_word
[
32
]
byte
,
_size
uint8
)
(
*
types
.
Transaction
,
error
)
{
return
_PreimageOracle
.
contract
.
Transact
(
opts
,
"loadLocalData"
,
_ident
,
_word
,
_size
)
return
_PreimageOracle
.
contract
.
Transact
(
opts
,
"loadLocalData"
,
_ident
,
_word
,
_size
)
}
}
// LoadLocalData is a paid mutator transaction binding the contract method 0xe52f0937.
// LoadLocalData is a paid mutator transaction binding the contract method 0xe52f0937.
//
//
// Solidity: function loadLocalData(uint256 _ident, bytes32 _word, uint8 _size) returns()
// Solidity: function loadLocalData(uint256 _ident, bytes32 _word, uint8 _size) returns(
bytes32 key_
)
func
(
_PreimageOracle
*
PreimageOracleSession
)
LoadLocalData
(
_ident
*
big
.
Int
,
_word
[
32
]
byte
,
_size
uint8
)
(
*
types
.
Transaction
,
error
)
{
func
(
_PreimageOracle
*
PreimageOracleSession
)
LoadLocalData
(
_ident
*
big
.
Int
,
_word
[
32
]
byte
,
_size
uint8
)
(
*
types
.
Transaction
,
error
)
{
return
_PreimageOracle
.
Contract
.
LoadLocalData
(
&
_PreimageOracle
.
TransactOpts
,
_ident
,
_word
,
_size
)
return
_PreimageOracle
.
Contract
.
LoadLocalData
(
&
_PreimageOracle
.
TransactOpts
,
_ident
,
_word
,
_size
)
}
}
// LoadLocalData is a paid mutator transaction binding the contract method 0xe52f0937.
// LoadLocalData is a paid mutator transaction binding the contract method 0xe52f0937.
//
//
// Solidity: function loadLocalData(uint256 _ident, bytes32 _word, uint8 _size) returns()
// Solidity: function loadLocalData(uint256 _ident, bytes32 _word, uint8 _size) returns(
bytes32 key_
)
func
(
_PreimageOracle
*
PreimageOracleTransactorSession
)
LoadLocalData
(
_ident
*
big
.
Int
,
_word
[
32
]
byte
,
_size
uint8
)
(
*
types
.
Transaction
,
error
)
{
func
(
_PreimageOracle
*
PreimageOracleTransactorSession
)
LoadLocalData
(
_ident
*
big
.
Int
,
_word
[
32
]
byte
,
_size
uint8
)
(
*
types
.
Transaction
,
error
)
{
return
_PreimageOracle
.
Contract
.
LoadLocalData
(
&
_PreimageOracle
.
TransactOpts
,
_ident
,
_word
,
_size
)
return
_PreimageOracle
.
Contract
.
LoadLocalData
(
&
_PreimageOracle
.
TransactOpts
,
_ident
,
_word
,
_size
)
}
}
packages/contracts-bedrock/src/cannon/PreimageOracle.sol
View file @
713ad666
...
@@ -62,22 +62,22 @@ contract PreimageOracle {
...
@@ -62,22 +62,22 @@ contract PreimageOracle {
/// specific data.
/// specific data.
///
///
/// There are 5 local data identifiers:
/// There are 5 local data identifiers:
/// ┌────────────┬─────────────────┐
/// ┌────────────┬─────────────────
───────
┐
/// │ Identifier │ Data │
/// │ Identifier │ Data
│
/// ├────────────┼─────────────────┤
/// ├────────────┼─────────────────
───────
┤
/// │ 1 │ L1 Head Hash
│
/// │ 1 │ L1 Head Hash
(bytes32)
│
/// │ 2 │ Output Root
│
/// │ 2 │ Output Root
(bytes32)
│
/// │ 3 │ Root Claim
│
/// │ 3 │ Root Claim
(bytes32)
│
/// │ 4 │ L2 Block Number │
/// │ 4 │ L2 Block Number
(u64)
│
/// │ 5 │ Chain ID │
/// │ 5 │ Chain ID
(u64)
│
/// └────────────┴─────────────────┘
/// └────────────┴─────────────────
───────
┘
function loadLocalData(
function loadLocalData(
uint256 _ident,
uint256 _ident,
bytes32 _word,
bytes32 _word,
uint8 _size
uint8 _size
) external {
) external
returns (bytes32 key_)
{
// Compute the localized key from the given local identifier.
// Compute the localized key from the given local identifier.
bytes32 key
= PreimageKeyLib.localizeIdent(_ident);
key_
= PreimageKeyLib.localizeIdent(_ident);
// Load both parts of the local data word into storage for future
// Load both parts of the local data word into storage for future
// reads.
// reads.
...
@@ -89,18 +89,18 @@ contract PreimageOracle {
...
@@ -89,18 +89,18 @@ contract PreimageOracle {
}
}
// Store the first part with offset 0.
// Store the first part with offset 0.
preimagePartOk[key][0] = true;
preimagePartOk[key
_
][0] = true;
preimageParts[key][0] = part1;
preimageParts[key
_
][0] = part1;
// If the size is greater than 24, we need to store a second part as well.
// If the size is greater than 24, we need to store a second part as well.
if (_size > 24) {
if (_size > 24) {
bytes32 part2 = _word << 192;
bytes32 part2 = _word << 192;
preimagePartOk[key][32] = true;
preimagePartOk[key
_
][32] = true;
preimageParts[key][32] = part2;
preimageParts[key
_
][32] = part2;
}
}
// 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;
}
}
/// @notice Prepares a pre-image to be read by keccak256 key, starting at
/// @notice Prepares a pre-image to be read by keccak256 key, starting at
...
...
packages/contracts-bedrock/src/dispute/interfaces/IBigStepper.sol
View file @
713ad666
...
@@ -43,5 +43,5 @@ interface IPreimageOracle {
...
@@ -43,5 +43,5 @@ interface IPreimageOracle {
uint256 _ident,
uint256 _ident,
bytes32 _word,
bytes32 _word,
uint8 _size
uint8 _size
) external;
) external
returns (bytes32 key_)
;
}
}
packages/contracts-bedrock/test/PreimageOracle.t.sol
View file @
713ad666
...
@@ -24,6 +24,64 @@ contract PreimageOracle_Test is Test {
...
@@ -24,6 +24,64 @@ contract PreimageOracle_Test is Test {
assertEq(key, known);
assertEq(key, known);
}
}
/// @notice Tests that context-specific data [0, 24] bytes in length can be loaded correctly.
function test_loadLocalData_onePart_succeeds() public {
uint256 ident = 1;
bytes32 word = bytes32(uint256(0xdeadbeef) << 224);
uint8 size = 4;
// Load the local data into the preimage oracle under the test contract's context.
bytes32 contextKey = oracle.loadLocalData(ident, word, size);
// Validate that the pre-image part is set
bool ok = oracle.preimagePartOk(contextKey, 0);
assertTrue(ok);
// Validate the local data part
bytes32 expectedPart = 0x0000000000000004deadbeef0000000000000000000000000000000000000000;
assertEq(oracle.preimageParts(contextKey, 0), expectedPart);
// Validate the local data length
uint256 length = oracle.preimageLengths(contextKey);
assertEq(length, size);
}
/// @notice Tests that context-specific data [0, 32] bytes in length can be loaded correctly.
function testFuzz_loadLocalData_varyingLength_succeeds(
uint256 ident,
bytes32 word,
uint256 size
) public {
// Bound the size to [0, 32]
size = bound(size, 0, 32);
// Load the local data into the preimage oracle under the test contract's context.
bytes32 contextKey = oracle.loadLocalData(ident, word, uint8(size));
// Validate that the first local data part is set
bool ok = oracle.preimagePartOk(contextKey, 0);
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);
}
// Validate the local data length
uint256 length = oracle.preimageLengths(contextKey);
assertEq(length, size);
}
/// @notice Tests that a pre-image is correctly set.
/// @notice Tests that a pre-image is correctly set.
function test_loadKeccak256PreimagePart_succeeds() public {
function test_loadKeccak256PreimagePart_succeeds() public {
// Set the pre-image
// Set the pre-image
...
...
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