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
94a9993c
Commit
94a9993c
authored
Apr 18, 2023
by
Joshua Gutow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: Simplify parsing in ProcessSystemConfigUpdateLogEvent
parent
815cdbc6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
79 deletions
+76
-79
l1_block_info.go
op-node/rollup/derive/l1_block_info.go
+4
-1
system_config.go
op-node/rollup/derive/system_config.go
+38
-78
util.go
op-service/solabi/util.go
+6
-0
utils_test.go
op-service/solabi/utils_test.go
+28
-0
No files found.
op-node/rollup/derive/l1_block_info.go
View file @
94a9993c
...
@@ -2,6 +2,7 @@ package derive
...
@@ -2,6 +2,7 @@ package derive
import
(
import
(
"bytes"
"bytes"
"errors"
"fmt"
"fmt"
"math/big"
"math/big"
...
@@ -126,7 +127,9 @@ func (info *L1BlockInfo) UnmarshalBinary(data []byte) error {
...
@@ -126,7 +127,9 @@ func (info *L1BlockInfo) UnmarshalBinary(data []byte) error {
if
info
.
L1FeeScalar
,
err
=
solabi
.
ReadEthBytes32
(
reader
);
err
!=
nil
{
if
info
.
L1FeeScalar
,
err
=
solabi
.
ReadEthBytes32
(
reader
);
err
!=
nil
{
return
err
return
err
}
}
// TODO: solabi.EmptyReader
if
!
solabi
.
EmptyReader
(
reader
)
{
return
errors
.
New
(
"too many bytes"
)
}
return
nil
return
nil
}
}
...
...
op-node/rollup/derive/system_config.go
View file @
94a9993c
...
@@ -2,7 +2,7 @@ package derive
...
@@ -2,7 +2,7 @@ package derive
import
(
import
(
"bytes"
"bytes"
"e
ncoding/binary
"
"e
rrors
"
"fmt"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
...
@@ -12,6 +12,7 @@ import (
...
@@ -12,6 +12,7 @@ import (
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-service/solabi"
)
)
var
(
var
(
...
@@ -27,17 +28,6 @@ var (
...
@@ -27,17 +28,6 @@ var (
ConfigUpdateEventVersion0
=
common
.
Hash
{}
ConfigUpdateEventVersion0
=
common
.
Hash
{}
)
)
var
(
// A left-padded uint256 equal to 32.
oneWordUint
=
common
.
Hash
{
31
:
32
}
// A left-padded uint256 equal to 64.
twoWordUint
=
common
.
Hash
{
31
:
64
}
// 24 zero bytes (the padding for a uint64 in a 32 byte word)
uint64Padding
=
make
([]
byte
,
24
)
// 12 zero bytes (the padding for an Ethereum address in a 32 byte word)
addressPadding
=
make
([]
byte
,
12
)
)
// UpdateSystemConfigWithL1Receipts filters all L1 receipts to find config updates and applies the config updates to the given sysCfg
// UpdateSystemConfigWithL1Receipts filters all L1 receipts to find config updates and applies the config updates to the given sysCfg
func
UpdateSystemConfigWithL1Receipts
(
sysCfg
*
eth
.
SystemConfig
,
receipts
[]
*
types
.
Receipt
,
cfg
*
rollup
.
Config
)
error
{
func
UpdateSystemConfigWithL1Receipts
(
sysCfg
*
eth
.
SystemConfig
,
receipts
[]
*
types
.
Receipt
,
cfg
*
rollup
.
Config
)
error
{
var
result
error
var
result
error
...
@@ -84,90 +74,60 @@ func ProcessSystemConfigUpdateLogEvent(destSysCfg *eth.SystemConfig, ev *types.L
...
@@ -84,90 +74,60 @@ func ProcessSystemConfigUpdateLogEvent(destSysCfg *eth.SystemConfig, ev *types.L
// Create a reader of the unindexed data
// Create a reader of the unindexed data
reader
:=
bytes
.
NewReader
(
ev
.
Data
)
reader
:=
bytes
.
NewReader
(
ev
.
Data
)
// Counter for the number of bytes read from `reader` via `readWord`
countReadBytes
:=
0
// Helper function to read a word from the log data reader
readWord
:=
func
()
(
b
[
32
]
byte
)
{
if
_
,
err
:=
reader
.
Read
(
b
[
:
]);
err
!=
nil
{
// If there is an error reading the next 32 bytes from the reader, return an empty
// 32 byte array. We always check that the number of bytes read (`countReadBytes`)
// is equal to the expected amount at the end of each switch case.
return
b
}
countReadBytes
+=
32
return
b
}
// Attempt to read unindexed data
// Attempt to read unindexed data
switch
updateType
{
switch
updateType
{
case
SystemConfigUpdateBatcher
:
case
SystemConfigUpdateBatcher
:
// Read the pointer, it should always equal 32.
if
pointer
,
err
:=
solabi
.
ReadUint64
(
reader
);
err
!=
nil
||
pointer
!=
32
{
if
word
:=
readWord
();
word
!=
oneWordUint
{
return
NewCriticalError
(
errors
.
New
(
"invalid pointer field"
))
return
fmt
.
Errorf
(
"expected offset to point to length location, but got %s"
,
word
)
}
}
if
length
,
err
:=
solabi
.
ReadUint64
(
reader
);
err
!=
nil
||
length
!=
32
{
// Read the length, it should also always equal 32.
return
NewCriticalError
(
errors
.
New
(
"invalid length field"
))
if
word
:=
readWord
();
word
!=
oneWordUint
{
return
fmt
.
Errorf
(
"expected length to be 32 bytes, but got %s"
,
word
)
}
}
address
,
err
:=
solabi
.
ReadAddress
(
reader
)
// Indexing `word` directly is always safe here, it is guaranteed to be 32 bytes in length.
if
err
!=
nil
{
// Check that the batcher address is correctly zero-padded.
return
NewCriticalError
(
errors
.
New
(
"could not read address"
))
word
:=
readWord
()
if
!
bytes
.
Equal
(
word
[
:
12
],
addressPadding
)
{
return
fmt
.
Errorf
(
"expected version 0 batcher hash with zero padding, but got %x"
,
word
)
}
}
destSysCfg
.
BatcherAddr
.
SetBytes
(
word
[
12
:
])
if
!
solabi
.
EmptyReader
(
reader
)
{
return
NewCriticalError
(
errors
.
New
(
"too many bytes"
))
if
countReadBytes
!=
32
*
3
{
return
NewCriticalError
(
fmt
.
Errorf
(
"expected 32*3 bytes in batcher hash update, but got %d bytes"
,
len
(
ev
.
Data
)))
}
}
destSysCfg
.
BatcherAddr
=
address
return
nil
return
nil
case
SystemConfigUpdateGasConfig
:
case
SystemConfigUpdateGasConfig
:
// Read the pointer, it should always equal 32.
if
pointer
,
err
:=
solabi
.
ReadUint64
(
reader
);
err
!=
nil
||
pointer
!=
32
{
if
word
:=
readWord
();
word
!=
oneWordUint
{
return
NewCriticalError
(
errors
.
New
(
"invalid pointer field"
))
return
fmt
.
Errorf
(
"expected offset to point to length location, but got %s"
,
word
)
}
}
if
length
,
err
:=
solabi
.
ReadUint64
(
reader
);
err
!=
nil
||
length
!=
64
{
// Read the length, it should always equal 64.
return
NewCriticalError
(
errors
.
New
(
"invalid length field"
))
if
word
:=
readWord
();
word
!=
twoWordUint
{
return
fmt
.
Errorf
(
"expected length to be 64 bytes, but got %s"
,
word
)
}
}
overhead
,
err
:=
solabi
.
ReadEthBytes32
(
reader
)
// Set the system config's overhead and scalar values to the values read from the log
if
err
!=
nil
{
destSysCfg
.
Overhead
=
readWord
()
return
NewCriticalError
(
errors
.
New
(
"could not read overhead"
))
destSysCfg
.
Scalar
=
readWord
()
if
countReadBytes
!=
32
*
4
{
return
NewCriticalError
(
fmt
.
Errorf
(
"expected 32*4 bytes in GPO params update data, but got %d"
,
len
(
ev
.
Data
)))
}
}
scalar
,
err
:=
solabi
.
ReadEthBytes32
(
reader
)
if
err
!=
nil
{
return
NewCriticalError
(
errors
.
New
(
"could not read scalar"
))
}
if
!
solabi
.
EmptyReader
(
reader
)
{
return
NewCriticalError
(
errors
.
New
(
"too many bytes"
))
}
destSysCfg
.
Overhead
=
overhead
destSysCfg
.
Scalar
=
scalar
return
nil
return
nil
case
SystemConfigUpdateGasLimit
:
case
SystemConfigUpdateGasLimit
:
// Read the pointer, it should always equal 32.
if
pointer
,
err
:=
solabi
.
ReadUint64
(
reader
);
err
!=
nil
||
pointer
!=
32
{
if
word
:=
readWord
();
word
!=
oneWordUint
{
return
NewCriticalError
(
errors
.
New
(
"invalid pointer field"
))
return
fmt
.
Errorf
(
"expected offset to point to length location, but got %s"
,
word
)
}
}
if
length
,
err
:=
solabi
.
ReadUint64
(
reader
);
err
!=
nil
||
length
!=
32
{
// Read the length, it should also always equal 32.
return
NewCriticalError
(
errors
.
New
(
"invalid length field"
))
if
word
:=
readWord
();
word
!=
oneWordUint
{
return
fmt
.
Errorf
(
"expected length to be 32 bytes, but got %s"
,
word
)
}
}
gasLimit
,
err
:=
solabi
.
ReadUint64
(
reader
)
// Indexing `word` directly is always safe here, it is guaranteed to be 32 bytes in length.
if
err
!=
nil
{
// Check that the gas limit is correctly zero-padded.
return
NewCriticalError
(
errors
.
New
(
"could not read gas limit"
))
word
:=
readWord
()
if
!
bytes
.
Equal
(
word
[
:
24
],
uint64Padding
)
{
return
fmt
.
Errorf
(
"expected zero padding for gaslimit, but got %x"
,
word
)
}
}
destSysCfg
.
GasLimit
=
binary
.
BigEndian
.
Uint64
(
word
[
24
:
])
if
!
solabi
.
EmptyReader
(
reader
)
{
return
NewCriticalError
(
errors
.
New
(
"too many bytes"
))
if
countReadBytes
!=
32
*
3
{
return
NewCriticalError
(
fmt
.
Errorf
(
"expected 32*3 bytes in gas limit update, but got %d bytes"
,
len
(
ev
.
Data
)))
}
}
destSysCfg
.
GasLimit
=
gasLimit
return
nil
return
nil
case
SystemConfigUpdateUnsafeBlockSigner
:
case
SystemConfigUpdateUnsafeBlockSigner
:
// Ignored in derivation. This configurable applies to runtime configuration outside of the derivation.
// Ignored in derivation. This configurable applies to runtime configuration outside of the derivation.
...
...
op-service/solabi/util.go
View file @
94a9993c
...
@@ -79,6 +79,12 @@ func ReadUint256(r io.Reader) (*big.Int, error) {
...
@@ -79,6 +79,12 @@ func ReadUint256(r io.Reader) (*big.Int, error) {
return
new
(
big
.
Int
)
.
SetBytes
(
n
[
:
]),
nil
return
new
(
big
.
Int
)
.
SetBytes
(
n
[
:
]),
nil
}
}
func
EmptyReader
(
r
io
.
Reader
)
bool
{
var
t
[
1
]
byte
n
,
err
:=
r
.
Read
(
t
[
:
])
return
n
==
0
&&
err
==
io
.
EOF
}
func
WriteSignature
(
w
io
.
Writer
,
sig
[]
byte
)
error
{
func
WriteSignature
(
w
io
.
Writer
,
sig
[]
byte
)
error
{
_
,
err
:=
w
.
Write
(
sig
)
_
,
err
:=
w
.
Write
(
sig
)
return
err
return
err
...
...
op-service/solabi/utils_test.go
0 → 100644
View file @
94a9993c
package
solabi_test
import
(
"bytes"
"testing"
"github.com/ethereum-optimism/optimism/op-service/solabi"
"github.com/stretchr/testify/require"
)
func
TestEmptyReader
(
t
*
testing
.
T
)
{
t
.
Run
(
"empty"
,
func
(
t
*
testing
.
T
)
{
r
:=
new
(
bytes
.
Buffer
)
require
.
True
(
t
,
solabi
.
EmptyReader
(
r
))
})
t
.
Run
(
"empty after read"
,
func
(
t
*
testing
.
T
)
{
r
:=
bytes
.
NewBufferString
(
"not empty"
)
tmp
:=
make
([]
byte
,
9
)
n
,
err
:=
r
.
Read
(
tmp
)
require
.
Equal
(
t
,
9
,
n
)
require
.
NoError
(
t
,
err
)
require
.
True
(
t
,
solabi
.
EmptyReader
(
r
))
})
t
.
Run
(
"extra bytes"
,
func
(
t
*
testing
.
T
)
{
r
:=
bytes
.
NewBufferString
(
"not empty"
)
require
.
False
(
t
,
solabi
.
EmptyReader
(
r
))
})
}
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