Skip to content

Add agave-precompiles crate#5509

Merged
jstarry merged 10 commits intoanza-xyz:masterfrom
jstarry:agave-precompiles
Mar 27, 2025
Merged

Add agave-precompiles crate#5509
jstarry merged 10 commits intoanza-xyz:masterfrom
jstarry:agave-precompiles

Conversation

@jstarry
Copy link
Copy Markdown

@jstarry jstarry commented Mar 26, 2025

Problem

Precompile verification is subject to runtime feature gates and should live in the agave monorepo rather than creating a circular dependency between agave and the sdk repos.

Summary of Changes

  • Pull in precompile definitions and the verification code from all 3 precompiles

Everything from sdk that was pulled into agave in this PR will get deprecated in the sdk crates

Fixes #

@jstarry jstarry requested a review from a team as a code owner March 26, 2025 18:44
@mergify
Copy link
Copy Markdown

mergify Bot commented Mar 26, 2025

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.

@jstarry jstarry requested a review from t-nelson March 26, 2025 19:00
@t-nelson t-nelson requested a review from joncinque March 26, 2025 19:21
Copy link
Copy Markdown

@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 great to me overall! Note that I mostly skimmed the verify functions and tests. Just some small questions.

Also, there are two other places in agave that still use precompiles from the sdk that should get updated to use agave-precompiles instead:

I was worried that this would be much worse, but thankfully there aren't any users of Transaction::verify_precompiles, so we can also deprecate that safely.

Finally, what's the plan for feature set usage in reserved-account-keys? Is the idea to refactor the one usage of it into the runtime? Thankfully, I only see one use at

reserved_keys.update_active_set(&self.feature_set);

Comment thread svm/Cargo.toml Outdated
Comment thread programs/bpf_loader/Cargo.toml Outdated
Comment thread precompiles/src/lib.rs
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
use {
lazy_static::lazy_static,
solana_feature_set::{enable_secp256r1_precompile, FeatureSet},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just to make sure, this will use agave-feature-set in a future PR, correct?

Comment thread precompiles/Cargo.toml Outdated
solana-precompile-error = { workspace = true }
solana-pubkey = { workspace = true }
solana-sdk-ids = { workspace = true }
solana-secp256k1-program = { workspace = true, features = ["bincode"] }
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is the bincode feature required on this dep? I couldn't find any parts of the code that were using stuff gated by it. It'll probably need serde though to ser/de the offsets

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yup turns out it is:

error[E0277]: the trait bound `SecpSignatureOffsets: serde::de::Deserialize<'_>` is not satisfied
  | --> precompiles/src/secp256k1.rs:51:45
  | \|
  | 51  \|         let offsets: SecpSignatureOffsets = bincode::deserialize(&data[start..end])
  | \|                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `serde::de::Deserialize<'_>` is not implemented for `SecpSignatureOffsets`
  |  

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry, what I meant is just changing it to features = ["serde"]. I tested that locally and it works, since there's nothing required from the "bincode" feature (and bincode enables serde)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You don't have to be sorry that I'm dumb lol

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed, thanks! 0392e6b

Comment on lines +109 to +127
fn get_data_slice<'a>(
instruction_datas: &'a [&[u8]],
instruction_index: u8,
offset_start: u16,
size: usize,
) -> Result<&'a [u8], PrecompileError> {
let signature_index = instruction_index as usize;
if signature_index >= instruction_datas.len() {
return Err(PrecompileError::InvalidDataOffsets);
}
let signature_instruction = &instruction_datas[signature_index];
let start = offset_start as usize;
let end = start.saturating_add(size);
if end > signature_instruction.len() {
return Err(PrecompileError::InvalidSignature);
}

Ok(&instruction_datas[signature_index][start..end])
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nothing to do here, but it's a bit baffling that the behavior of this isn't exactly the same between the precompiles

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nothing to do here, but it's a bit baffling that the behavior of this isn't exactly the same between the precompiles

don't look too closely at each of their "offsets" structs

Comment thread program-runtime/Cargo.toml Outdated
@jstarry
Copy link
Copy Markdown
Author

jstarry commented Mar 26, 2025

