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
e07b48c9
Commit
e07b48c9
authored
Oct 23, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lint
parent
01ec03a8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
20 deletions
+22
-20
trie.go
packages/contracts-bedrock/scripts/go-ffi/trie.go
+22
-20
No files found.
packages/contracts-bedrock/scripts/go-ffi/trie.go
View file @
e07b48c9
...
@@ -50,12 +50,10 @@ func FuzzTrie() {
...
@@ -50,12 +50,10 @@ func FuzzTrie() {
switch
variant
{
switch
variant
{
case
valid
:
case
valid
:
testCase
=
genTrieTestCase
(
false
)
testCase
=
genTrieTestCase
(
false
)
break
case
extraProofElems
:
case
extraProofElems
:
testCase
=
genTrieTestCase
(
false
)
testCase
=
genTrieTestCase
(
false
)
// Duplicate the last element of the proof
// Duplicate the last element of the proof
testCase
.
Proof
=
append
(
testCase
.
Proof
,
[][]
byte
{
testCase
.
Proof
[
len
(
testCase
.
Proof
)
-
1
]}
...
)
testCase
.
Proof
=
append
(
testCase
.
Proof
,
[][]
byte
{
testCase
.
Proof
[
len
(
testCase
.
Proof
)
-
1
]}
...
)
break
case
corruptedProof
:
case
corruptedProof
:
testCase
=
genTrieTestCase
(
false
)
testCase
=
genTrieTestCase
(
false
)
...
@@ -63,17 +61,17 @@ func FuzzTrie() {
...
@@ -63,17 +61,17 @@ func FuzzTrie() {
idx
:=
randRange
(
0
,
int64
(
len
(
testCase
.
Proof
)))
idx
:=
randRange
(
0
,
int64
(
len
(
testCase
.
Proof
)))
encoded
,
_
:=
rlp
.
EncodeToBytes
(
testCase
.
Proof
[
idx
])
encoded
,
_
:=
rlp
.
EncodeToBytes
(
testCase
.
Proof
[
idx
])
testCase
.
Proof
[
idx
]
=
encoded
testCase
.
Proof
[
idx
]
=
encoded
break
case
invalidDataRemainder
:
case
invalidDataRemainder
:
testCase
=
genTrieTestCase
(
false
)
testCase
=
genTrieTestCase
(
false
)
// Alter true length of random proof element by appending random bytes
// Alter true length of random proof element by appending random bytes
// Do not update the encoded length
// Do not update the encoded length
idx
:=
randRange
(
0
,
int64
(
len
(
testCase
.
Proof
)))
idx
:=
randRange
(
0
,
int64
(
len
(
testCase
.
Proof
)))
bytes
:=
make
([]
byte
,
randRange
(
1
,
512
))
b
:=
make
([]
byte
,
randRange
(
1
,
512
))
rand
.
Read
(
bytes
)
if
_
,
err
:=
rand
.
Read
(
b
);
err
!=
nil
{
testCase
.
Proof
[
idx
]
=
append
(
testCase
.
Proof
[
idx
],
bytes
...
)
log
.
Fatal
(
"Error generating random bytes"
)
break
}
testCase
.
Proof
[
idx
]
=
append
(
testCase
.
Proof
[
idx
],
b
...
)
case
invalidLargeInternalHash
:
case
invalidLargeInternalHash
:
testCase
=
genTrieTestCase
(
false
)
testCase
=
genTrieTestCase
(
false
)
...
@@ -82,7 +80,9 @@ func FuzzTrie() {
...
@@ -82,7 +80,9 @@ func FuzzTrie() {
// bytes to overwrite.
// bytes to overwrite.
idx
:=
randRange
(
1
,
int64
(
len
(
testCase
.
Proof
)))
idx
:=
randRange
(
1
,
int64
(
len
(
testCase
.
Proof
)))
b
:=
make
([]
byte
,
4
)
b
:=
make
([]
byte
,
4
)
rand
.
Read
(
b
)
if
_
,
err
:=
rand
.
Read
(
b
);
err
!=
nil
{
log
.
Fatal
(
"Error generating random bytes"
)
}
testCase
.
Proof
[
idx
]
=
append
(
testCase
.
Proof
[
idx
]
=
append
(
testCase
.
Proof
[
idx
][
:
20
],
testCase
.
Proof
[
idx
][
:
20
],
append
(
append
(
...
@@ -90,27 +90,26 @@ func FuzzTrie() {
...
@@ -90,27 +90,26 @@ func FuzzTrie() {
testCase
.
Proof
[
idx
][
24
:
]
...
,
testCase
.
Proof
[
idx
][
24
:
]
...
,
)
...
,
)
...
,
)
)
break
case
invalidInternalNodeHash
:
case
invalidInternalNodeHash
:
testCase
=
genTrieTestCase
(
false
)
testCase
=
genTrieTestCase
(
false
)
// Assign the last proof element to an encoded list containing a
// Assign the last proof element to an encoded list containing a
// random 29 byte value
// random 29 byte value
b
:=
make
([]
byte
,
29
)
b
:=
make
([]
byte
,
29
)
rand
.
Read
(
b
)
if
_
,
err
:=
rand
.
Read
(
b
);
err
!=
nil
{
log
.
Fatal
(
"Error generating random bytes"
)
}
e
,
_
:=
rlp
.
EncodeToBytes
(
b
)
e
,
_
:=
rlp
.
EncodeToBytes
(
b
)
testCase
.
Proof
[
len
(
testCase
.
Proof
)
-
1
]
=
append
([]
byte
{
0xc0
+
30
},
e
...
)
testCase
.
Proof
[
len
(
testCase
.
Proof
)
-
1
]
=
append
([]
byte
{
0xc0
+
30
},
e
...
)
break
case
prefixedValidKey
:
case
prefixedValidKey
:
testCase
=
genTrieTestCase
(
false
)
testCase
=
genTrieTestCase
(
false
)
bytes
:=
make
([]
byte
,
randRange
(
1
,
16
))
b
:=
make
([]
byte
,
randRange
(
1
,
16
))
rand
.
Read
(
bytes
)
if
_
,
err
:=
rand
.
Read
(
b
);
err
!=
nil
{
testCase
.
Key
=
append
(
bytes
,
testCase
.
Key
...
)
log
.
Fatal
(
"Error generating random bytes"
)
break
}
testCase
.
Key
=
append
(
b
,
testCase
.
Key
...
)
case
emptyKey
:
case
emptyKey
:
testCase
=
genTrieTestCase
(
true
)
testCase
=
genTrieTestCase
(
true
)
break
case
partialProof
:
case
partialProof
:
testCase
=
genTrieTestCase
(
false
)
testCase
=
genTrieTestCase
(
false
)
...
@@ -122,7 +121,6 @@ func FuzzTrie() {
...
@@ -122,7 +121,6 @@ func FuzzTrie() {
}
}
testCase
.
Proof
=
newProof
testCase
.
Proof
=
newProof
break
default
:
default
:
log
.
Fatal
(
"Invalid variant passed to trie fuzzer!"
)
log
.
Fatal
(
"Invalid variant passed to trie fuzzer!"
)
}
}
...
@@ -154,8 +152,12 @@ func genTrieTestCase(selectEmptyKey bool) trieTestCase {
...
@@ -154,8 +152,12 @@ func genTrieTestCase(selectEmptyKey bool) trieTestCase {
// Add `randN` elements to the trie
// Add `randN` elements to the trie
for
i
:=
int64
(
0
);
i
<
randN
;
i
++
{
for
i
:=
int64
(
0
);
i
<
randN
;
i
++
{
// Randomize the contents of `randKey` and `randValue`
// Randomize the contents of `randKey` and `randValue`
rand
.
Read
(
randKey
)
if
_
,
err
:=
rand
.
Read
(
randKey
);
err
!=
nil
{
rand
.
Read
(
randValue
)
log
.
Fatal
(
"Error generating random bytes"
)
}
if
_
,
err
:=
rand
.
Read
(
randValue
);
err
!=
nil
{
log
.
Fatal
(
"Error generating random bytes"
)
}
// Clear the selected key if `selectEmptyKey` is true
// Clear the selected key if `selectEmptyKey` is true
if
i
==
randSelect
&&
selectEmptyKey
{
if
i
==
randSelect
&&
selectEmptyKey
{
...
...
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