Skip to content

Conversation

@rustopian
Copy link
Contributor

@rustopian rustopian commented May 5, 2025

Adds SlotHashes sysvar support. Checked and unchecked zero-copy paths are both included. Intended to replace 121.

Binary search is used, but zerocopy Iterator and copy fetch / fetch_into / fetch_into_unchecked are also implemented for those with different SlotHashes access needs.

Comment on lines 71 to 79
// Reject oversized entry counts to prevent surprises.
if num_entries > MAX_ENTRIES {
return Err(ProgramError::InvalidArgument);
}

let required_len = NUM_ENTRIES_SIZE + num_entries * ENTRY_SIZE;
if buffer.len() < required_len {
return Err(ProgramError::InvalidArgument);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure the need for this checks. I would assume that the syscall did the right thing, so num_entries would never be greater than MAX_ENTRIES and if the length was invalid, the syscall would fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed num_entries > MAX_ENTRIES check in 551b0f9

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need the if buffer.len() < required_le check? This is after the syscall was called, so if the buffer length was invalid, the syscall would have failed.

Copy link
Contributor Author

@rustopian rustopian Jul 26, 2025

Choose a reason for hiding this comment

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

Removed. More importantly, as I double-checked the context here, I saw that cases involving offset would happily return an incorrect number of entries to the caller (reading slot number data as a num_entries header).

fetch_into and validate_buffer_size (now named validate_and_get_buffer_capacity) have been rewritten to fix this, plus some test updates and a new test test_fetch_into_offset_avoids_incorrect_entry_count

Copy link
Collaborator

@febo febo left a comment

Choose a reason for hiding this comment

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

Looks great, just very minor things.

@rustopian rustopian force-pushed the rustopian/slot-hashes-sysvar branch from 12ce68d to 99eb7da Compare July 25, 2025 10:51
@rustopian rustopian enabled auto-merge (squash) July 25, 2025 11:31
@rustopian rustopian requested a review from febo July 25, 2025 11:31
@rustopian
Copy link
Contributor Author

Looks great, just very minor things.

Minor things addressed (and hunspell satisfied).

@rustopian rustopian force-pushed the rustopian/slot-hashes-sysvar branch from 6b6aca4 to 6ed4829 Compare July 26, 2025 10:22
@rustopian rustopian force-pushed the rustopian/slot-hashes-sysvar branch from 6ed4829 to 1d9cab0 Compare July 26, 2025 11:23
@zakajd
Copy link

zakajd commented Aug 8, 2025

Still hoping this will be merged... It looks done, does @febo need to review this one last time before merging?

Copy link
Collaborator

@febo febo left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@rustopian rustopian merged commit 7c40b9d into anza-xyz:main Aug 9, 2025
10 checks passed
@rustopian
Copy link
Contributor Author

rustopian commented Aug 9, 2025

Still hoping this will be merged... It looks done, does @febo need to review this one last time before merging?

Got your wish, it's in! (thanks febo)

@rustopian rustopian deleted the rustopian/slot-hashes-sysvar branch November 11, 2025 10:22
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