Finally, what's the plan for feature set usage in reserved-account-keys? Is the idea to refactor the one usage of it into the runtime? Thankfully, I only see one use at

I gave it a similar treatment here: #5513

It seems useful to have it be a separate crate for now.

t-nelson
t-nelson previously approved these changes Mar 26, 2025
Copy link
Copy Markdown

@t-nelson t-nelson left a comment

Choose a reason for hiding this comment

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

disaster averted! 🎉

joncinque
joncinque previously approved these changes Mar 26, 2025
Copy link
Copy Markdown

@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 to me, up to you if you want to downgrade that feature now or in future work. It's a mostly pedantic point since that feature's likely to get enabled by another user of the crate.

@jstarry jstarry dismissed stale reviews from joncinque and t-nelson via 0392e6b March 26, 2025 21:34
@jstarry jstarry requested a review from joncinque March 26, 2025 21:35
joncinque
joncinque previously approved these changes Mar 26, 2025
Copy link
Copy Markdown

@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.

Thanks!

@jstarry jstarry added automerge automerge Merge this Pull Request automatically once CI passes v2.2 labels Mar 26, 2025
@mergify
Copy link
Copy Markdown

mergify Bot commented Mar 26, 2025

Backports to the beta branch are to be avoided unless absolutely necessary for fixing bugs, security issues, and perf regressions. Changes intended for backport should be structured such that a minimum effective diff can be committed separately from any refactoring, plumbing, cleanup, etc that are not strictly necessary to achieve the goal. Any of the latter should go only into master and ride the normal stabilization schedule. Exceptions include CI/metrics changes, CLI improvements and documentation updates on a case by case basis.

@mergify
Copy link
Copy Markdown

mergify Bot commented Mar 26, 2025

automerge label removed due to a CI failure

@mergify mergify Bot removed the automerge automerge Merge this Pull Request automatically once CI passes label Mar 26, 2025
@pgarg66
Copy link
Copy Markdown

pgarg66 commented Mar 26, 2025

This will add a dependency in SVM code to monorepo.
@t-nelson, @jstarry Any thoughts on how to resolve that once we split SVM to its own repo?

  1. Should we move this along with SVM? Since the reason to move it here is runtime features.
  2. Add a callback in SVM code to lookup precompiles?

@jstarry
Copy link
Copy Markdown
Author

jstarry commented Mar 26, 2025

@pgarg66 I think regardless of this dependency change the SVM is going to have to figure out a reasonable interface for dealing with precompiles before it gets migrated out, this PR doesn't really change that fact. Happy to discuss approaches in a new issue.

pgarg66
pgarg66 previously approved these changes Mar 26, 2025
@jstarry
Copy link
Copy Markdown
Author

jstarry commented Mar 26, 2025

Just pushed changes:

  • I rebased to fix conflicts with the merged agave-reserved-account-keys PR
  • Updated the precompiles tests to NOT use Transaction::verify_precompiles: 58f7b3a
  • Fixed a clippy warning that showed up locally: 43e8ae7

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 26, 2025

Codecov Report

❌ Patch coverage is 97.13542% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.4%. Comparing base (df2d3d8) to head (3ef35c5).
⚠️ Report is 3816 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##           master    #5509     +/-   ##
=========================================
  Coverage    83.3%    83.4%             
=========================================
  Files         823      827      +4     
  Lines      372396   373548   +1152     
=========================================
+ Hits       310512   311606   +1094     
- Misses      61884    61942     +58     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jstarry jstarry merged commit e1162f7 into anza-xyz:master Mar 27, 2025
58 checks passed
@jstarry jstarry deleted the agave-precompiles branch March 27, 2025 00:33
mergify Bot pushed a commit that referenced this pull request Mar 27, 2025
(cherry picked from commit e1162f7)

# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	program-runtime/Cargo.toml
#	programs/bpf_loader/src/syscalls/mod.rs
#	programs/sbf/Cargo.lock
#	runtime/Cargo.toml
#	runtime/src/bank.rs
#	svm/examples/Cargo.lock
jstarry added a commit that referenced this pull request Mar 27, 2025
t-nelson pushed a commit that referenced this pull request Mar 27, 2025
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.

5 participants