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
28d6921f
Unverified
Commit
28d6921f
authored
Oct 07, 2022
by
Maurelian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: FillBytes size check in deposit marshalling
parent
af72fd09
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
12 deletions
+34
-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
No files found.
op-node/rollup/derive/attributes_test.go
View file @
28d6921f
...
@@ -114,12 +114,13 @@ func TestPreparePayloadAttributes(t *testing.T) {
...
@@ -114,12 +114,13 @@ func TestPreparePayloadAttributes(t *testing.T) {
l1Info
.
InfoParentHash
=
l2Parent
.
L1Origin
.
Hash
l1Info
.
InfoParentHash
=
l2Parent
.
L1Origin
.
Hash
l1Info
.
InfoNum
=
l2Parent
.
L1Origin
.
Number
+
1
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
,
false
}},
{
goodReceipt
:
true
,
DepositLogs
:
[]
bool
{
true
}},
{
goodReceipt
:
true
,
DepositLogs
:
[]
bool
{
true
}},
{
goodReceipt
:
false
,
DepositLogs
:
[]
bool
{
true
}},
{
goodReceipt
:
false
,
DepositLogs
:
[]
bool
{
true
}},
{
goodReceipt
:
false
,
DepositLogs
:
[]
bool
{
false
}},
{
goodReceipt
:
false
,
DepositLogs
:
[]
bool
{
false
}},
})
})
require
.
NoError
(
t
,
err
)
usedDepositTxs
,
err
:=
encodeDeposits
(
depositTxs
)
usedDepositTxs
,
err
:=
encodeDeposits
(
depositTxs
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
...
...
op-node/rollup/derive/deposit_log.go
View file @
28d6921f
...
@@ -140,7 +140,7 @@ func unmarshalDepositVersion0(dep *types.DepositTx, to common.Address, opaqueDat
...
@@ -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.
// MarshalDepositLogEvent returns an EVM log entry that encodes a TransactionDeposited event from the deposit contract.
// This is the reverse of the deposit transaction derivation.
// 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
{}
toBytes
:=
common
.
Hash
{}
if
deposit
.
To
!=
nil
{
if
deposit
.
To
!=
nil
{
toBytes
=
deposit
.
To
.
Hash
()
toBytes
=
deposit
.
To
.
Hash
()
...
@@ -157,7 +157,10 @@ func MarshalDepositLogEvent(depositContractAddr common.Address, deposit *types.D
...
@@ -157,7 +157,10 @@ func MarshalDepositLogEvent(depositContractAddr common.Address, deposit *types.D
// opaqueData slice content offset: value will always be 0x20.
// opaqueData slice content offset: value will always be 0x20.
binary
.
BigEndian
.
PutUint64
(
data
[
32
-
8
:
32
],
32
)
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
// opaqueData slice length
binary
.
BigEndian
.
PutUint64
(
data
[
64
-
8
:
64
],
uint64
(
len
(
opaqueData
)))
binary
.
BigEndian
.
PutUint64
(
data
[
64
-
8
:
64
],
uint64
(
len
(
opaqueData
)))
...
@@ -182,20 +185,26 @@ func MarshalDepositLogEvent(depositContractAddr common.Address, deposit *types.D
...
@@ -182,20 +185,26 @@ func MarshalDepositLogEvent(depositContractAddr common.Address, deposit *types.D
TxIndex
:
0
,
TxIndex
:
0
,
BlockHash
:
common
.
Hash
{},
BlockHash
:
common
.
Hash
{},
Index
:
0
,
Index
:
0
,
}
}
,
nil
}
}
func
marshalDepositVersion0
(
deposit
*
types
.
DepositTx
)
(
opaqueData
[]
byte
)
{
func
marshalDepositVersion0
(
deposit
*
types
.
DepositTx
)
(
[]
byte
,
error
)
{
opaqueData
=
make
([]
byte
,
32
+
32
+
8
+
1
,
32
+
32
+
8
+
1
+
len
(
deposit
.
Data
))
opaqueData
:
=
make
([]
byte
,
32
+
32
+
8
+
1
,
32
+
32
+
8
+
1
+
len
(
deposit
.
Data
))
offset
:=
0
offset
:=
0
// uint256 mint
// uint256 mint
if
deposit
.
Mint
!=
nil
{
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
])
deposit
.
Mint
.
FillBytes
(
opaqueData
[
offset
:
offset
+
32
])
}
}
offset
+=
32
offset
+=
32
// uint256 value
// 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
])
deposit
.
Value
.
FillBytes
(
opaqueData
[
offset
:
offset
+
32
])
offset
+=
32
offset
+=
32
...
@@ -211,5 +220,5 @@ func marshalDepositVersion0(deposit *types.DepositTx) (opaqueData []byte) {
...
@@ -211,5 +220,5 @@ func marshalDepositVersion0(deposit *types.DepositTx) (opaqueData []byte) {
// Deposit data then fills the remaining event data
// Deposit data then fills the remaining event data
opaqueData
=
append
(
opaqueData
,
deposit
.
Data
...
)
opaqueData
=
append
(
opaqueData
,
deposit
.
Data
...
)
return
opaqueData
return
opaqueData
,
nil
}
}
op-node/rollup/derive/deposit_log_test.go
View file @
28d6921f
...
@@ -23,7 +23,10 @@ func TestUnmarshalLogEvent(t *testing.T) {
...
@@ -23,7 +23,10 @@ func TestUnmarshalLogEvent(t *testing.T) {
LogIndex
:
uint64
(
rng
.
Intn
(
10000
)),
LogIndex
:
uint64
(
rng
.
Intn
(
10000
)),
}
}
depInput
:=
testutils
.
GenerateDeposit
(
source
.
SourceHash
(),
rng
)
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
.
TxIndex
=
uint
(
rng
.
Intn
(
10000
))
log
.
Index
=
uint
(
source
.
LogIndex
)
log
.
Index
=
uint
(
source
.
LogIndex
)
...
@@ -47,8 +50,10 @@ type receiptData struct {
...
@@ -47,8 +50,10 @@ type receiptData struct {
DepositLogs
[]
bool
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
)
logIndex
:=
uint
(
0
)
receipts
:=
[]
*
types
.
Receipt
{}
expectedDeposits
:=
[]
*
types
.
DepositTx
{}
for
txIndex
,
rData
:=
range
testReceipts
{
for
txIndex
,
rData
:=
range
testReceipts
{
var
logs
[]
*
types
.
Log
var
logs
[]
*
types
.
Log
status
:=
types
.
ReceiptStatusSuccessful
status
:=
types
.
ReceiptStatusSuccessful
...
@@ -57,13 +62,17 @@ func makeReceipts(rng *rand.Rand, blockHash common.Hash, depositContractAddr com
...
@@ -57,13 +62,17 @@ func makeReceipts(rng *rand.Rand, blockHash common.Hash, depositContractAddr com
}
}
for
_
,
isDeposit
:=
range
rData
.
DepositLogs
{
for
_
,
isDeposit
:=
range
rData
.
DepositLogs
{
var
ev
*
types
.
Log
var
ev
*
types
.
Log
var
err
error
if
isDeposit
{
if
isDeposit
{
source
:=
UserDepositSource
{
L1BlockHash
:
blockHash
,
LogIndex
:
uint64
(
logIndex
)}
source
:=
UserDepositSource
{
L1BlockHash
:
blockHash
,
LogIndex
:
uint64
(
logIndex
)}
dep
:=
testutils
.
GenerateDeposit
(
source
.
SourceHash
(),
rng
)
dep
:=
testutils
.
GenerateDeposit
(
source
.
SourceHash
(),
rng
)
if
status
==
types
.
ReceiptStatusSuccessful
{
if
status
==
types
.
ReceiptStatusSuccessful
{
expectedDeposits
=
append
(
expectedDeposits
,
dep
)
expectedDeposits
=
append
(
expectedDeposits
,
dep
)
}
}
ev
=
MarshalDepositLogEvent
(
depositContractAddr
,
dep
)
ev
,
err
=
MarshalDepositLogEvent
(
depositContractAddr
,
dep
)
if
err
!=
nil
{
return
[]
*
types
.
Receipt
{},
[]
*
types
.
DepositTx
{},
err
}
}
else
{
}
else
{
ev
=
testutils
.
GenerateLog
(
testutils
.
RandomAddress
(
rng
),
nil
,
nil
)
ev
=
testutils
.
GenerateLog
(
testutils
.
RandomAddress
(
rng
),
nil
,
nil
)
}
}
...
@@ -82,7 +91,7 @@ func makeReceipts(rng *rand.Rand, blockHash common.Hash, depositContractAddr com
...
@@ -82,7 +91,7 @@ func makeReceipts(rng *rand.Rand, blockHash common.Hash, depositContractAddr com
TransactionIndex
:
uint
(
txIndex
),
TransactionIndex
:
uint
(
txIndex
),
})
})
}
}
return
return
receipts
,
expectedDeposits
,
nil
}
}
type
DeriveUserDepositsTestCase
struct
{
type
DeriveUserDepositsTestCase
struct
{
...
@@ -108,7 +117,10 @@ func TestDeriveUserDeposits(t *testing.T) {
...
@@ -108,7 +117,10 @@ func TestDeriveUserDeposits(t *testing.T) {
t
.
Run
(
testCase
.
name
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
testCase
.
name
,
func
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
1234
+
int64
(
i
)))
rng
:=
rand
.
New
(
rand
.
NewSource
(
1234
+
int64
(
i
)))
blockHash
:=
testutils
.
RandomHash
(
rng
)
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
)
got
,
err
:=
UserDeposits
(
receipts
,
MockDepositContractAddr
)
require
.
NoError
(
t
,
err
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
len
(
got
),
len
(
expectedDeposits
))
require
.
Equal
(
t
,
len
(
got
),
len
(
expectedDeposits
))
...
...
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