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
afb4ea6a
Unverified
Commit
afb4ea6a
authored
Feb 09, 2024
by
Adrian Sutton
Committed by
GitHub
Feb 08, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-preimage: Update verification for sha256 and blobs (#9432)
parent
9f5269e3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
25 deletions
+53
-25
verifier.go
op-preimage/verifier.go
+10
-0
verifier_test.go
op-preimage/verifier_test.go
+43
-25
No files found.
op-preimage/verifier.go
View file @
afb4ea6a
package
preimage
import
(
"crypto/sha256"
"errors"
"fmt"
"slices"
...
...
@@ -28,6 +29,15 @@ func WithVerification(source PreimageGetter) PreimageGetter {
return
nil
,
fmt
.
Errorf
(
"%w for key %v, hash: %v data: %x"
,
ErrIncorrectData
,
key
,
hash
,
data
)
}
return
data
,
nil
case
Sha256KeyType
:
hash
:=
sha256
.
Sum256
(
data
)
if
!
slices
.
Equal
(
hash
[
1
:
],
key
[
1
:
])
{
return
nil
,
fmt
.
Errorf
(
"%w for key %v, hash: %v data: %x"
,
ErrIncorrectData
,
key
,
hash
,
data
)
}
return
data
,
nil
case
BlobKeyType
:
// Can't verify an individual field element without having a kzg proof
return
data
,
nil
default
:
return
nil
,
fmt
.
Errorf
(
"%w: %v"
,
ErrUnsupportedKeyType
,
key
[
0
])
}
...
...
op-preimage/verifier_test.go
View file @
afb4ea6a
package
preimage
import
(
"crypto/sha256"
"errors"
"fmt"
"reflect"
"testing"
"github.com/stretchr/testify/require"
...
...
@@ -10,16 +13,20 @@ import (
func
TestWithVerification
(
t
*
testing
.
T
)
{
validData
:=
[]
byte
{
1
,
2
,
3
,
4
,
5
,
6
}
keccak256Key
:=
Keccak256Key
(
Keccak256
(
validData
))
sha256Key
:=
Sha256Key
(
sha256
.
Sum256
(
validData
))
anError
:=
errors
.
New
(
"boom"
)
tests
:=
[]
struct
{
validKeys
:=
[]
Key
{
keccak256Key
,
sha256Key
}
type
testData
struct
{
name
string
key
Key
data
[]
byte
err
error
expectedErr
error
expectedData
[]
byte
}{
}
tests
:=
[]
testData
{
{
name
:
"LocalKey NoVerification"
,
key
:
LocalIndexKey
(
1
),
...
...
@@ -27,36 +34,47 @@ func TestWithVerification(t *testing.T) {
expectedData
:
[]
byte
{
4
,
3
,
5
,
7
,
3
},
},
{
name
:
"Keccak256 Valid"
,
key
:
keccak256Key
,
name
:
"BlobKey NoVerification"
,
key
:
BlobKey
([
32
]
byte
{
1
,
2
,
3
,
4
}),
data
:
[]
byte
{
4
,
3
,
5
,
7
,
3
},
expectedData
:
[]
byte
{
4
,
3
,
5
,
7
,
3
},
},
{
name
:
"UnknownKey"
,
key
:
invalidKey
([
32
]
byte
{
0xaa
}),
data
:
[]
byte
{},
expectedErr
:
ErrUnsupportedKeyType
,
},
}
for
_
,
key
:=
range
validKeys
{
name
:=
reflect
.
TypeOf
(
key
)
.
Name
()
tests
=
append
(
tests
,
testData
{
name
:
fmt
.
Sprintf
(
"%v-Valid"
,
name
),
key
:
key
,
data
:
validData
,
expectedData
:
validData
,
},
{
name
:
"Keccak256 Error"
,
key
:
keccak256K
ey
,
testData
{
name
:
fmt
.
Sprintf
(
"%v-Error"
,
name
)
,
key
:
k
ey
,
data
:
validData
,
err
:
anError
,
expectedErr
:
anError
,
},
{
name
:
"Keccak256 InvalidData"
,
key
:
keccak256K
ey
,
testData
{
name
:
fmt
.
Sprintf
(
"%v-InvalidData"
,
name
)
,
key
:
k
ey
,
data
:
[]
byte
{
6
,
7
,
8
},
expectedErr
:
ErrIncorrectData
,
},
{
name
:
"EmptyData"
,
key
:
keccak256K
ey
,
testData
{
name
:
fmt
.
Sprintf
(
"%v-EmptyData"
,
name
)
,
key
:
k
ey
,
data
:
[]
byte
{},
expectedErr
:
ErrIncorrectData
,
},
{
name
:
"UnknownKey"
,
key
:
invalidKey
([
32
]
byte
{
0xaa
}),
data
:
[]
byte
{},
expectedErr
:
ErrUnsupportedKeyType
,
},
})
}
for
_
,
test
:=
range
tests
{
...
...
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