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
c36b3d94
Commit
c36b3d94
authored
Aug 03, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix up the cannon updater with tests
parent
2b0c5664
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
110 additions
and
42 deletions
+110
-42
provider.go
op-challenger/fault/cannon/provider.go
+7
-6
updater.go
op-challenger/fault/cannon/updater.go
+10
-10
updater_test.go
op-challenger/fault/cannon/updater_test.go
+68
-15
alphabet.go
op-challenger/fault/test/alphabet.go
+1
-1
types.go
op-challenger/fault/types/types.go
+20
-8
types_test.go
op-challenger/fault/types/types_test.go
+4
-2
No files found.
op-challenger/fault/cannon/provider.go
View file @
c36b3d94
...
...
@@ -21,11 +21,12 @@ const (
)
type
proofData
struct
{
ClaimValue
hexutil
.
Bytes
`json:"post"`
StateData
hexutil
.
Bytes
`json:"state-data"`
ProofData
hexutil
.
Bytes
`json:"proof-data"`
OracleKey
hexutil
.
Bytes
`json:"oracle-key,omitempty"`
OracleValue
hexutil
.
Bytes
`json:"oracle-value,omitempty"`
ClaimValue
hexutil
.
Bytes
`json:"post"`
StateData
hexutil
.
Bytes
`json:"state-data"`
ProofData
hexutil
.
Bytes
`json:"proof-data"`
OracleKey
hexutil
.
Bytes
`json:"oracle-key,omitempty"`
OracleValue
hexutil
.
Bytes
`json:"oracle-value,omitempty"`
OracleOffset
uint32
`json:"oracle-offset,omitempty"`
}
type
ProofGenerator
interface
{
...
...
@@ -52,7 +53,7 @@ func (p *CannonTraceProvider) GetOracleData(ctx context.Context, i uint64) (*typ
if
err
!=
nil
{
return
nil
,
err
}
data
:=
types
.
NewPreimageOracleData
(
proof
.
OracleKey
,
proof
.
OracleValue
)
data
:=
types
.
NewPreimageOracleData
(
proof
.
OracleKey
,
proof
.
OracleValue
,
proof
.
OracleOffset
)
return
&
data
,
nil
}
...
...
op-challenger/fault/cannon/updater.go
View file @
c36b3d94
...
...
@@ -66,7 +66,7 @@ func (u *cannonUpdater) UpdateOracle(ctx context.Context, data types.PreimageOra
// sendLocalOracleData sends the local oracle data to the [txmgr].
func
(
u
*
cannonUpdater
)
sendLocalOracleData
(
ctx
context
.
Context
,
data
types
.
PreimageOracleData
)
error
{
txData
,
err
:=
u
.
b
uildLocalOracleData
(
data
)
txData
,
err
:=
u
.
B
uildLocalOracleData
(
data
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"local oracle tx data build: %w"
,
err
)
}
...
...
@@ -75,32 +75,32 @@ func (u *cannonUpdater) sendLocalOracleData(ctx context.Context, data types.Prei
// sendGlobalOracleData sends the global oracle data to the [txmgr].
func
(
u
*
cannonUpdater
)
sendGlobalOracleData
(
ctx
context
.
Context
,
data
types
.
PreimageOracleData
)
error
{
txData
,
err
:=
u
.
b
uildGlobalOracleData
(
data
)
txData
,
err
:=
u
.
B
uildGlobalOracleData
(
data
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"global oracle tx data build: %w"
,
err
)
}
return
u
.
sendTxAndWait
(
ctx
,
u
.
fdgAddr
,
txData
)
}
//
b
uildLocalOracleData takes the local preimage key and data
//
B
uildLocalOracleData takes the local preimage key and data
// and creates tx data to load the key, data pair into the
// PreimageOracle contract from the FaultDisputeGame contract call.
func
(
u
*
cannonUpdater
)
b
uildLocalOracleData
(
data
types
.
PreimageOracleData
)
([]
byte
,
error
)
{
func
(
u
*
cannonUpdater
)
B
uildLocalOracleData
(
data
types
.
PreimageOracleData
)
([]
byte
,
error
)
{
return
u
.
fdgAbi
.
Pack
(
"addLocalData"
,
data
.
OracleKey
,
big
.
NewInt
(
0
),
data
.
GetIdent
()
,
big
.
NewInt
(
int64
(
data
.
OracleOffset
)
),
)
}
//
b
uildGlobalOracleData takes the global preimage key and data
//
B
uildGlobalOracleData takes the global preimage key and data
// and creates tx data to load the key, data pair into the
// PreimageOracle contract.
func
(
u
*
cannonUpdater
)
b
uildGlobalOracleData
(
data
types
.
PreimageOracleData
)
([]
byte
,
error
)
{
func
(
u
*
cannonUpdater
)
B
uildGlobalOracleData
(
data
types
.
PreimageOracleData
)
([]
byte
,
error
)
{
return
u
.
preimageOracleAbi
.
Pack
(
"loadKeccak256PreimagePart"
,
big
.
NewInt
(
0
),
data
.
OracleData
,
big
.
NewInt
(
int64
(
data
.
OracleOffset
)
),
data
.
GetPreimageWithoutSize
()
,
)
}
...
...
op-challenger/fault/cannon/updater_test.go
View file @
c36b3d94
...
...
@@ -6,6 +6,7 @@ import (
"math/big"
"testing"
"github.com/ethereum-optimism/optimism/op-challenger/fault/types"
"github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
...
...
@@ -13,6 +14,7 @@ import (
ethtypes
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/require"
...
...
@@ -25,14 +27,15 @@ var (
)
type
mockTxManager
struct
{
from
common
.
Address
sends
int
calls
int
sendFails
bool
from
common
.
Address
sends
int
failedSends
int
sendFails
bool
}
func
(
m
*
mockTxManager
)
Send
(
ctx
context
.
Context
,
candidate
txmgr
.
TxCandidate
)
(
*
ethtypes
.
Receipt
,
error
)
{
if
m
.
sendFails
{
m
.
failedSends
++
return
nil
,
mockSendError
}
m
.
sends
++
...
...
@@ -44,11 +47,7 @@ func (m *mockTxManager) Send(ctx context.Context, candidate txmgr.TxCandidate) (
}
func
(
m
*
mockTxManager
)
Call
(
_
context
.
Context
,
_
ethereum
.
CallMsg
,
_
*
big
.
Int
)
([]
byte
,
error
)
{
if
m
.
sendFails
{
return
nil
,
mockSendError
}
m
.
calls
++
return
[]
byte
{},
nil
panic
(
"not implemented"
)
}
func
(
m
*
mockTxManager
)
BlockNumber
(
ctx
context
.
Context
)
(
uint64
,
error
)
{
...
...
@@ -74,14 +73,68 @@ func newTestCannonUpdater(t *testing.T, sendFails bool) (*cannonUpdater, *mockTx
// UpdateOracle function.
func
TestCannonUpdater_UpdateOracle
(
t
*
testing
.
T
)
{
t
.
Run
(
"succeeds"
,
func
(
t
*
testing
.
T
)
{
_
,
_
=
newTestCannonUpdater
(
t
,
false
)
// require.Nil(t, updater.UpdateOracle(context.Background(), types.PreimageOracleData{}))
// require.Equal(t, 1, mockTxMgr.calls)
updater
,
mockTxMgr
:=
newTestCannonUpdater
(
t
,
false
)
require
.
Nil
(
t
,
updater
.
UpdateOracle
(
context
.
Background
(),
types
.
PreimageOracleData
{
OracleData
:
common
.
Hex2Bytes
(
"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
),
}))
require
.
Equal
(
t
,
1
,
mockTxMgr
.
sends
)
})
t
.
Run
(
"send fails"
,
func
(
t
*
testing
.
T
)
{
_
,
_
=
newTestCannonUpdater
(
t
,
true
)
// require.Error(t, updater.UpdateOracle(context.Background(), types.PreimageOracleData{}))
// require.Equal(t, 1, mockTxMgr.calls)
updater
,
mockTxMgr
:=
newTestCannonUpdater
(
t
,
true
)
require
.
Error
(
t
,
updater
.
UpdateOracle
(
context
.
Background
(),
types
.
PreimageOracleData
{
OracleData
:
common
.
Hex2Bytes
(
"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
),
}))
require
.
Equal
(
t
,
1
,
mockTxMgr
.
failedSends
)
})
}
// TestCannonUpdater_BuildLocalOracleData tests the [cannonUpdater]
// builds a valid tx candidate for a local oracle update.
func
TestCannonUpdater_BuildLocalOracleData
(
t
*
testing
.
T
)
{
updater
,
_
:=
newTestCannonUpdater
(
t
,
false
)
oracleData
:=
types
.
PreimageOracleData
{
OracleKey
:
common
.
Hex2Bytes
(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
),
OracleData
:
common
.
Hex2Bytes
(
"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
),
OracleOffset
:
7
,
}
txData
,
err
:=
updater
.
BuildLocalOracleData
(
oracleData
)
require
.
NoError
(
t
,
err
)
var
addLocalDataBytes4
=
crypto
.
Keccak256
([]
byte
(
"addLocalData(uint256,uint256)"
))[
:
4
]
// Pack the tx data manually.
var
expected
[]
byte
expected
=
append
(
expected
,
addLocalDataBytes4
...
)
expected
=
append
(
expected
,
common
.
Hex2Bytes
(
"00aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
)
...
)
expected
=
append
(
expected
,
common
.
Hex2Bytes
(
"0000000000000000000000000000000000000000000000000000000000000007"
)
...
)
require
.
Equal
(
t
,
expected
,
txData
)
}
// TestCannonUpdater_BuildGlobalOracleData tests the [cannonUpdater]
// builds a valid tx candidate for a global oracle update.
func
TestCannonUpdater_BuildGlobalOracleData
(
t
*
testing
.
T
)
{
updater
,
_
:=
newTestCannonUpdater
(
t
,
false
)
oracleData
:=
types
.
PreimageOracleData
{
OracleKey
:
common
.
Hex2Bytes
(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
),
OracleData
:
common
.
Hex2Bytes
(
"cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
),
OracleOffset
:
7
,
}
txData
,
err
:=
updater
.
BuildGlobalOracleData
(
oracleData
)
require
.
NoError
(
t
,
err
)
var
loadKeccak256PreimagePartBytes4
=
crypto
.
Keccak256
([]
byte
(
"loadKeccak256PreimagePart(uint256,bytes)"
))[
:
4
]
// Pack the tx data manually.
var
expected
[]
byte
expected
=
append
(
expected
,
loadKeccak256PreimagePartBytes4
...
)
expected
=
append
(
expected
,
common
.
Hex2Bytes
(
"0000000000000000000000000000000000000000000000000000000000000007"
)
...
)
expected
=
append
(
expected
,
common
.
Hex2Bytes
(
"0000000000000000000000000000000000000000000000000000000000000040"
)
...
)
expected
=
append
(
expected
,
common
.
Hex2Bytes
(
"0000000000000000000000000000000000000000000000000000000000000018"
)
...
)
expected
=
append
(
expected
,
common
.
Hex2Bytes
(
"cccccccccccccccccccccccccccccccccccccccccccccccc0000000000000000"
)
...
)
require
.
Equal
(
t
,
expected
,
txData
)
}
op-challenger/fault/test/alphabet.go
View file @
c36b3d94
...
...
@@ -37,6 +37,6 @@ func (a *alphabetWithProofProvider) GetOracleData(ctx context.Context, i uint64)
if
a
.
OracleError
!=
nil
{
return
&
types
.
PreimageOracleData
{},
a
.
OracleError
}
data
:=
types
.
NewPreimageOracleData
([]
byte
{
byte
(
i
)},
[]
byte
{
byte
(
i
)})
data
:=
types
.
NewPreimageOracleData
([]
byte
{
byte
(
i
)},
[]
byte
{
byte
(
i
)}
,
uint32
(
i
)
)
return
&
data
,
nil
}
op-challenger/fault/types/types.go
View file @
c36b3d94
...
...
@@ -23,22 +23,34 @@ const (
// PreimageOracleData encapsulates the preimage oracle data
// to load into the onchain oracle.
type
PreimageOracleData
struct
{
IsLocal
bool
OracleKey
[]
byte
OracleData
[]
byte
IsLocal
bool
OracleKey
[]
byte
OracleData
[]
byte
OracleOffset
uint32
}
// GetType returns the type for the preimage oracle data.
func
(
p
*
PreimageOracleData
)
GetType
()
*
big
.
Int
{
return
big
.
NewInt
(
int64
(
p
.
OracleKey
[
0
]))
}
// GetIdent returns the ident for the preimage oracle data.
func
(
p
*
PreimageOracleData
)
GetIdent
()
*
big
.
Int
{
return
big
.
NewInt
(
int64
(
p
.
OracleData
[
0
]))
return
big
.
NewInt
(
0
)
.
SetBytes
(
p
.
OracleKey
[
1
:
])
}
// GetPreimageWithoutSize returns the preimage for the preimage oracle data.
func
(
p
*
PreimageOracleData
)
GetPreimageWithoutSize
()
[]
byte
{
return
p
.
OracleData
[
8
:
]
}
// NewPreimageOracleData creates a new [PreimageOracleData] instance.
func
NewPreimageOracleData
(
key
[]
byte
,
data
[]
byte
)
PreimageOracleData
{
func
NewPreimageOracleData
(
key
[]
byte
,
data
[]
byte
,
offset
uint32
)
PreimageOracleData
{
return
PreimageOracleData
{
IsLocal
:
len
(
key
)
>
0
&&
key
[
0
]
==
byte
(
1
),
OracleKey
:
key
,
OracleData
:
data
,
IsLocal
:
len
(
key
)
>
0
&&
key
[
0
]
==
byte
(
1
),
OracleKey
:
key
,
OracleData
:
data
,
OracleOffset
:
offset
,
}
}
...
...
op-challenger/fault/types/types_test.go
View file @
c36b3d94
...
...
@@ -8,16 +8,18 @@ import (
func
TestNewPreimageOracleData
(
t
*
testing
.
T
)
{
t
.
Run
(
"LocalData"
,
func
(
t
*
testing
.
T
)
{
data
:=
NewPreimageOracleData
([]
byte
{
1
,
2
,
3
},
[]
byte
{
4
,
5
,
6
})
data
:=
NewPreimageOracleData
([]
byte
{
1
,
2
,
3
},
[]
byte
{
4
,
5
,
6
}
,
7
)
require
.
True
(
t
,
data
.
IsLocal
)
require
.
Equal
(
t
,
[]
byte
{
1
,
2
,
3
},
data
.
OracleKey
)
require
.
Equal
(
t
,
[]
byte
{
4
,
5
,
6
},
data
.
OracleData
)
require
.
Equal
(
t
,
uint32
(
7
),
data
.
OracleOffset
)
})
t
.
Run
(
"GlobalData"
,
func
(
t
*
testing
.
T
)
{
data
:=
NewPreimageOracleData
([]
byte
{
0
,
2
,
3
},
[]
byte
{
4
,
5
,
6
})
data
:=
NewPreimageOracleData
([]
byte
{
0
,
2
,
3
},
[]
byte
{
4
,
5
,
6
}
,
7
)
require
.
False
(
t
,
data
.
IsLocal
)
require
.
Equal
(
t
,
[]
byte
{
0
,
2
,
3
},
data
.
OracleKey
)
require
.
Equal
(
t
,
[]
byte
{
4
,
5
,
6
},
data
.
OracleData
)
require
.
Equal
(
t
,
uint32
(
7
),
data
.
OracleOffset
)
})
}
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