Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

op-node: Fix Frame parsing #4867

Merged
merged 7 commits into from
Feb 15, 2023
Merged

op-node: Fix Frame parsing #4867

merged 7 commits into from
Feb 15, 2023

Conversation

sebastianst
Copy link
Member

@sebastianst sebastianst commented Feb 13, 2023

Description

This PR fixes the binary-unmarshaling of Frames. The last byte of an encoded frame could be missing and would still have passed as a valid frame.

Function Frame.UnmarshalBinary now does proper error checks to ensure all frame data is present in an encoded frame. It also converts io.EOF errors that happen intermediately into io.ErrUnexpectedEOF errors, which is more idiomatic.

Tests

Added:

  • Happy marshaling followed by unmarshaling of random frames.
  • Failing unmarshaling of frames with an invalid value for last byte is_last.
  • Failing unmarshaling of frames truncated at various positions.
  • Failing ParseFrames for truncated last frame.

Metadata

@changeset-bot
Copy link

changeset-bot bot commented Feb 13, 2023

⚠️ No Changeset found

Latest commit: 0f8c7ce

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@sebastianst
Copy link
Member Author

Is it worth making randomFrame public in the testutils package?

@tynes
Copy link
Contributor

tynes commented Feb 14, 2023

Is it worth making randomFrame public in the testutils package?

Definitely think this is a good idea to reduce code duplication!

@sebastianst sebastianst changed the title Fix Frame parsing op-node: Fix Frame parsing Feb 14, 2023
@sebastianst sebastianst marked this pull request as ready for review February 14, 2023 18:36
@sebastianst
Copy link
Member Author

Is it worth making randomFrame public in the testutils package?

Definitely think this is a good idea to reduce code duplication!

It would definitely be nice, but looking at the testutils package, the scope of its random functions are limited to general Ethereum types, not Optimism types. So if we wanted to make randomFrame public, maybe it would be cleaner to move it into a package like op-node/rollup/derive/test. (It's a general pattern I've been using in the past: instead of putting many test utils into a single large package, create many test sub-packages and put relevant testing tools there. This can help with dependency conflicts in tests down the line.)

Is there any other place in the code where random frames would be used, except for the tests I added here?

@codecov
Copy link

codecov bot commented Feb 14, 2023

Codecov Report

Merging #4867 (0f8c7ce) into develop (1e780a3) will decrease coverage by 4.00%.
The diff coverage is 95.23%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4867      +/-   ##
===========================================
- Coverage    39.89%   35.90%   -4.00%     
===========================================
  Files          307      181     -126     
  Lines        18590    15359    -3231     
  Branches       761        0     -761     
===========================================
- Hits          7417     5514    -1903     
+ Misses       10597     9273    -1324     
+ Partials       576      572       -4     
Flag Coverage Δ
bedrock-go-tests 35.90% <95.23%> (+1.20%) ⬆️
contracts-bedrock-tests ?
contracts-tests ?
core-utils-tests ?
dtl-tests ?
fault-detector-tests ?
sdk-tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
op-node/rollup/derive/frame.go 66.25% <93.75%> (+66.25%) ⬆️
op-node/testutils/random.go 88.46% <100.00%> (+0.32%) ⬆️
packages/sdk/src/utils/message-utils.ts
...ackages/contracts-bedrock/contracts/L2/L1Block.sol
...contracts-bedrock/contracts/libraries/Encoding.sol
...cts/contracts/L2/predeploys/OVM_GasPriceOracle.sol
...cts/contracts/libraries/utils/Lib_Bytes32Utils.sol
packages/core-utils/src/external/ethers/index.ts
packages/core-utils/src/common/test-utils.ts
.../contracts/L1/messaging/L1CrossDomainMessenger.sol
... and 152 more

Copy link
Contributor

@trianglesphere trianglesphere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love seeing more tests

op-node/rollup/derive/frame_test.go Outdated Show resolved Hide resolved
@mergify
Copy link
Contributor

mergify bot commented Feb 15, 2023

This PR has been added to the merge queue, and will be merged soon.

@mergify
Copy link
Contributor

mergify bot commented Feb 15, 2023

This PR is next in line to be merged, and will be merged as soon as checks pass.

@mergify mergify bot merged commit a65ceee into develop Feb 15, 2023
@mergify mergify bot deleted the seb/fix-frame-parsing branch February 15, 2023 16:28
@mergify mergify bot removed the on-merge-train label Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants