Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,802 changes: 515 additions & 2,287 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions pythnet/pythnet_sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pythnet-sdk"
version = "2.3.1"
version = "2.3.2"
description = "Pyth Runtime for Solana"
authors = ["Pyth Data Association"]
repository = "https://github.com/pyth-network/pythnet"
Expand All @@ -13,11 +13,12 @@ name = "pythnet_sdk"

[features]
test-utils = ["dep:wormhole-vaas-serde", "dep:serde_wormhole", "dep:libsecp256k1", "dep:rand"]
solana-program = ["dep:solana-program", "dep:anchor-lang"]
solana-program = ["dep:anchor-lang"]
idl-build = ["solana-program", "anchor-lang/idl-build"]

[dependencies]
bincode = "1.3.1"
borsh = "0.10.3"
borsh = "1.6.1"
bytemuck = { version = "1.11.0", features = ["derive"] }
byteorder = "1.4.3"
fast-math = "0.1"
Expand All @@ -28,14 +29,11 @@ quickcheck = { version = "1", optional = true}
sha3 = "0.10.4"
slow_primes = "0.1.14"
thiserror = "1.0.40"
pyth-sdk = { version = "0.5.0" }

serde_wormhole = {version ="0.1.0", optional = true}
wormhole-vaas-serde = {version = "0.1.0", optional = true}
libsecp256k1 = {version ="0.7.1", optional = true}
rand = {version = "0.8.5", optional = true}
solana-program = {version = ">=1.13.6", optional = true}
anchor-lang = {version = ">=0.28.0", optional = true}
anchor-lang = {version = "1.0.2", optional = true}

[dev-dependencies]
base64 = "0.21.0"
Expand Down
2 changes: 1 addition & 1 deletion pythnet/pythnet_sdk/src/accumulators/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub struct MerkleTree<H: Hasher = Keccak256> {
pub root: MerkleRoot<H>,

#[serde(skip)]
#[borsh_skip]
#[borsh(skip)]
pub nodes: Vec<H::Hash>,
}

Expand Down
12 changes: 0 additions & 12 deletions pythnet/pythnet_sdk/src/hashers/keccak256_160.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#[cfg(not(feature = "solana-program"))]
use sha3::{Digest, Keccak256};
#[cfg(feature = "solana-program")]
use solana_program::keccak::hashv;
use {crate::hashers::Hasher, serde::Serialize};

#[derive(Clone, Default, Debug, Eq, Hash, PartialEq, Serialize)]
Expand All @@ -10,15 +7,6 @@ pub struct Keccak160 {}
impl Hasher for Keccak160 {
type Hash = [u8; 20];

#[cfg(feature = "solana-program")]
fn hashv(data: &[impl AsRef<[u8]>]) -> Self::Hash {
let bytes = hashv(&data.iter().map(|x| x.as_ref()).collect::<Vec<&[u8]>>());
let mut hash = [0u8; 20];
hash.copy_from_slice(&bytes.as_ref()[0..20]);
hash
}

#[cfg(not(feature = "solana-program"))]
fn hashv(data: &[impl AsRef<[u8]>]) -> [u8; 20] {
let mut hasher = Keccak256::new();
data.iter().for_each(|d| hasher.update(d));
Comment on lines 7 to 12

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔴 Removal of on-chain keccak syscall causes significant compute unit regression

The solana-program feature-gated implementation of Keccak160::hashv that used solana_program::keccak::hashv (a cheap syscall at ~100 CU) was removed. Now all on-chain merkle proof verifications use the sha3 crate's software implementation, which costs thousands of CU per hash. Since pyth-solana-receiver uses pythnet-sdk with features = ["solana-program"] and calls root.check() in verify_merkle_proof (target_chains/solana/programs/pyth-solana-receiver/src/lib.rs), each price update verification requires ~10-20 hash operations. The CU increase from ~2k total (syscall) to ~50k-200k (software) could push transactions over compute budget limits for existing integrations.

(Refers to lines 1-18)

Prompt for agents
The file keccak256_160.rs previously had a feature-gated implementation that used solana_program::keccak::hashv when the solana-program feature was enabled. This syscall is significantly cheaper on-chain (~100 CU vs thousands of CU for software keccak). Since anchor-lang 1.0.2 re-exports solana_program, the syscall is still accessible via anchor_lang::solana_program::keccak::hashv. The fix should restore the conditional compilation: when the solana-program feature is enabled, use the syscall for on-chain efficiency; otherwise fall back to the sha3 crate implementation. The cfg attributes should check for the solana-program feature and import from anchor_lang::solana_program::keccak::hashv.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Expand Down
2 changes: 0 additions & 2 deletions pythnet/pythnet_sdk/src/legacy/mod.rs

This file was deleted.

Loading