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
5a897e2a
Commit
5a897e2a
authored
Jan 17, 2023
by
clabby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inline read func; ignore possible errors from `Read` due to length check
parent
ec73572d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
40 deletions
+37
-40
system_config.go
op-node/rollup/derive/system_config.go
+37
-40
No files found.
op-node/rollup/derive/system_config.go
View file @
5a897e2a
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-multierror"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/eth"
...
@@ -27,6 +28,8 @@ var (
...
@@ -27,6 +28,8 @@ var (
ConfigUpdateEventVersion0
=
common
.
Hash
{}
ConfigUpdateEventVersion0
=
common
.
Hash
{}
)
)
var
logger
=
log
.
New
(
"derive"
,
"system_config"
)
// 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
...
@@ -75,6 +78,20 @@ func ProcessSystemConfigUpdateLogEvent(destSysCfg *eth.SystemConfig, ev *types.L
...
@@ -75,6 +78,20 @@ func ProcessSystemConfigUpdateLogEvent(destSysCfg *eth.SystemConfig, ev *types.L
// Allocate a placeholder word to read into
// Allocate a placeholder word to read into
word
:=
make
([]
byte
,
32
)
word
:=
make
([]
byte
,
32
)
// Helper function to prevent code duplication.
readIntoWord
:=
func
(
b
[]
byte
)
{
// Sanity check that the byte array we're reading into is always 32 bytes in length.
if
len
(
b
)
!=
32
{
panic
(
"invalid word length"
)
}
if
_
,
err
:=
reader
.
Read
(
b
);
err
!=
nil
{
// The possible error returned by `Read` is ignored due to the length check of the unindexed data in
// all cases of the below switch statement. While we don't panic here, this log should *never* be emitted.
logger
.
Crit
(
"failed to read word from unindexed log data"
)
}
}
// Attempt to read unindexed data
// Attempt to read unindexed data
switch
updateType
{
switch
updateType
{
case
SystemConfigUpdateBatcher
:
case
SystemConfigUpdateBatcher
:
...
@@ -82,26 +99,20 @@ func ProcessSystemConfigUpdateLogEvent(destSysCfg *eth.SystemConfig, ev *types.L
...
@@ -82,26 +99,20 @@ func ProcessSystemConfigUpdateLogEvent(destSysCfg *eth.SystemConfig, ev *types.L
return
fmt
.
Errorf
(
"expected 32*3 bytes in batcher hash update, but got %d bytes"
,
len
(
ev
.
Data
))
return
fmt
.
Errorf
(
"expected 32*3 bytes in batcher hash update, but got %d bytes"
,
len
(
ev
.
Data
))
}
}
// Attempt to read the pointer, it should always equal 32.
// Read the pointer, it should always equal 32.
if
_
,
err
:=
reader
.
Read
(
word
);
err
!=
nil
{
readIntoWord
(
word
)
return
fmt
.
Errorf
(
"failed to read pointer in batcher address update"
)
}
if
common
.
BytesToHash
(
word
)
!=
(
common
.
Hash
{
31
:
32
})
{
if
common
.
BytesToHash
(
word
)
!=
(
common
.
Hash
{
31
:
32
})
{
return
fmt
.
Errorf
(
"expected offset to point to length location, but got %s"
,
word
)
return
fmt
.
Errorf
(
"expected offset to point to length location, but got %s"
,
word
)
}
}
// Attempt to read the length, it should also always equal 32.
// Read the length, it should also always equal 32.
if
_
,
err
:=
reader
.
Read
(
word
);
err
!=
nil
{
readIntoWord
(
word
)
return
fmt
.
Errorf
(
"failed to read length in batcher address update"
)
}
if
common
.
BytesToHash
(
word
)
!=
(
common
.
Hash
{
31
:
32
})
{
if
common
.
BytesToHash
(
word
)
!=
(
common
.
Hash
{
31
:
32
})
{
return
fmt
.
Errorf
(
"expected length to be 32 bytes, but got %s"
,
word
)
return
fmt
.
Errorf
(
"expected length to be 32 bytes, but got %s"
,
word
)
}
}
// Attempt to read the batcher hash
// Read the updated batcher address
if
_
,
err
:=
reader
.
Read
(
word
);
err
!=
nil
{
readIntoWord
(
word
)
return
fmt
.
Errorf
(
"failed to read batcher hash in batcher address update"
)
}
// Indexing `word` directly is always safe here, it is guaranteed to be 32 bytes in length.
// Indexing `word` directly is always safe here, it is guaranteed to be 32 bytes in length.
// Check that the batcher address is correctly zero-padded.
// Check that the batcher address is correctly zero-padded.
if
!
bytes
.
Equal
(
word
[
:
12
],
make
([]
byte
,
12
))
{
if
!
bytes
.
Equal
(
word
[
:
12
],
make
([]
byte
,
12
))
{
...
@@ -114,34 +125,26 @@ func ProcessSystemConfigUpdateLogEvent(destSysCfg *eth.SystemConfig, ev *types.L
...
@@ -114,34 +125,26 @@ func ProcessSystemConfigUpdateLogEvent(destSysCfg *eth.SystemConfig, ev *types.L
return
fmt
.
Errorf
(
"expected 32*4 bytes in GPO params update data, but got %d"
,
len
(
ev
.
Data
))
return
fmt
.
Errorf
(
"expected 32*4 bytes in GPO params update data, but got %d"
,
len
(
ev
.
Data
))
}
}
// Attempt to read the pointer, it should always equal 32.
// Read the pointer, it should always equal 32.
if
_
,
err
:=
reader
.
Read
(
word
);
err
!=
nil
{
readIntoWord
(
word
)
return
fmt
.
Errorf
(
"failed to read pointer in GPO params update"
)
}
if
common
.
BytesToHash
(
word
)
!=
(
common
.
Hash
{
31
:
32
})
{
if
common
.
BytesToHash
(
word
)
!=
(
common
.
Hash
{
31
:
32
})
{
return
fmt
.
Errorf
(
"expected offset to point to length location, but got %s"
,
word
)
return
fmt
.
Errorf
(
"expected offset to point to length location, but got %s"
,
word
)
}
}
// Attempt to read the length, it should always equal 64.
// Read the length, it should always equal 64.
if
_
,
err
:=
reader
.
Read
(
word
);
err
!=
nil
{
readIntoWord
(
word
)
return
fmt
.
Errorf
(
"failed to read length in GPO params update"
)
}
if
common
.
BytesToHash
(
word
)
!=
(
common
.
Hash
{
31
:
64
})
{
if
common
.
BytesToHash
(
word
)
!=
(
common
.
Hash
{
31
:
64
})
{
return
fmt
.
Errorf
(
"expected length to be 64 bytes, but got %s"
,
word
)
return
fmt
.
Errorf
(
"expected length to be 64 bytes, but got %s"
,
word
)
}
}
// Attempt to read the overhead
// Read the overhead
if
_
,
err
:=
reader
.
Read
(
word
);
err
!=
nil
{
readIntoWord
(
word
)
return
fmt
.
Errorf
(
"failed to read overhead in GPO params update"
)
}
// Allocate a second word to read the scalar into
// Allocate a second word to read the scalar into
secondWord
:=
make
([]
byte
,
32
)
secondWord
:=
make
([]
byte
,
32
)
// Attempt to read the scalar
// Read the scalar
if
_
,
err
:=
reader
.
Read
(
secondWord
);
err
!=
nil
{
readIntoWord
(
secondWord
)
return
fmt
.
Errorf
(
"failed to read scalar in GPO params update"
)
}
// Set the system config's overhead and scalar values to the values read from the log
// Set the system config's overhead and scalar values to the values read from the log
copy
(
destSysCfg
.
Overhead
[
:
],
word
)
copy
(
destSysCfg
.
Overhead
[
:
],
word
)
...
@@ -152,26 +155,20 @@ func ProcessSystemConfigUpdateLogEvent(destSysCfg *eth.SystemConfig, ev *types.L
...
@@ -152,26 +155,20 @@ func ProcessSystemConfigUpdateLogEvent(destSysCfg *eth.SystemConfig, ev *types.L
return
fmt
.
Errorf
(
"expected 32*3 bytes in gas limit update, but got %d bytes"
,
len
(
ev
.
Data
))
return
fmt
.
Errorf
(
"expected 32*3 bytes in gas limit update, but got %d bytes"
,
len
(
ev
.
Data
))
}
}
// Attempt to read the pointer, it should always equal 32.
// Read the pointer, it should always equal 32.
if
_
,
err
:=
reader
.
Read
(
word
);
err
!=
nil
{
readIntoWord
(
word
)
return
fmt
.
Errorf
(
"failed to read pointer in gas limit update"
)
}
if
common
.
BytesToHash
(
word
)
!=
(
common
.
Hash
{
31
:
32
})
{
if
common
.
BytesToHash
(
word
)
!=
(
common
.
Hash
{
31
:
32
})
{
return
fmt
.
Errorf
(
"expected offset to point to length location, but got %s"
,
word
)
return
fmt
.
Errorf
(
"expected offset to point to length location, but got %s"
,
word
)
}
}
// Attempt to read the length, it should also always equal 32.
// Read the length, it should also always equal 32.
if
_
,
err
:=
reader
.
Read
(
word
);
err
!=
nil
{
readIntoWord
(
word
)
return
fmt
.
Errorf
(
"failed to read length in gas limit update"
)
}
if
common
.
BytesToHash
(
word
)
!=
(
common
.
Hash
{
31
:
32
})
{
if
common
.
BytesToHash
(
word
)
!=
(
common
.
Hash
{
31
:
32
})
{
return
fmt
.
Errorf
(
"expected length to be 32 bytes, but got %s"
,
word
)
return
fmt
.
Errorf
(
"expected length to be 32 bytes, but got %s"
,
word
)
}
}
// Attempt to read the gas limit
// Read the gas limit
if
_
,
err
:=
reader
.
Read
(
word
);
err
!=
nil
{
readIntoWord
(
word
)
return
fmt
.
Errorf
(
"failed to read gas limit in gas limit update"
)
}
// Indexing `word` directly is always safe here, it is guaranteed to be 32 bytes in length.
// Indexing `word` directly is always safe here, it is guaranteed to be 32 bytes in length.
// Check that the gas limit is correctly zero-padded.
// Check that the gas limit is correctly zero-padded.
if
!
bytes
.
Equal
(
word
[
:
24
],
make
([]
byte
,
24
))
{
if
!
bytes
.
Equal
(
word
[
:
24
],
make
([]
byte
,
24
))
{
...
...
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