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

Program: add custom error codes for readonly writes #43

Merged
merged 3 commits into from
Nov 9, 2024

Conversation

buffalojoec
Copy link
Contributor

Problem

Working more with the Firedancer conformance harness, yet another inconsequential mismatch between the BPF version and its original builtin version has popped up.

When a builtin program attempts to write to an executable or read-only account, it will be immediately rejected by the TransactionContext. However, BPF programs do not query the TransactionContext for the ability to perform a write. Instead, they perform writes at-will, and the loader will inspect the serialized account memory region for any account update violations after the VM has completed execution.

The loader's inspection will catch any unauthorized modifications, however, when the exact same data is written to the account, thus rendering the serialized account state unchanged, the program succeeds.

Summary of Changes

In order to maximize backwards compatibility between the BPF version and its original builtin, we add these checks from TransactionContext to the program directly, to throw even when the data being written is the same as what's currently in the account.

Unfortunately, the two InstructionError variants thrown do not have ProgramError counterparts, so we mock them out with custom error codes.

@buffalojoec

This comment was marked as resolved.

@buffalojoec buffalojoec changed the title Program: add custom error codes for executable, readonly writes Program: add custom error codes for readonly writes Nov 8, 2024
Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

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

Looks good! Just the one bit about the error code, but that can get changed later if needed

pub enum AddressLookupTableError {
/// Instruction modified data of a read-only account.
#[error("Instruction modified data of a read-only account")]
ReadonlyDataModified = 10,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason this is 10? The other PR didn't set a number

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, accidentally removed my comment, but it's to avoid collisions with the custom errors from System program.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the comment back!

@buffalojoec buffalojoec merged commit 8be62dd into main Nov 9, 2024
3 checks passed
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.

2 participants