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

Check lastPreimage != nil before accessing the cached preimage #114

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mininny
Copy link
Collaborator

@mininny mininny commented Jan 7, 2025

Description

The Fast VM implementation assumes the last preimage read has been cached, even if this is the first read. Moreover, the preimage key is always initialized to zeroes ([32]byte{}) while the cached preimage value is initialized to a null pointer.

That means if either there's an attempt to read the preimage value before writing a key, or if the key written is zero, an attempt to access the null pointer will cause a panic.

Neither scenario should happen in a correct Kona implementation -- reads should always be preceded by writing the corresponding key, and a key with zero value isn't valid. However this is the oracle's concern and should be delegated to it.

@codecov-commenter
Copy link

codecov-commenter commented Jan 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.89%. Comparing base (8ff9318) to head (1203fc4).
Report is 25 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #114   +/-   ##
=======================================
  Coverage   61.89%   61.89%           
=======================================
  Files          27       27           
  Lines        4091     4091           
=======================================
  Hits         2532     2532           
  Misses       1427     1427           
  Partials      132      132           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mininny mininny added the Audit finding grouping for our audit findings label Jan 7, 2025
@mininny mininny requested a review from refcell January 7, 2025 05:02
if key != m.lastPreimageKey {
if preimage == nil || key != m.lastPreimageKey {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this is right - cannon doesn't perform this check - see here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, this is normally not needed, but the reviewers pointed out that this can result in NPE if a preimage read is not preceded with preimage write - just in case the client program misbehaves.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also added a test here: 1203fc4 so that we can check the regression

@mininny mininny requested a review from refcell January 9, 2025 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Audit finding grouping for our audit findings
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants