perf: use solana hash precompile (#1400)

This commit is contained in:
guibescos 2024-03-27 15:39:43 +00:00 committed by GitHub
parent df585e440e
commit 0e6484daca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 24 additions and 8 deletions

View File

@ -13,6 +13,7 @@ name = "pythnet_sdk"
[features]
test-utils = ["dep:wormhole-vaas-serde", "dep:serde_wormhole", "dep:libsecp256k1", "dep:rand"]
solana-program = ["dep:solana-program"]
[dependencies]
bincode = "1.3.1"
@ -31,6 +32,7 @@ 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}
[dev-dependencies]
base64 = "0.21.0"

View File

@ -1,18 +1,31 @@
#[cfg(not(feature = "solana-program"))]
use sha3::{
Digest,
Keccak256,
};
#[cfg(feature = "solana-program")]
use solana_program::keccak::hashv;
use {
crate::hashers::Hasher,
serde::Serialize,
sha3::{
Digest,
Keccak256,
},
};
#[derive(Clone, Default, Debug, Eq, Hash, PartialEq, Serialize)]
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));

View File

@ -3095,6 +3095,7 @@ dependencies = [
"serde_wormhole",
"sha3 0.10.6",
"slow_primes",
"solana-program",
"thiserror",
"wormhole-vaas-serde",
]

View File

@ -17,7 +17,7 @@ test-bpf = []
[dependencies]
anchor-lang = { workspace = true }
pythnet-sdk = { path = "../../../../pythnet/pythnet_sdk" }
pythnet-sdk = { path = "../../../../pythnet/pythnet_sdk", features = ["solana-program"] }
solana-program = { workspace = true }
byteorder = "1.4.3"
wormhole-core-bridge-solana = {workspace = true}

View File

@ -1,12 +1,12 @@
/**
* A hard-coded budget for the compute units required for the `verifyEncodedVaa` instruction in the Wormhole program.
*/
export const VERIFY_ENCODED_VAA_COMPUTE_BUDGET = 400000;
export const VERIFY_ENCODED_VAA_COMPUTE_BUDGET = 350000;
/**
* A hard-coded budget for the compute units required for the `postUpdateAtomic` instruction in the Pyth Solana Receiver program.
*/
export const POST_UPDATE_ATOMIC_COMPUTE_BUDGET = 400000;
export const POST_UPDATE_ATOMIC_COMPUTE_BUDGET = 170000;
/**
* A hard-coded budget for the compute units required for the `postUpdate` instruction in the Pyth Solana Receiver program.
*/
export const POST_UPDATE_COMPUTE_BUDGET = 200000;
export const POST_UPDATE_COMPUTE_BUDGET = 35000;