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
3dcf11ba
Unverified
Commit
3dcf11ba
authored
Oct 08, 2022
by
mergify[bot]
Committed by
GitHub
Oct 08, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3674 from ethereum-optimism/fix/opb-02
op-node: Fillbytes size check in l1 block info
parents
8c8adcf6
e074acb6
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
12 deletions
+38
-12
attributes_test.go
op-node/rollup/derive/attributes_test.go
+2
-1
deposit_log.go
op-node/rollup/derive/deposit_log.go
+15
-6
deposit_log_test.go
op-node/rollup/derive/deposit_log_test.go
+17
-5
l1_block_info.go
op-node/rollup/derive/l1_block_info.go
+4
-0
No files found.
op-node/rollup/derive/attributes_test.go
View file @
3dcf11ba
...
...
@@ -114,12 +114,13 @@ func TestPreparePayloadAttributes(t *testing.T) {
l1Info
.
InfoParentHash
=
l2Parent
.
L1Origin
.
Hash
l1Info
.
InfoNum
=
l2Parent
.
L1Origin
.
Number
+
1
receipts
,
depositTxs
:=
makeReceipts
(
rng
,
l1Info
.
InfoHash
,
cfg
.
DepositContractAddress
,
[]
receiptData
{
receipts
,
depositTxs
,
err
:=
makeReceipts
(
rng
,
l1Info
.
InfoHash
,
cfg
.
DepositContractAddress
,
[]
receiptData
{
{
goodReceipt
:
true
,
DepositLogs
:
[]
bool
{
true
,
false
}},
{
goodReceipt
:
true
,
DepositLogs
:
[]
bool
{
true
}},
{
goodReceipt
:
false
,
DepositLogs
:
[]
bool
{
true
}},
{
goodReceipt
:
false
,
DepositLogs
:
[]
bool
{
false
}},
})
require
.
NoError
(
t
,
err
)
usedDepositTxs
,
err
:=
encodeDeposits
(
depositTxs
)
require
.
NoError
(
t
,
err
)
...
...
op-node/rollup/derive/deposit_log.go
View file @
3dcf11ba
...
...
@@ -140,7 +140,7 @@ func unmarshalDepositVersion0(dep *types.DepositTx, to common.Address, opaqueDat
// MarshalDepositLogEvent returns an EVM log entry that encodes a TransactionDeposited event from the deposit contract.
// This is the reverse of the deposit transaction derivation.
func
MarshalDepositLogEvent
(
depositContractAddr
common
.
Address
,
deposit
*
types
.
DepositTx
)
*
types
.
Log
{
func
MarshalDepositLogEvent
(
depositContractAddr
common
.
Address
,
deposit
*
types
.
DepositTx
)
(
*
types
.
Log
,
error
)
{
toBytes
:=
common
.
Hash
{}
if
deposit
.
To
!=
nil
{
toBytes
=
deposit
.
To
.
Hash
()
...
...
@@ -157,7 +157,10 @@ func MarshalDepositLogEvent(depositContractAddr common.Address, deposit *types.D
// opaqueData slice content offset: value will always be 0x20.
binary
.
BigEndian
.
PutUint64
(
data
[
32
-
8
:
32
],
32
)
opaqueData
:=
marshalDepositVersion0
(
deposit
)
opaqueData
,
err
:=
marshalDepositVersion0
(
deposit
)
if
err
!=
nil
{
return
&
types
.
Log
{},
err
}
// opaqueData slice length
binary
.
BigEndian
.
PutUint64
(
data
[
64
-
8
:
64
],
uint64
(
len
(
opaqueData
)))
...
...
@@ -182,20 +185,26 @@ func MarshalDepositLogEvent(depositContractAddr common.Address, deposit *types.D
TxIndex
:
0
,
BlockHash
:
common
.
Hash
{},
Index
:
0
,
}
}
,
nil
}
func
marshalDepositVersion0
(
deposit
*
types
.
DepositTx
)
(
opaqueData
[]
byte
)
{
opaqueData
=
make
([]
byte
,
32
+
32
+
8
+
1
,
32
+
32
+
8
+
1
+
len
(
deposit
.
Data
))
func
marshalDepositVersion0
(
deposit
*
types
.
DepositTx
)
(
[]
byte
,
error
)
{
opaqueData
:
=
make
([]
byte
,
32
+
32
+
8
+
1
,
32
+
32
+
8
+
1
+
len
(
deposit
.
Data
))
offset
:=
0
// uint256 mint
if
deposit
.
Mint
!=
nil
{
if
deposit
.
Mint
.
BitLen
()
>
256
{
return
nil
,
fmt
.
Errorf
(
"mint value exceeds 256 bits: %d"
,
deposit
.
Mint
)
}
deposit
.
Mint
.
FillBytes
(
opaqueData
[
offset
:
offset
+
32
])
}
offset
+=
32
// uint256 value
if
deposit
.
Value
.
BitLen
()
>
256
{
return
nil
,
fmt
.
Errorf
(
"value value exceeds 256 bits: %d"
,
deposit
.
Value
)
}
deposit
.
Value
.
FillBytes
(
opaqueData
[
offset
:
offset
+
32
])
offset
+=
32
...
...
@@ -211,5 +220,5 @@ func marshalDepositVersion0(deposit *types.DepositTx) (opaqueData []byte) {
// Deposit data then fills the remaining event data
opaqueData
=
append
(
opaqueData
,
deposit
.
Data
...
)
return
opaqueData
return
opaqueData
,
nil
}
op-node/rollup/derive/deposit_log_test.go
View file @
3dcf11ba
...
...
@@ -23,7 +23,10 @@ func TestUnmarshalLogEvent(t *testing.T) {
LogIndex
:
uint64
(
rng
.
Intn
(
10000
)),
}
depInput
:=
testutils
.
GenerateDeposit
(
source
.
SourceHash
(),
rng
)
log
:=
MarshalDepositLogEvent
(
MockDepositContractAddr
,
depInput
)
log
,
err
:=
MarshalDepositLogEvent
(
MockDepositContractAddr
,
depInput
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
log
.
TxIndex
=
uint
(
rng
.
Intn
(
10000
))
log
.
Index
=
uint
(
source
.
LogIndex
)
...
...
@@ -47,8 +50,10 @@ type receiptData struct {
DepositLogs
[]
bool
}
func
makeReceipts
(
rng
*
rand
.
Rand
,
blockHash
common
.
Hash
,
depositContractAddr
common
.
Address
,
testReceipts
[]
receiptData
)
(
receipts
[]
*
types
.
Receipt
,
expectedDeposits
[]
*
types
.
DepositTx
)
{
func
makeReceipts
(
rng
*
rand
.
Rand
,
blockHash
common
.
Hash
,
depositContractAddr
common
.
Address
,
testReceipts
[]
receiptData
)
(
[]
*
types
.
Receipt
,
[]
*
types
.
DepositTx
,
error
)
{
logIndex
:=
uint
(
0
)
receipts
:=
[]
*
types
.
Receipt
{}
expectedDeposits
:=
[]
*
types
.
DepositTx
{}
for
txIndex
,
rData
:=
range
testReceipts
{
var
logs
[]
*
types
.
Log
status
:=
types
.
ReceiptStatusSuccessful
...
...
@@ -57,13 +62,17 @@ func makeReceipts(rng *rand.Rand, blockHash common.Hash, depositContractAddr com
}
for
_
,
isDeposit
:=
range
rData
.
DepositLogs
{
var
ev
*
types
.
Log
var
err
error
if
isDeposit
{
source
:=
UserDepositSource
{
L1BlockHash
:
blockHash
,
LogIndex
:
uint64
(
logIndex
)}
dep
:=
testutils
.
GenerateDeposit
(
source
.
SourceHash
(),
rng
)
if
status
==
types
.
ReceiptStatusSuccessful
{
expectedDeposits
=
append
(
expectedDeposits
,
dep
)
}
ev
=
MarshalDepositLogEvent
(
depositContractAddr
,
dep
)
ev
,
err
=
MarshalDepositLogEvent
(
depositContractAddr
,
dep
)
if
err
!=
nil
{
return
[]
*
types
.
Receipt
{},
[]
*
types
.
DepositTx
{},
err
}
}
else
{
ev
=
testutils
.
GenerateLog
(
testutils
.
RandomAddress
(
rng
),
nil
,
nil
)
}
...
...
@@ -82,7 +91,7 @@ func makeReceipts(rng *rand.Rand, blockHash common.Hash, depositContractAddr com
TransactionIndex
:
uint
(
txIndex
),
})
}
return
return
receipts
,
expectedDeposits
,
nil
}
type
DeriveUserDepositsTestCase
struct
{
...
...
@@ -108,7 +117,10 @@ func TestDeriveUserDeposits(t *testing.T) {
t
.
Run
(
testCase
.
name
,
func
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
1234
+
int64
(
i
)))
blockHash
:=
testutils
.
RandomHash
(
rng
)
receipts
,
expectedDeposits
:=
makeReceipts
(
rng
,
blockHash
,
MockDepositContractAddr
,
testCase
.
receipts
)
receipts
,
expectedDeposits
,
err
:=
makeReceipts
(
rng
,
blockHash
,
MockDepositContractAddr
,
testCase
.
receipts
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
got
,
err
:=
UserDeposits
(
receipts
,
MockDepositContractAddr
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
got
),
len
(
expectedDeposits
))
...
...
op-node/rollup/derive/l1_block_info.go
View file @
3dcf11ba
...
...
@@ -40,6 +40,10 @@ func (info *L1BlockInfo) MarshalBinary() ([]byte, error) {
offset
+=
32
binary
.
BigEndian
.
PutUint64
(
data
[
offset
+
24
:
offset
+
32
],
info
.
Time
)
offset
+=
32
// Ensure that the baseFee is not too large.
if
info
.
BaseFee
.
BitLen
()
>
256
{
return
nil
,
fmt
.
Errorf
(
"base fee exceeds 256 bits: %d"
,
info
.
BaseFee
)
}
info
.
BaseFee
.
FillBytes
(
data
[
offset
:
offset
+
32
])
offset
+=
32
copy
(
data
[
offset
:
offset
+
32
],
info
.
BlockHash
.
Bytes
())
...
...
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