perf: use solana hash precompile (#1400)
This commit is contained in:
parent
df585e440e
commit
0e6484daca
|
@ -13,6 +13,7 @@ name = "pythnet_sdk"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
test-utils = ["dep:wormhole-vaas-serde", "dep:serde_wormhole", "dep:libsecp256k1", "dep:rand"]
|
test-utils = ["dep:wormhole-vaas-serde", "dep:serde_wormhole", "dep:libsecp256k1", "dep:rand"]
|
||||||
|
solana-program = ["dep:solana-program"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bincode = "1.3.1"
|
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}
|
wormhole-vaas-serde = {version = "0.1.0", optional = true}
|
||||||
libsecp256k1 = {version ="0.7.1", optional = true}
|
libsecp256k1 = {version ="0.7.1", optional = true}
|
||||||
rand = {version = "0.8.5", optional = true}
|
rand = {version = "0.8.5", optional = true}
|
||||||
|
solana-program = {version = ">=1.13.6", optional = true}
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
base64 = "0.21.0"
|
base64 = "0.21.0"
|
||||||
|
|
|
@ -1,18 +1,31 @@
|
||||||
|
#[cfg(not(feature = "solana-program"))]
|
||||||
|
use sha3::{
|
||||||
|
Digest,
|
||||||
|
Keccak256,
|
||||||
|
};
|
||||||
|
#[cfg(feature = "solana-program")]
|
||||||
|
use solana_program::keccak::hashv;
|
||||||
use {
|
use {
|
||||||
crate::hashers::Hasher,
|
crate::hashers::Hasher,
|
||||||
serde::Serialize,
|
serde::Serialize,
|
||||||
sha3::{
|
|
||||||
Digest,
|
|
||||||
Keccak256,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Default, Debug, Eq, Hash, PartialEq, Serialize)]
|
#[derive(Clone, Default, Debug, Eq, Hash, PartialEq, Serialize)]
|
||||||
pub struct Keccak160 {}
|
pub struct Keccak160 {}
|
||||||
|
|
||||||
impl Hasher for Keccak160 {
|
impl Hasher for Keccak160 {
|
||||||
type Hash = [u8; 20];
|
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] {
|
fn hashv(data: &[impl AsRef<[u8]>]) -> [u8; 20] {
|
||||||
let mut hasher = Keccak256::new();
|
let mut hasher = Keccak256::new();
|
||||||
data.iter().for_each(|d| hasher.update(d));
|
data.iter().for_each(|d| hasher.update(d));
|
||||||
|
|
|
@ -3095,6 +3095,7 @@ dependencies = [
|
||||||
"serde_wormhole",
|
"serde_wormhole",
|
||||||
"sha3 0.10.6",
|
"sha3 0.10.6",
|
||||||
"slow_primes",
|
"slow_primes",
|
||||||
|
"solana-program",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"wormhole-vaas-serde",
|
"wormhole-vaas-serde",
|
||||||
]
|
]
|
||||||
|
|
|
@ -17,7 +17,7 @@ test-bpf = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anchor-lang = { workspace = true }
|
anchor-lang = { workspace = true }
|
||||||
pythnet-sdk = { path = "../../../../pythnet/pythnet_sdk" }
|
pythnet-sdk = { path = "../../../../pythnet/pythnet_sdk", features = ["solana-program"] }
|
||||||
solana-program = { workspace = true }
|
solana-program = { workspace = true }
|
||||||
byteorder = "1.4.3"
|
byteorder = "1.4.3"
|
||||||
wormhole-core-bridge-solana = {workspace = true}
|
wormhole-core-bridge-solana = {workspace = true}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
/**
|
/**
|
||||||
* A hard-coded budget for the compute units required for the `verifyEncodedVaa` instruction in the Wormhole program.
|
* 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.
|
* 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.
|
* 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;
|
||||||
|
|
Loading…
Reference in New Issue