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
51bb4d1a
Unverified
Commit
51bb4d1a
authored
Feb 06, 2024
by
Adrian Sutton
Committed by
GitHub
Feb 06, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-challenger: Support posting sha256 preimages (#9373)
parent
0d9c9b20
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
15 deletions
+55
-15
oracle.go
op-challenger/game/fault/contracts/oracle.go
+18
-2
oracle_test.go
op-challenger/game/fault/contracts/oracle_test.go
+32
-10
vm_test.go
op-challenger/game/fault/contracts/vm_test.go
+2
-1
types.go
op-challenger/game/fault/types/types.go
+2
-1
iface.go
op-preimage/iface.go
+1
-1
No files found.
op-challenger/game/fault/contracts/oracle.go
View file @
51bb4d1a
...
@@ -12,6 +12,7 @@ import (
...
@@ -12,6 +12,7 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/merkle"
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/merkle"
keccakTypes
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
keccakTypes
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
preimage
"github.com/ethereum-optimism/optimism/op-preimage"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
...
@@ -22,6 +23,7 @@ const (
...
@@ -22,6 +23,7 @@ const (
methodAddLeavesLPP
=
"addLeavesLPP"
methodAddLeavesLPP
=
"addLeavesLPP"
methodSqueezeLPP
=
"squeezeLPP"
methodSqueezeLPP
=
"squeezeLPP"
methodLoadKeccak256PreimagePart
=
"loadKeccak256PreimagePart"
methodLoadKeccak256PreimagePart
=
"loadKeccak256PreimagePart"
methodLoadSha256PreimagePart
=
"loadSha256PreimagePart"
methodProposalCount
=
"proposalCount"
methodProposalCount
=
"proposalCount"
methodProposals
=
"proposals"
methodProposals
=
"proposals"
methodProposalMetadata
=
"proposalMetadata"
methodProposalMetadata
=
"proposalMetadata"
...
@@ -37,6 +39,8 @@ const (
...
@@ -37,6 +39,8 @@ const (
var
(
var
(
ErrInvalidAddLeavesCall
=
errors
.
New
(
"tx is not a valid addLeaves call"
)
ErrInvalidAddLeavesCall
=
errors
.
New
(
"tx is not a valid addLeaves call"
)
ErrInvalidPreimageKey
=
errors
.
New
(
"invalid preimage key"
)
ErrUnsupportedKeyType
=
errors
.
New
(
"unsupported preimage key type"
)
)
)
// PreimageOracleContract is a binding that works with contracts implementing the IPreimageOracle interface
// PreimageOracleContract is a binding that works with contracts implementing the IPreimageOracle interface
...
@@ -73,8 +77,20 @@ func (c *PreimageOracleContract) Addr() common.Address {
...
@@ -73,8 +77,20 @@ func (c *PreimageOracleContract) Addr() common.Address {
}
}
func
(
c
*
PreimageOracleContract
)
AddGlobalDataTx
(
data
*
types
.
PreimageOracleData
)
(
txmgr
.
TxCandidate
,
error
)
{
func
(
c
*
PreimageOracleContract
)
AddGlobalDataTx
(
data
*
types
.
PreimageOracleData
)
(
txmgr
.
TxCandidate
,
error
)
{
call
:=
c
.
contract
.
Call
(
methodLoadKeccak256PreimagePart
,
new
(
big
.
Int
)
.
SetUint64
(
uint64
(
data
.
OracleOffset
)),
data
.
GetPreimageWithoutSize
())
if
len
(
data
.
OracleKey
)
==
0
{
return
call
.
ToTxCandidate
()
return
txmgr
.
TxCandidate
{},
ErrInvalidPreimageKey
}
keyType
:=
preimage
.
KeyType
(
data
.
OracleKey
[
0
])
switch
keyType
{
case
preimage
.
Keccak256KeyType
:
call
:=
c
.
contract
.
Call
(
methodLoadKeccak256PreimagePart
,
new
(
big
.
Int
)
.
SetUint64
(
uint64
(
data
.
OracleOffset
)),
data
.
GetPreimageWithoutSize
())
return
call
.
ToTxCandidate
()
case
preimage
.
Sha256KeyType
:
call
:=
c
.
contract
.
Call
(
methodLoadSha256PreimagePart
,
new
(
big
.
Int
)
.
SetUint64
(
uint64
(
data
.
OracleOffset
)),
data
.
GetPreimageWithoutSize
())
return
call
.
ToTxCandidate
()
default
:
return
txmgr
.
TxCandidate
{},
fmt
.
Errorf
(
"%w: %v"
,
ErrUnsupportedKeyType
,
keyType
)
}
}
}
func
(
c
*
PreimageOracleContract
)
InitLargePreimage
(
uuid
*
big
.
Int
,
partOffset
uint32
,
claimedSize
uint32
)
(
txmgr
.
TxCandidate
,
error
)
{
func
(
c
*
PreimageOracleContract
)
InitLargePreimage
(
uuid
*
big
.
Int
,
partOffset
uint32
,
claimedSize
uint32
)
(
txmgr
.
TxCandidate
,
error
)
{
...
...
op-challenger/game/fault/contracts/oracle_test.go
View file @
51bb4d1a
...
@@ -11,24 +11,46 @@ import (
...
@@ -11,24 +11,46 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/merkle"
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/merkle"
keccakTypes
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
keccakTypes
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
preimage
"github.com/ethereum-optimism/optimism/op-preimage"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
batchingTest
"github.com/ethereum-optimism/optimism/op-service/sources/batching/test"
batchingTest
"github.com/ethereum-optimism/optimism/op-service/sources/batching/test"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
)
)
func
TestPreimageOracleContract_LoadKeccak256
(
t
*
testing
.
T
)
{
func
TestPreimageOracleContract_AddGlobalDataTx
(
t
*
testing
.
T
)
{
stubRpc
,
oracle
:=
setupPreimageOracleTest
(
t
)
t
.
Run
(
"UnknownType"
,
func
(
t
*
testing
.
T
)
{
_
,
oracle
:=
setupPreimageOracleTest
(
t
)
data
:=
types
.
NewPreimageOracleData
(
common
.
Hash
{
0xcc
}
.
Bytes
(),
make
([]
byte
,
20
),
uint32
(
545
))
_
,
err
:=
oracle
.
AddGlobalDataTx
(
data
)
require
.
ErrorIs
(
t
,
err
,
ErrUnsupportedKeyType
)
})
data
:=
types
.
NewPreimageOracleData
(
common
.
Hash
{
0xcc
}
.
Bytes
(),
make
([]
byte
,
20
),
545
)
t
.
Run
(
"Keccak256"
,
func
(
t
*
testing
.
T
)
{
stubRpc
.
SetResponse
(
oracleAddr
,
methodLoadKeccak256PreimagePart
,
batching
.
BlockLatest
,
[]
interface
{}{
stubRpc
,
oracle
:=
setupPreimageOracleTest
(
t
)
new
(
big
.
Int
)
.
SetUint64
(
uint64
(
data
.
OracleOffset
)),
data
:=
types
.
NewPreimageOracleData
(
common
.
Hash
{
byte
(
preimage
.
Keccak256KeyType
),
0xcc
}
.
Bytes
(),
make
([]
byte
,
20
),
uint32
(
545
))
data
.
GetPreimageWithoutSize
(),
stubRpc
.
SetResponse
(
oracleAddr
,
methodLoadKeccak256PreimagePart
,
batching
.
BlockLatest
,
[]
interface
{}{
},
nil
)
new
(
big
.
Int
)
.
SetUint64
(
uint64
(
data
.
OracleOffset
)),
data
.
GetPreimageWithoutSize
(),
},
nil
)
tx
,
err
:=
oracle
.
AddGlobalDataTx
(
data
)
tx
,
err
:=
oracle
.
AddGlobalDataTx
(
data
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
stubRpc
.
VerifyTxCandidate
(
tx
)
stubRpc
.
VerifyTxCandidate
(
tx
)
})
t
.
Run
(
"Sha256"
,
func
(
t
*
testing
.
T
)
{
stubRpc
,
oracle
:=
setupPreimageOracleTest
(
t
)
data
:=
types
.
NewPreimageOracleData
(
common
.
Hash
{
byte
(
preimage
.
Sha256KeyType
),
0xcc
}
.
Bytes
(),
make
([]
byte
,
20
),
uint32
(
545
))
stubRpc
.
SetResponse
(
oracleAddr
,
methodLoadSha256PreimagePart
,
batching
.
BlockLatest
,
[]
interface
{}{
new
(
big
.
Int
)
.
SetUint64
(
uint64
(
data
.
OracleOffset
)),
data
.
GetPreimageWithoutSize
(),
},
nil
)
tx
,
err
:=
oracle
.
AddGlobalDataTx
(
data
)
require
.
NoError
(
t
,
err
)
stubRpc
.
VerifyTxCandidate
(
tx
)
})
}
}
func
TestPreimageOracleContract_ChallengePeriod
(
t
*
testing
.
T
)
{
func
TestPreimageOracleContract_ChallengePeriod
(
t
*
testing
.
T
)
{
...
...
op-challenger/game/fault/contracts/vm_test.go
View file @
51bb4d1a
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/types"
preimage
"github.com/ethereum-optimism/optimism/op-preimage"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
batchingTest
"github.com/ethereum-optimism/optimism/op-service/sources/batching/test"
batchingTest
"github.com/ethereum-optimism/optimism/op-service/sources/batching/test"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
...
@@ -24,7 +25,7 @@ func TestVMContract_Oracle(t *testing.T) {
...
@@ -24,7 +25,7 @@ func TestVMContract_Oracle(t *testing.T) {
oracleContract
,
err
:=
vmContract
.
Oracle
(
context
.
Background
())
oracleContract
,
err
:=
vmContract
.
Oracle
(
context
.
Background
())
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
tx
,
err
:=
oracleContract
.
AddGlobalDataTx
(
types
.
NewPreimageOracleData
(
common
.
Hash
{}
.
Bytes
(),
make
([]
byte
,
20
),
0
))
tx
,
err
:=
oracleContract
.
AddGlobalDataTx
(
types
.
NewPreimageOracleData
(
common
.
Hash
{
byte
(
preimage
.
Keccak256KeyType
)
}
.
Bytes
(),
make
([]
byte
,
20
),
0
))
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
// This test doesn't care about all the tx details, we just want to confirm the contract binding is using the
// This test doesn't care about all the tx details, we just want to confirm the contract binding is using the
// correct address
// correct address
...
...
op-challenger/game/fault/types/types.go
View file @
51bb4d1a
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"math/big"
"math/big"
"time"
"time"
preimage
"github.com/ethereum-optimism/optimism/op-preimage"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
)
)
...
@@ -48,7 +49,7 @@ func (p *PreimageOracleData) GetPreimageWithSize() []byte {
...
@@ -48,7 +49,7 @@ func (p *PreimageOracleData) GetPreimageWithSize() []byte {
// NewPreimageOracleData creates a new [PreimageOracleData] instance.
// NewPreimageOracleData creates a new [PreimageOracleData] instance.
func
NewPreimageOracleData
(
key
[]
byte
,
data
[]
byte
,
offset
uint32
)
*
PreimageOracleData
{
func
NewPreimageOracleData
(
key
[]
byte
,
data
[]
byte
,
offset
uint32
)
*
PreimageOracleData
{
return
&
PreimageOracleData
{
return
&
PreimageOracleData
{
IsLocal
:
len
(
key
)
>
0
&&
key
[
0
]
==
byte
(
1
),
IsLocal
:
len
(
key
)
>
0
&&
key
[
0
]
==
byte
(
preimage
.
LocalKeyType
),
OracleKey
:
key
,
OracleKey
:
key
,
oracleData
:
data
,
oracleData
:
data
,
OracleOffset
:
offset
,
OracleOffset
:
offset
,
...
...
op-preimage/iface.go
View file @
51bb4d1a
...
@@ -34,7 +34,7 @@ const (
...
@@ -34,7 +34,7 @@ const (
LocalKeyType
KeyType
=
1
LocalKeyType
KeyType
=
1
// Keccak256KeyType is for keccak256 pre-images, for any global shared pre-images.
// Keccak256KeyType is for keccak256 pre-images, for any global shared pre-images.
Keccak256KeyType
KeyType
=
2
Keccak256KeyType
KeyType
=
2
// GlobalGenericKeyType is a reseved key type for generic global data.
// GlobalGenericKeyType is a rese
r
ved key type for generic global data.
GlobalGenericKeyType
KeyType
=
3
GlobalGenericKeyType
KeyType
=
3
// Sha256KeyType is for sha256 pre-images, for any global shared pre-images.
// Sha256KeyType is for sha256 pre-images, for any global shared pre-images.
Sha256KeyType
KeyType
=
4
Sha256KeyType
KeyType
=
4
...
...
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