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
aeed0da3
Unverified
Commit
aeed0da3
authored
Jan 30, 2024
by
Adrian Sutton
Committed by
GitHub
Jan 29, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-challenger: Switch Leaf.Index to uint64 instead of big.Int (#9229)
parent
78e3cbb8
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
44 deletions
+30
-44
oracle.go
op-challenger/game/fault/contracts/oracle.go
+1
-1
oracle_test.go
op-challenger/game/fault/contracts/oracle_test.go
+8
-8
large_test.go
op-challenger/game/fault/preimages/large_test.go
+8
-8
matrix.go
op-challenger/game/keccak/matrix/matrix.go
+7
-7
matrix_test.go
op-challenger/game/keccak/matrix/matrix_test.go
+4
-5
types.go
op-challenger/game/keccak/types/types.go
+2
-15
No files found.
op-challenger/game/fault/contracts/oracle.go
View file @
aeed0da3
...
...
@@ -50,7 +50,7 @@ type PreimageOracleContract struct {
func
toPreimageOracleLeaf
(
l
keccakTypes
.
Leaf
)
bindings
.
PreimageOracleLeaf
{
return
bindings
.
PreimageOracleLeaf
{
Input
:
l
.
Input
[
:
],
Index
:
l
.
Index
,
Index
:
new
(
big
.
Int
)
.
SetUint64
(
l
.
Index
)
,
StateCommitment
:
l
.
StateCommitment
,
}
}
...
...
op-challenger/game/fault/contracts/oracle_test.go
View file @
aeed0da3
...
...
@@ -138,13 +138,13 @@ func TestPreimageOracleContract_Squeeze(t *testing.T) {
stateMatrix
:=
matrix
.
NewStateMatrix
()
preState
:=
keccakTypes
.
Leaf
{
Input
:
[
keccakTypes
.
BlockSize
]
byte
{
0x12
},
Index
:
big
.
NewInt
(
123
)
,
Index
:
123
,
StateCommitment
:
common
.
Hash
{
0x34
},
}
preStateProof
:=
merkle
.
Proof
{{
0x34
}}
postState
:=
keccakTypes
.
Leaf
{
Input
:
[
keccakTypes
.
BlockSize
]
byte
{
0x34
},
Index
:
big
.
NewInt
(
456
)
,
Index
:
456
,
StateCommitment
:
common
.
Hash
{
0x56
},
}
postStateProof
:=
merkle
.
Proof
{{
0x56
}}
...
...
@@ -507,7 +507,7 @@ func TestChallenge_First(t *testing.T) {
Prestate
:
keccakTypes
.
Leaf
{},
Poststate
:
keccakTypes
.
Leaf
{
Input
:
[
136
]
byte
{
5
,
4
,
3
,
2
,
1
},
Index
:
big
.
NewInt
(
0
)
,
Index
:
0
,
StateCommitment
:
common
.
Hash
{
0xbb
},
},
PoststateProof
:
merkle
.
Proof
{
common
.
Hash
{
0x01
},
common
.
Hash
{
0x02
}},
...
...
@@ -517,7 +517,7 @@ func TestChallenge_First(t *testing.T) {
ident
.
Claimant
,
ident
.
UUID
,
bindings
.
PreimageOracleLeaf
{
Input
:
challenge
.
Poststate
.
Input
[
:
],
Index
:
challenge
.
Poststate
.
Index
,
Index
:
new
(
big
.
Int
)
.
SetUint64
(
challenge
.
Poststate
.
Index
)
,
StateCommitment
:
challenge
.
Poststate
.
StateCommitment
,
},
challenge
.
PoststateProof
,
...
...
@@ -539,13 +539,13 @@ func TestChallenge_NotFirst(t *testing.T) {
StateMatrix
:
bytes
.
Repeat
([]
byte
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
},
25
),
Prestate
:
keccakTypes
.
Leaf
{
Input
:
[
136
]
byte
{
9
,
8
,
7
,
6
,
5
},
Index
:
big
.
NewInt
(
3
)
,
Index
:
3
,
StateCommitment
:
common
.
Hash
{
0xcc
},
},
PrestateProof
:
merkle
.
Proof
{
common
.
Hash
{
0x01
},
common
.
Hash
{
0x02
}},
Poststate
:
keccakTypes
.
Leaf
{
Input
:
[
136
]
byte
{
5
,
4
,
3
,
2
,
1
},
Index
:
big
.
NewInt
(
4
)
,
Index
:
4
,
StateCommitment
:
common
.
Hash
{
0xbb
},
},
PoststateProof
:
merkle
.
Proof
{
common
.
Hash
{
0x03
},
common
.
Hash
{
0x04
}},
...
...
@@ -556,13 +556,13 @@ func TestChallenge_NotFirst(t *testing.T) {
abiEncodePackedState
(
challenge
.
StateMatrix
),
bindings
.
PreimageOracleLeaf
{
Input
:
challenge
.
Prestate
.
Input
[
:
],
Index
:
challenge
.
Prestate
.
Index
,
Index
:
new
(
big
.
Int
)
.
SetUint64
(
challenge
.
Prestate
.
Index
)
,
StateCommitment
:
challenge
.
Prestate
.
StateCommitment
,
},
challenge
.
PrestateProof
,
bindings
.
PreimageOracleLeaf
{
Input
:
challenge
.
Poststate
.
Input
[
:
],
Index
:
challenge
.
Poststate
.
Index
,
Index
:
new
(
big
.
Int
)
.
SetUint64
(
challenge
.
Poststate
.
Index
)
,
StateCommitment
:
challenge
.
Poststate
.
StateCommitment
,
},
challenge
.
PoststateProof
,
...
...
op-challenger/game/fault/preimages/large_test.go
View file @
aeed0da3
...
...
@@ -206,12 +206,12 @@ func TestLargePreimageUploader_UploadPreimage_Succeeds(t *testing.T) {
addCalls
:
1
,
prestateLeaf
:
keccakTypes
.
Leaf
{
Input
:
*
fullLeaf
,
Index
:
big
.
NewInt
(
0
)
,
Index
:
0
,
StateCommitment
:
common
.
HexToHash
(
"9788a3b3bc36c482525b5890767be37130c997917bceca6e91a6c93359a4d1c6"
),
},
poststateLeaf
:
keccakTypes
.
Leaf
{
Input
:
[
keccakTypes
.
BlockSize
]
byte
{},
Index
:
big
.
NewInt
(
1
)
,
Index
:
1
,
StateCommitment
:
common
.
HexToHash
(
"78358b902b7774b314bcffdf0948746f18d6044086e76e3924d585dca3486c7d"
),
},
},
...
...
@@ -221,12 +221,12 @@ func TestLargePreimageUploader_UploadPreimage_Succeeds(t *testing.T) {
addCalls
:
1
,
prestateLeaf
:
keccakTypes
.
Leaf
{
Input
:
*
fullLeaf
,
Index
:
big
.
NewInt
(
2
)
,
Index
:
2
,
StateCommitment
:
common
.
HexToHash
(
"e3deed8ab6f8bbcf3d4fe825d74f703b3f2fc2f5b0afaa2574926fcfd0d4c895"
),
},
poststateLeaf
:
keccakTypes
.
Leaf
{
Input
:
[
keccakTypes
.
BlockSize
]
byte
{},
Index
:
big
.
NewInt
(
3
)
,
Index
:
3
,
StateCommitment
:
common
.
HexToHash
(
"79115eeab1ff2eccf5baf3ea2dda13bc79c548ce906bdd16433a23089c679df2"
),
},
},
...
...
@@ -236,12 +236,12 @@ func TestLargePreimageUploader_UploadPreimage_Succeeds(t *testing.T) {
addCalls
:
1
,
prestateLeaf
:
keccakTypes
.
Leaf
{
Input
:
*
fullLeaf
,
Index
:
big
.
NewInt
(
1
)
,
Index
:
1
,
StateCommitment
:
common
.
HexToHash
(
"b5ea400e375b2c1ce348f3cc4ad5b6ad28e1b36759ddd2aba155f0b1d476b015"
),
},
poststateLeaf
:
keccakTypes
.
Leaf
{
Input
:
[
keccakTypes
.
BlockSize
]
byte
{
byte
(
9
)},
Index
:
big
.
NewInt
(
2
)
,
Index
:
2
,
StateCommitment
:
common
.
HexToHash
(
"fa87e115dc4786e699bf80cc75d13ac1e2db0708c1418fc8cbc9800d17b5811a"
),
},
},
...
...
@@ -251,12 +251,12 @@ func TestLargePreimageUploader_UploadPreimage_Succeeds(t *testing.T) {
addCalls
:
2
,
prestateLeaf
:
keccakTypes
.
Leaf
{
Input
:
*
fullLeaf
,
Index
:
big
.
NewInt
(
301
)
,
Index
:
301
,
StateCommitment
:
common
.
HexToHash
(
"4e9c55542478939feca4ff55ee98fbc632bb65a784a55b94536644bc87298ca4"
),
},
poststateLeaf
:
keccakTypes
.
Leaf
{
Input
:
[
keccakTypes
.
BlockSize
]
byte
{},
Index
:
big
.
NewInt
(
302
)
,
Index
:
302
,
StateCommitment
:
common
.
HexToHash
(
"775020bfcaa93700263d040a4eeec3c8c3cf09e178457d04044594beaaf5e20b"
),
},
},
...
...
op-challenger/game/keccak/matrix/matrix.go
View file @
aeed0da3
...
...
@@ -74,9 +74,9 @@ func Challenge(data io.Reader, commitments []common.Hash) (types.Challenge, erro
if
firstInvalidLeaf
!=
(
types
.
Leaf
{})
{
var
prestateProof
merkle
.
Proof
if
lastValidLeaf
!=
(
types
.
Leaf
{})
{
prestateProof
=
s
.
merkleTree
.
ProofAtIndex
(
lastValidLeaf
.
Index
Uint64
()
)
prestateProof
=
s
.
merkleTree
.
ProofAtIndex
(
lastValidLeaf
.
Index
)
}
poststateProof
:=
s
.
merkleTree
.
ProofAtIndex
(
firstInvalidLeaf
.
Index
Uint64
()
)
poststateProof
:=
s
.
merkleTree
.
ProofAtIndex
(
firstInvalidLeaf
.
Index
)
return
types
.
Challenge
{
StateMatrix
:
lastValidState
,
Prestate
:
lastValidLeaf
,
...
...
@@ -113,7 +113,7 @@ func (d *StateMatrix) PackState() []byte {
}
// newLeafWithPadding creates a new [Leaf] from inputs, padding the input to the [BlockSize].
func
newLeafWithPadding
(
input
[]
byte
,
index
*
big
.
Int
,
commitment
common
.
Hash
)
types
.
Leaf
{
func
newLeafWithPadding
(
input
[]
byte
,
index
uint64
,
commitment
common
.
Hash
)
types
.
Leaf
{
// TODO(client-pod#480): Add actual keccak padding to ensure the merkle proofs are correct (for readData)
var
paddedInput
[
types
.
BlockSize
]
byte
copy
(
paddedInput
[
:
],
input
)
...
...
@@ -156,13 +156,13 @@ func (d *StateMatrix) AbsorbUpTo(in io.Reader, maxLen int) (types.InputData, err
// PrestateWithProof returns the prestate leaf with its merkle proof.
func
(
d
*
StateMatrix
)
PrestateWithProof
()
(
types
.
Leaf
,
merkle
.
Proof
)
{
proof
:=
d
.
merkleTree
.
ProofAtIndex
(
d
.
prestateLeaf
.
Index
Uint64
()
)
proof
:=
d
.
merkleTree
.
ProofAtIndex
(
d
.
prestateLeaf
.
Index
)
return
d
.
prestateLeaf
,
proof
}
// PoststateWithProof returns the poststate leaf with its merkle proof.
func
(
d
*
StateMatrix
)
PoststateWithProof
()
(
types
.
Leaf
,
merkle
.
Proof
)
{
proof
:=
d
.
merkleTree
.
ProofAtIndex
(
d
.
poststateLeaf
.
Index
Uint64
()
)
proof
:=
d
.
merkleTree
.
ProofAtIndex
(
d
.
poststateLeaf
.
Index
)
return
d
.
poststateLeaf
,
proof
}
...
...
@@ -193,10 +193,10 @@ func (d *StateMatrix) absorbNextLeafInput(in io.Reader, stateCommitment func() c
commitment
:=
stateCommitment
()
if
d
.
poststateLeaf
==
(
types
.
Leaf
{})
{
d
.
prestateLeaf
=
types
.
Leaf
{}
d
.
poststateLeaf
=
newLeafWithPadding
(
input
,
big
.
NewInt
(
0
)
,
commitment
)
d
.
poststateLeaf
=
newLeafWithPadding
(
input
,
0
,
commitment
)
}
else
{
d
.
prestateLeaf
=
d
.
poststateLeaf
d
.
poststateLeaf
=
newLeafWithPadding
(
input
,
new
(
big
.
Int
)
.
Add
(
d
.
prestateLeaf
.
Index
,
big
.
NewInt
(
1
))
,
commitment
)
d
.
poststateLeaf
=
newLeafWithPadding
(
input
,
d
.
prestateLeaf
.
Index
+
1
,
commitment
)
}
d
.
merkleTree
.
AddLeaf
(
d
.
poststateLeaf
.
Hash
())
if
final
{
...
...
op-challenger/game/keccak/matrix/matrix_test.go
View file @
aeed0da3
...
...
@@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"math/big"
"math/rand"
"testing"
...
...
@@ -291,7 +290,7 @@ func TestVerifyPreimage(t *testing.T) {
for
i
,
commitment
:=
range
commitments
{
leaf
:=
types
.
Leaf
{
Input
:
leafData
(
i
),
Index
:
big
.
NewInt
(
int64
(
i
)
),
Index
:
uint64
(
i
),
StateCommitment
:
commitment
,
}
m
.
AddLeaf
(
leaf
.
Hash
())
...
...
@@ -312,14 +311,14 @@ func TestVerifyPreimage(t *testing.T) {
StateMatrix
:
s
.
PackState
(),
Prestate
:
types
.
Leaf
{
Input
:
prestateLeaf
,
Index
:
big
.
NewInt
(
int64
(
invalidIdx
-
1
)
),
Index
:
uint64
(
invalidIdx
-
1
),
StateCommitment
:
commitments
[
invalidIdx
-
1
],
},
PrestateProof
:
fullMerkle
.
ProofAtIndex
(
uint64
(
invalidIdx
-
1
)),
Poststate
:
types
.
Leaf
{
Input
:
poststateLeaf
,
Index
:
big
.
NewInt
(
int64
(
invalidIdx
)
),
Index
:
uint64
(
invalidIdx
),
StateCommitment
:
commitments
[
invalidIdx
],
},
PoststateProof
:
fullMerkle
.
ProofAtIndex
(
uint64
(
invalidIdx
)),
...
...
@@ -353,7 +352,7 @@ func TestVerifyPreimage(t *testing.T) {
Prestate
:
types
.
Leaf
{},
Poststate
:
types
.
Leaf
{
Input
:
poststateLeaf
,
Index
:
big
.
NewInt
(
int64
(
0
))
,
Index
:
0
,
StateCommitment
:
common
.
Hash
{
0xaa
},
},
PoststateProof
:
merkleTree
(
incorrectFirstCommitment
)
.
ProofAtIndex
(
0
),
...
...
op-challenger/game/keccak/types/types.go
View file @
aeed0da3
...
...
@@ -18,30 +18,17 @@ type Leaf struct {
// Input is the data absorbed for the block, exactly 136 bytes
Input
[
BlockSize
]
byte
// Index of the block in the absorption process
Index
*
big
.
Int
Index
uint64
// StateCommitment is the hash of the internal state after absorbing the input.
StateCommitment
common
.
Hash
}
func
(
l
Leaf
)
IndexUint64
()
uint64
{
if
l
.
Index
==
nil
{
return
0
}
return
l
.
Index
.
Uint64
()
}
// Hash returns the hash of the leaf data. That is the
// bytewise concatenation of the input, index, and state commitment.
func
(
l
Leaf
)
Hash
()
common
.
Hash
{
concatted
:=
make
([]
byte
,
0
,
136
+
32
+
32
)
concatted
=
append
(
concatted
,
l
.
Input
[
:
]
...
)
var
indexBytes
[]
byte
if
l
.
Index
!=
nil
{
indexBytes
=
l
.
Index
.
Bytes
()
}
else
{
indexBytes
=
big
.
NewInt
(
0
)
.
Bytes
()
}
concatted
=
append
(
concatted
,
indexBytes
...
)
concatted
=
append
(
concatted
,
new
(
big
.
Int
)
.
SetUint64
(
l
.
Index
)
.
Bytes
()
...
)
concatted
=
append
(
concatted
,
l
.
StateCommitment
.
Bytes
()
...
)
return
crypto
.
Keccak256Hash
(
concatted
)
}
...
...
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