Add agave-precompiles crate#5509
Conversation
|
The Firedancer team maintains a line-for-line reimplementation of the |
joncinque
left a comment
There was a problem hiding this comment.
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:
Line 136 in 108fcb4
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
Line 6466 in 108fcb4
| #![cfg_attr(docsrs, feature(doc_auto_cfg))] | ||
| use { | ||
| lazy_static::lazy_static, | ||
| solana_feature_set::{enable_secp256r1_precompile, FeatureSet}, |
There was a problem hiding this comment.
Just to make sure, this will use agave-feature-set in a future PR, correct?
| solana-precompile-error = { workspace = true } | ||
| solana-pubkey = { workspace = true } | ||
| solana-sdk-ids = { workspace = true } | ||
| solana-secp256k1-program = { workspace = true, features = ["bincode"] } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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`
|
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
You don't have to be sorry that I'm dumb lol
| 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]) | ||
| } |
There was a problem hiding this comment.
Nothing to do here, but it's a bit baffling that the behavior of this isn't exactly the same between the precompiles
There was a problem hiding this comment.
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
1e1faec to
83c2c98
Compare
I gave it a similar treatment here: #5513 It seems useful to have it be a separate crate for now. |
joncinque
left a comment
There was a problem hiding this comment.
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.
|
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. |
|
automerge label removed due to a CI failure |
|
@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. |
0392e6b to
255b759
Compare
Codecov Report❌ Patch coverage is 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:
|
(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
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
Everything from sdk that was pulled into agave in this PR will get deprecated in the sdk crates
Fixes #