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

Simplify check for data Rc in account info data and improve tesing #4046

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

seanyoung
Copy link

sol_invoke_signed_rust() takes an slice of AccountInfo. The account data field is defined as a Rc<RefCell<&mut [u8]>. This means that the AccountInfo struct holds a single pointer for the data field, which points to a struct containing:

  • Rc fields for strong and weak reference count
  • borrow count field for the RefCell
  • a pointer and length for the &[u8] slice

account_info.data.as_ptr() gives as the pointer to the data field of the Rc<RefCell<>> struct, not the data pointer itself; it's the data of the RefCell.

The check for the offset of the length field is therefore redundant and therefore removed.

Also improve the test which show UB without the checks we added in #3471

sol_invoke_signed_rust() takes an slice of AccountInfo. The account
data field is defined as a Rc<RefCell<&mut [u8]>. This means that the
AccountInfo struct holds a single pointer for the data field, which
points to a struct containing:

 - Rc fields for strong and weak reference count
 - borrow count field for the RefCell
 - a pointer and length for the &[u8] slice

account_info.data.as_ptr() gives as the pointer to the data field
of the Rc<RefCell<>> struct, not the data pointer itself; it's the data
of the RefCell.

The check for the offset of the length field is therefore redundant and
therefore removed.

Also improve the test which show UB without the checks.
Copy link

mergify bot commented Dec 10, 2024

The Firedancer team maintains a line-for-line reimplementation of the
native programs, and until native programs are moved to BPF, those
implementations must exactly match their Agave counterparts.
If this PR represents a change to a native program implementation (not
tests), please include a reviewer from the Firedancer team. And please
keep refactors to a minimum.

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.

1 participant