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
835dd0ff
Commit
835dd0ff
authored
Mar 17, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add maxSize check to the channel out OutputFrame
⚙
parent
2351ed46
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
8 deletions
+35
-8
channel_out.go
op-node/rollup/derive/channel_out.go
+7
-0
channel_out_test.go
op-node/rollup/derive/channel_out_test.go
+28
-8
No files found.
op-node/rollup/derive/channel_out.go
View file @
835dd0ff
...
@@ -14,6 +14,7 @@ import (
...
@@ -14,6 +14,7 @@ import (
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rlp"
)
)
var
ErrMaxFrameSizeTooSmall
=
errors
.
New
(
"maxSize is too small to fit the fixed frame overhead"
)
var
ErrNotDepositTx
=
errors
.
New
(
"first transaction in block is not a deposit tx"
)
var
ErrNotDepositTx
=
errors
.
New
(
"first transaction in block is not a deposit tx"
)
var
ErrTooManyRLPBytes
=
errors
.
New
(
"batch would cause RLP bytes to go over limit"
)
var
ErrTooManyRLPBytes
=
errors
.
New
(
"batch would cause RLP bytes to go over limit"
)
...
@@ -150,6 +151,12 @@ func (co *ChannelOut) OutputFrame(w *bytes.Buffer, maxSize uint64) (uint16, erro
...
@@ -150,6 +151,12 @@ func (co *ChannelOut) OutputFrame(w *bytes.Buffer, maxSize uint64) (uint16, erro
FrameNumber
:
uint16
(
co
.
frame
),
FrameNumber
:
uint16
(
co
.
frame
),
}
}
// Error if the `maxSize` is too small to fit the fixed frame
// overhead as specified below.
if
maxSize
<
23
{
return
0
,
ErrMaxFrameSizeTooSmall
}
// Copy data from the local buffer into the frame data buffer
// Copy data from the local buffer into the frame data buffer
// Don't go past the maxSize with the fixed frame overhead.
// Don't go past the maxSize with the fixed frame overhead.
// Fixed overhead: 16 + 2 + 4 + 1 = 23 bytes.
// Fixed overhead: 16 + 2 + 4 + 1 = 23 bytes.
...
...
op-node/rollup/derive/channel_out_test.go
View file @
835dd0ff
...
@@ -29,6 +29,26 @@ func TestChannelOutAddBlock(t *testing.T) {
...
@@ -29,6 +29,26 @@ func TestChannelOutAddBlock(t *testing.T) {
})
})
}
}
// TestOutputFrameSmallMaxSize tests that calling [OutputFrame] with a small
// max size that is below the fixed frame size overhead of 23, will return
// an error.
func
TestOutputFrameSmallMaxSize
(
t
*
testing
.
T
)
{
cout
,
err
:=
NewChannelOut
()
require
.
NoError
(
t
,
err
)
// Set the channel out frame details
cout
.
id
=
ChannelID
{
0x01
}
cout
.
frame
=
0
// Call OutputFrame with the range of small max size values that err
w
:=
bytes
.
NewBuffer
([]
byte
{})
for
i
:=
0
;
i
<
23
;
i
++
{
fid
,
err
:=
cout
.
OutputFrame
(
w
,
uint64
(
i
))
require
.
ErrorIs
(
t
,
err
,
ErrMaxFrameSizeTooSmall
)
require
.
Zero
(
t
,
fid
)
}
}
// TestRLPByteLimit ensures that stream encoder is properly limiting the length.
// TestRLPByteLimit ensures that stream encoder is properly limiting the length.
// It will decode the input if `len(input) <= inputLimit`.
// It will decode the input if `len(input) <= inputLimit`.
func
TestRLPByteLimit
(
t
*
testing
.
T
)
{
func
TestRLPByteLimit
(
t
*
testing
.
T
)
{
...
@@ -64,42 +84,42 @@ func TestForceCloseTxData(t *testing.T) {
...
@@ -64,42 +84,42 @@ func TestForceCloseTxData(t *testing.T) {
output
:
""
,
output
:
""
,
},
},
{
{
frames
:
[]
Frame
{
Frame
{
FrameNumber
:
0
,
IsLast
:
false
},
Frame
{
ID
:
id
,
FrameNumber
:
1
,
IsLast
:
true
}},
frames
:
[]
Frame
{
{
FrameNumber
:
0
,
IsLast
:
false
},
{
ID
:
id
,
FrameNumber
:
1
,
IsLast
:
true
}},
errors
:
true
,
errors
:
true
,
output
:
""
,
output
:
""
,
},
},
{
{
frames
:
[]
Frame
{
Frame
{
ID
:
id
,
FrameNumber
:
0
,
IsLast
:
false
}},
frames
:
[]
Frame
{{
ID
:
id
,
FrameNumber
:
0
,
IsLast
:
false
}},
errors
:
false
,
errors
:
false
,
output
:
"00deadbeefdeadbeefdeadbeefdeadbeef00000000000001"
,
output
:
"00deadbeefdeadbeefdeadbeefdeadbeef00000000000001"
,
},
},
{
{
frames
:
[]
Frame
{
Frame
{
ID
:
id
,
FrameNumber
:
0
,
IsLast
:
true
}},
frames
:
[]
Frame
{{
ID
:
id
,
FrameNumber
:
0
,
IsLast
:
true
}},
errors
:
false
,
errors
:
false
,
output
:
"00"
,
output
:
"00"
,
},
},
{
{
frames
:
[]
Frame
{
Frame
{
ID
:
id
,
FrameNumber
:
1
,
IsLast
:
false
}},
frames
:
[]
Frame
{{
ID
:
id
,
FrameNumber
:
1
,
IsLast
:
false
}},
errors
:
false
,
errors
:
false
,
output
:
"00deadbeefdeadbeefdeadbeefdeadbeef00000000000001"
,
output
:
"00deadbeefdeadbeefdeadbeefdeadbeef00000000000001"
,
},
},
{
{
frames
:
[]
Frame
{
Frame
{
ID
:
id
,
FrameNumber
:
1
,
IsLast
:
true
}},
frames
:
[]
Frame
{{
ID
:
id
,
FrameNumber
:
1
,
IsLast
:
true
}},
errors
:
false
,
errors
:
false
,
output
:
"00deadbeefdeadbeefdeadbeefdeadbeef00000000000000"
,
output
:
"00deadbeefdeadbeefdeadbeefdeadbeef00000000000000"
,
},
},
{
{
frames
:
[]
Frame
{
Frame
{
ID
:
id
,
FrameNumber
:
2
,
IsLast
:
true
}},
frames
:
[]
Frame
{{
ID
:
id
,
FrameNumber
:
2
,
IsLast
:
true
}},
errors
:
false
,
errors
:
false
,
output
:
"00deadbeefdeadbeefdeadbeefdeadbeef00000000000000deadbeefdeadbeefdeadbeefdeadbeef00010000000000"
,
output
:
"00deadbeefdeadbeefdeadbeefdeadbeef00000000000000deadbeefdeadbeefdeadbeefdeadbeef00010000000000"
,
},
},
{
{
frames
:
[]
Frame
{
Frame
{
ID
:
id
,
FrameNumber
:
1
,
IsLast
:
false
},
Frame
{
ID
:
id
,
FrameNumber
:
3
,
IsLast
:
true
}},
frames
:
[]
Frame
{
{
ID
:
id
,
FrameNumber
:
1
,
IsLast
:
false
},
{
ID
:
id
,
FrameNumber
:
3
,
IsLast
:
true
}},
errors
:
false
,
errors
:
false
,
output
:
"00deadbeefdeadbeefdeadbeefdeadbeef00000000000000deadbeefdeadbeefdeadbeefdeadbeef00020000000000"
,
output
:
"00deadbeefdeadbeefdeadbeefdeadbeef00000000000000deadbeefdeadbeefdeadbeefdeadbeef00020000000000"
,
},
},
{
{
frames
:
[]
Frame
{
Frame
{
ID
:
id
,
FrameNumber
:
1
,
IsLast
:
false
},
Frame
{
ID
:
id
,
FrameNumber
:
3
,
IsLast
:
true
},
Frame
{
ID
:
id
,
FrameNumber
:
5
,
IsLast
:
true
}},
frames
:
[]
Frame
{
{
ID
:
id
,
FrameNumber
:
1
,
IsLast
:
false
},
{
ID
:
id
,
FrameNumber
:
3
,
IsLast
:
true
},
{
ID
:
id
,
FrameNumber
:
5
,
IsLast
:
true
}},
errors
:
false
,
errors
:
false
,
output
:
"00deadbeefdeadbeefdeadbeefdeadbeef00000000000000deadbeefdeadbeefdeadbeefdeadbeef00020000000000"
,
output
:
"00deadbeefdeadbeefdeadbeefdeadbeef00000000000000deadbeefdeadbeefdeadbeefdeadbeef00020000000000"
,
},
},
...
...
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