From 03af7519e1ca7a29ed2ee25c2cd6b31e0d4e99fd Mon Sep 17 00:00:00 2001 From: "Frank V. Castellucci" Date: Tue, 11 May 2021 06:04:40 -0400 Subject: [PATCH] Updated for review comments --- programs/bpf_loader/Cargo.toml | 7 +- programs/bpf_loader/src/syscalls.rs | 88 ++++++------- sdk/program/src/bignum.rs | 197 +++++++++++++++++++--------- 3 files changed, 180 insertions(+), 112 deletions(-) diff --git a/programs/bpf_loader/Cargo.toml b/programs/bpf_loader/Cargo.toml index 9bf99839155a2b..8e09fb1f82e8c5 100644 --- a/programs/bpf_loader/Cargo.toml +++ b/programs/bpf_loader/Cargo.toml @@ -11,19 +11,20 @@ edition = "2018" [dependencies] bincode = "1.3.1" +blake3 = "0.3.7" byteorder = "1.3.4" +hkdf = "0.11.0" log = "0.4.11" num-derive = "0.3" num-traits = "0.2" +openssl = "0.10.32" rand_core = "0.6.2" solana-measure = { path = "../../measure", version = "=1.7.0" } solana-runtime = { path = "../../runtime", version = "=1.7.0" } solana-sdk = { path = "../../sdk", version = "=1.7.0" } solana_rbpf = "=0.2.8" thiserror = "1.0" -hkdf = "0.11.0" -blake3 = "0.3.7" -openssl = "0.10.32" + [dev-dependencies] rand = "0.7.3" diff --git a/programs/bpf_loader/src/syscalls.rs b/programs/bpf_loader/src/syscalls.rs index 8bae832f7bc702..0cc1bba350659e 100644 --- a/programs/bpf_loader/src/syscalls.rs +++ b/programs/bpf_loader/src/syscalls.rs @@ -1162,7 +1162,7 @@ macro_rules! calc_bignum_cost { } /// BIGNUM sol_bignum_new -pub struct SyscallBigNumNew<'a> { +struct SyscallBigNumNew<'a> { cost: u64, compute_meter: Rc>, loader_id: &'a Pubkey, @@ -1178,6 +1178,8 @@ impl<'a> SyscallObject for SyscallBigNumNew<'a> { memory_mapping: &MemoryMapping, result: &mut Result>, ) { + question_mark!(self.compute_meter.consume(self.cost), result); + let big_number = question_mark!( translate_type_mut::(memory_mapping, bn_addr, self.loader_id, true), result @@ -1186,12 +1188,11 @@ impl<'a> SyscallObject for SyscallBigNumNew<'a> { let rwptr = Box::into_raw(bbox); let bignum_ptr = rwptr as u64; *big_number = bignum_ptr; - question_mark!(self.compute_meter.consume(self.cost), result); *result = Ok(0) } } -pub struct SyscallBigNumFromU32<'a> { +struct SyscallBigNumFromU32<'a> { cost: u64, compute_meter: Rc>, loader_id: &'a Pubkey, @@ -1213,18 +1214,18 @@ impl<'a> SyscallObject for SyscallBigNumFromU32<'a> { ); let bbox = Box::new(BigNum::from_u32(u32_val as u32).unwrap()); let bytes = bbox.num_bytes() as f64; - let rwptr = Box::into_raw(bbox); - let bignum_ptr = rwptr as u64; - *big_number = bignum_ptr; question_mark!( self.compute_meter .consume(self.cost + calc_bignum_cost!(bytes)), result ); + let rwptr = Box::into_raw(bbox); + let bignum_ptr = rwptr as u64; + *big_number = bignum_ptr; *result = Ok(0) } } -pub struct SyscallBigNumFromBytes<'a> { +struct SyscallBigNumFromBytes<'a> { cost: u64, compute_meter: Rc>, loader_id: &'a Pubkey, @@ -1249,19 +1250,19 @@ impl<'a> SyscallObject for SyscallBigNumFromBytes<'a> { result ); let bytes: f64 = byte_slice.len() as f64; - let bbox = Box::new(BigNum::from_slice(byte_slice).unwrap()); - let rwptr = Box::into_raw(bbox); - let bignum_ptr = rwptr as u64; - *big_number = bignum_ptr; question_mark!( self.compute_meter .consume(self.cost + calc_bignum_cost!(bytes)), result ); + let bbox = Box::new(BigNum::from_slice(byte_slice).unwrap()); + let rwptr = Box::into_raw(bbox); + let bignum_ptr = rwptr as u64; + *big_number = bignum_ptr; *result = Ok(0) } } -pub struct SyscallBigNumToBytes<'a> { +struct SyscallBigNumToBytes<'a> { cost: u64, compute_meter: Rc>, loader_id: &'a Pubkey, @@ -1292,23 +1293,23 @@ impl<'a> SyscallObject for SyscallBigNumToBytes<'a> { let bn_self = unsafe { &*(*self_bignum_address as *mut BigNum) }; let bn_bytes = bn_self.as_ref().to_vec(); let bytes = bn_bytes.len() as f64; + question_mark!( + self.compute_meter + .consume(self.cost + calc_bignum_cost!(bytes)), + result + ); let mut index = 0; for byte in bn_bytes.iter() { bytes_buffer[index] = *byte; index += 1; } *bytes_len = index as u64; - question_mark!( - self.compute_meter - .consume(self.cost + calc_bignum_cost!(bytes)), - result - ); *result = Ok(0) } } /// BIGNUM sol_bignum_mod_exp -pub struct SyscallBigNumModExp<'a> { +struct SyscallBigNumModExp<'a> { cost: u64, compute_meter: Rc>, loader_id: &'a Pubkey, @@ -1346,6 +1347,11 @@ impl<'a> SyscallObject for SyscallBigNumModExp<'a> { let bn_exponent = unsafe { &*(*exponent_bignum_address as *const BigNum) }.as_ref(); let bn_modulus = (unsafe { &*(*modulus_bignum_address as *const BigNum) }).as_ref(); let bytes = (bn_self.num_bytes() + bn_exponent.num_bytes() + bn_modulus.num_bytes()) as f64; + question_mark!( + self.compute_meter + .consume(self.cost + calc_bignum_cost!(bytes)), + result + ); let ctx = &mut BigNumContext::new().unwrap(); match mod_exp_bn.mod_exp(bn_self, bn_exponent, bn_modulus, ctx) { Ok(()) => { @@ -1356,15 +1362,10 @@ impl<'a> SyscallObject for SyscallBigNumModExp<'a> { } Err(_) => *result = Err(SyscallError::BigNumberModExpError.into()), } - question_mark!( - self.compute_meter - .consume(self.cost + calc_bignum_cost!(bytes)), - result - ); } } /// Add BigNums -pub struct SyscallBigNumAdd<'a> { +struct SyscallBigNumAdd<'a> { cost: u64, compute_meter: Rc>, loader_id: &'a Pubkey, @@ -1416,7 +1417,7 @@ impl<'a> SyscallObject for SyscallBigNumAdd<'a> { } /// Subtract BigNums -pub struct SyscallBigNumSub<'a> { +struct SyscallBigNumSub<'a> { cost: u64, compute_meter: Rc>, loader_id: &'a Pubkey, @@ -1466,7 +1467,7 @@ impl<'a> SyscallObject for SyscallBigNumSub<'a> { } } /// Subtract BigNums -pub struct SyscallBigNumMul<'a> { +struct SyscallBigNumMul<'a> { cost: u64, compute_meter: Rc>, loader_id: &'a Pubkey, @@ -1521,7 +1522,7 @@ impl<'a> SyscallObject for SyscallBigNumMul<'a> { }; } } -pub struct SyscallBigNumDiv<'a> { +struct SyscallBigNumDiv<'a> { cost: u64, compute_meter: Rc>, loader_id: &'a Pubkey, @@ -1576,7 +1577,7 @@ impl<'a> SyscallObject for SyscallBigNumDiv<'a> { }; } } -pub struct SyscallBigNumExp<'a> { +struct SyscallBigNumExp<'a> { cost: u64, compute_meter: Rc>, loader_id: &'a Pubkey, @@ -1631,7 +1632,7 @@ impl<'a> SyscallObject for SyscallBigNumExp<'a> { }; } } -pub struct SyscallBigNumSqr<'a> { +struct SyscallBigNumSqr<'a> { cost: u64, compute_meter: Rc>, loader_id: &'a Pubkey, @@ -1676,7 +1677,7 @@ impl<'a> SyscallObject for SyscallBigNumSqr<'a> { }; } } -pub struct SyscallBigNumModSqr<'a> { +struct SyscallBigNumModSqr<'a> { cost: u64, compute_meter: Rc>, loader_id: &'a Pubkey, @@ -1732,7 +1733,7 @@ impl<'a> SyscallObject for SyscallBigNumModSqr<'a> { } } -pub struct SyscallBigNumModMul<'a> { +struct SyscallBigNumModMul<'a> { cost: u64, compute_meter: Rc>, loader_id: &'a Pubkey, @@ -1794,7 +1795,7 @@ impl<'a> SyscallObject for SyscallBigNumModMul<'a> { } } -pub struct SyscallBigNumModInv<'a> { +struct SyscallBigNumModInv<'a> { cost: u64, compute_meter: Rc>, loader_id: &'a Pubkey, @@ -1845,12 +1846,12 @@ impl<'a> SyscallObject for SyscallBigNumModInv<'a> { Err(_e) => { // println!("{}", e); *result = Err(SyscallError::BigNumberModInvError.into()) - }, + } }; } } -pub struct SyscallBigNumHg<'a> { +struct SyscallBigNumHg<'a> { cost: u64, compute_meter: Rc>, loader_id: &'a Pubkey, @@ -1899,10 +1900,6 @@ impl<'a> SyscallObject for SyscallBigNumHg<'a> { result ); - // println!("u:{}",u_bn); - // println!("a:{}",a_bn); - // println!("n:{}",n_bn); - // hash_generator let mut transcript = u_bn.as_ref().to_vec(); transcript.append(&mut a_bn.as_ref().to_vec()); @@ -1931,7 +1928,7 @@ impl<'a> SyscallObject for SyscallBigNumHg<'a> { } } /// BIGNUM sol_bignum_drop -pub struct SyscallBigNumDrop<'a> { +struct SyscallBigNumDrop<'a> { cost: u64, compute_meter: Rc>, loader_id: &'a Pubkey, @@ -1947,19 +1944,19 @@ impl<'a> SyscallObject for SyscallBigNumDrop<'a> { memory_mapping: &MemoryMapping, result: &mut Result>, ) { + question_mark!(self.compute_meter.consume(self.cost), result); let big_number = question_mark!( translate_type_mut::(memory_mapping, bn_addr, self.loader_id, true), result ); drop(unsafe { Box::from_raw(*big_number as *mut BigNum) }); *big_number = 0u64; - question_mark!(self.compute_meter.consume(self.cost), result); *result = Ok(0) } } /// Log BigNum values -pub struct SyscallLogBigNum<'a> { +struct SyscallLogBigNum<'a> { cost: u64, compute_meter: Rc>, logger: Rc>, @@ -1993,7 +1990,7 @@ impl<'a> SyscallObject for SyscallLogBigNum<'a> { } } -pub struct SyscallBlake3Digest<'a> { +struct SyscallBlake3Digest<'a> { cost: u64, compute_meter: Rc>, loader_id: &'a Pubkey, @@ -2052,7 +2049,7 @@ impl<'a> SyscallObject for SyscallBlake3Digest<'a> { } /// Finds a valid prime from hash of u, a, z, nonce -pub struct SyscallBigNumberHashToPrime<'a> { +struct SyscallBigNumberHashToPrime<'a> { cost: u64, compute_meter: Rc>, loader_id: &'a Pubkey, @@ -2122,11 +2119,8 @@ impl<'a> SyscallObject for SyscallBigNumberHashToPrime<'a> { // Only need 256 bits just borrow the bottom 32 bytes // There should be plenty of primes below 2^256 // and we want this to be reasonably fast - //num = BigNumber::from_bytes(&hash[32..]); num = BigNum::from_slice(&hash).unwrap(); if num.is_prime(15, ctx).unwrap() { - // msg!("num_bytes:{:?}",num.to_bytes().to_vec()); - // msg!("i:{}",i); break; } i += 1; @@ -4878,7 +4872,7 @@ mod tests { // println!("(3 * 3) % 7 = {:?}", braw); } #[test] - #[should_panic(expected="UserError(SyscallError(BigNumberModInvError))")] + #[should_panic(expected = "UserError(SyscallError(BigNumberModInvError))")] fn test_syscall_bignum_mod_inv() { let mut mod_inv = 0u64; let mod_inv_addr = &mut mod_inv as *mut _ as u64; diff --git a/sdk/program/src/bignum.rs b/sdk/program/src/bignum.rs index 10dd218d5a1da5..06c4144761e020 100644 --- a/sdk/program/src/bignum.rs +++ b/sdk/program/src/bignum.rs @@ -20,65 +20,6 @@ use std::fmt; pub struct BigNumber(u64); -// Syscall interfaces -#[cfg(target_arch = "bpf")] -extern "C" { - fn sol_bignum_new(bignum_ptr: *mut u64) -> u64; - fn sol_bignum_from_u32(bignum_ptr: *mut u64, val: u64) -> u64; - fn sol_bignum_from_bytes(bignum_ptr: *mut u64, bytes_ptr: *const u64, bytes_len: u64) -> u64; - fn sol_bignum_to_bytes(bignum_ptr: *const u64, bytes_ptr: *mut u8, bytes_len: *mut u64) -> u64; - fn sol_bignum_add(self_ptr: *const u64, rhs_ptr: *const u64, return_ptr: *mut u64) -> u64; - fn sol_bignum_sub(self_ptr: *const u64, rhs_ptr: *const u64, return_ptr: *mut u64) -> u64; - fn sol_bignum_mul(self_ptr: *const u64, rhs_ptr: *const u64, return_ptr: *mut u64) -> u64; - fn sol_bignum_div(self_ptr: *const u64, rhs_ptr: *const u64, return_ptr: *mut u64) -> u64; - fn sol_bignum_sqr(self_ptr: *const u64, bignum_ptr: *mut u64) -> u64; - fn sol_bignum_exp(self_ptr: *const u64, exponent_ptr: *const u64, bignum_ptr: *mut u64) -> u64; - fn sol_bignum_mod_sqr( - self_ptr: *const u64, - modulus_ptr: *const u64, - bignum_ptr: *mut u64, - ) -> u64; - fn sol_bignum_mod_mul( - self_ptr: *const u64, - multiplier_ptr: *const u64, - modulus_ptr: *const u64, - bignum_ptr: *mut u64, - ) -> u64; - fn sol_bignum_mod_inv( - self_ptr: *const u64, - modulus_ptr: *const u64, - bignum_ptr: *mut u64, - ) -> u64; - fn sol_bignum_mod_exp( - bignum_ptr: *mut u64, - self_ptr: *const u64, - exponent_ptr: *const u64, - modulus_ptr: *const u64, - ) -> u64; - fn sol_bignum_hashed_generator( - self_ptr: *const u64, - a: *const u64, - n: *const u64, - nonce: *const u64, - hg_ptr: *mut u64, - ) -> u64; - fn sol_bignum_hash_to_prime( - u: *const u64, - a: *const u64, - z: *const u64, - nonce: *const u64, - htp_ptr: *mut u64, - ) -> u64; - fn sol_log_bignum(bignum_addr: *const u64) -> u64; - fn sol_bignum_drop(bignum_ptr: *mut u64) -> u64; - fn sol_blake3_digest( - data_ptr: *const u8, - data_len: *const u64, - digest_ptr: *mut u8, - digest_len: *mut u64, - ) -> u64; -} - impl BigNumber { /// Returns a BigNumber with initial value of 0 pub fn new() -> Self { @@ -92,6 +33,9 @@ impl BigNumber { } #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_bignum_new(bignum_ptr: *mut u64) -> u64; + } let mut bignum_ptr = 0u64; unsafe { sol_bignum_new(&mut bignum_ptr as *mut _ as *mut u64); @@ -99,6 +43,7 @@ impl BigNumber { BigNumber::from(bignum_ptr) } } + /// Returns a BigNumber with initial value set to a u32 value pub fn from_u32(val: u32) -> Self { #[cfg(not(target_arch = "bpf"))] @@ -111,6 +56,9 @@ impl BigNumber { } #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_bignum_from_u32(bignum_ptr: *mut u64, val: u64) -> u64; + } let mut bignum_ptr = 0u64; unsafe { sol_bignum_from_u32(&mut bignum_ptr as *mut _ as *mut u64, val as u64); @@ -118,6 +66,7 @@ impl BigNumber { BigNumber::from(bignum_ptr) } } + /// Returns a BigNumber with value set to big endian array of bytes pub fn from_bytes(val: &[u8]) -> Self { #[cfg(not(target_arch = "bpf"))] @@ -130,6 +79,13 @@ impl BigNumber { } #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_bignum_from_bytes( + bignum_ptr: *mut u64, + bytes_ptr: *const u64, + bytes_len: u64, + ) -> u64; + } let mut bignum_ptr = 0u64; unsafe { sol_bignum_from_bytes( @@ -141,6 +97,7 @@ impl BigNumber { BigNumber::from(bignum_ptr) } } + /// Returns an array of bytes (big endian) of self pub fn to_bytes(&self) -> Vec { #[cfg(not(target_arch = "bpf"))] @@ -151,6 +108,13 @@ impl BigNumber { } #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_bignum_to_bytes( + bignum_ptr: *const u64, + bytes_ptr: *mut u8, + bytes_len: *mut u64, + ) -> u64; + } let mut my_buffer = [0u8; 256]; let mut my_buffer_len = my_buffer.len(); unsafe { @@ -163,6 +127,7 @@ impl BigNumber { my_buffer[0..my_buffer_len].to_vec() } } + /// Add BigNumbers pub fn add(&self, rhs: &BigNumber) -> Self { #[cfg(not(target_arch = "bpf"))] @@ -173,10 +138,17 @@ impl BigNumber { let rhs_ptr: &BigNum = unsafe { &*(rhs.0 as *const BigNum) }; BigNumRef::checked_add(&mut bbox, my_raw, rhs_ptr).unwrap(); let rwptr = Box::into_raw(bbox); - Self(rwptr as u64) + Self(rwptr as u64) } #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_bignum_add( + self_ptr: *const u64, + rhs_ptr: *const u64, + return_ptr: *mut u64, + ) -> u64; + } let mut bignum_ptr = 0u64; unsafe { sol_bignum_add( @@ -188,6 +160,7 @@ impl BigNumber { Self(bignum_ptr) } } + /// Subtract BigNumbers pub fn sub(&self, rhs: &BigNumber) -> Self { #[cfg(not(target_arch = "bpf"))] @@ -202,6 +175,13 @@ impl BigNumber { } #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_bignum_sub( + self_ptr: *const u64, + rhs_ptr: *const u64, + return_ptr: *mut u64, + ) -> u64; + } let mut bignum_ptr = 0u64; unsafe { sol_bignum_sub( @@ -213,6 +193,7 @@ impl BigNumber { Self(bignum_ptr) } } + /// Multiple BigNumbers pub fn mul(&self, rhs: &BigNumber) -> Self { #[cfg(not(target_arch = "bpf"))] @@ -233,6 +214,13 @@ impl BigNumber { } #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_bignum_mul( + self_ptr: *const u64, + rhs_ptr: *const u64, + return_ptr: *mut u64, + ) -> u64; + } let mut bignum_ptr = 0u64; unsafe { sol_bignum_mul( @@ -267,6 +255,14 @@ impl BigNumber { } #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_bignum_mod_mul( + self_ptr: *const u64, + multiplier_ptr: *const u64, + modulus_ptr: *const u64, + bignum_ptr: *mut u64, + ) -> u64; + } let mut bignum_ptr = 0u64; unsafe { sol_bignum_mod_mul( @@ -279,6 +275,7 @@ impl BigNumber { Self(bignum_ptr) } } + /// Finds the inverse of modulus on self pub fn mod_inv(&self, modulus: &BigNumber) -> Self { #[cfg(not(target_arch = "bpf"))] @@ -295,6 +292,13 @@ impl BigNumber { } #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_bignum_mod_inv( + self_ptr: *const u64, + modulus_ptr: *const u64, + bignum_ptr: *mut u64, + ) -> u64; + } let mut bignum_ptr = 0u64; unsafe { sol_bignum_mod_inv( @@ -327,6 +331,13 @@ impl BigNumber { } #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_bignum_div( + self_ptr: *const u64, + rhs_ptr: *const u64, + return_ptr: *mut u64, + ) -> u64; + } let mut bignum_ptr = 0u64; unsafe { sol_bignum_div( @@ -338,6 +349,7 @@ impl BigNumber { Self(bignum_ptr) } } + /// Square BigNumbers pub fn sqr(&self) -> Self { #[cfg(not(target_arch = "bpf"))] @@ -351,6 +363,12 @@ impl BigNumber { } #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_bignum_sqr( + self_ptr: *const u64, + modulus_ptr: *const u64, + ) -> u64; + } let mut bignum_ptr = 0u64; unsafe { sol_bignum_sqr( @@ -361,6 +379,7 @@ impl BigNumber { Self(bignum_ptr) } } + /// Square BigNumbers pub fn mod_sqr(&self, modulus: &BigNumber) -> Self { #[cfg(not(target_arch = "bpf"))] @@ -381,6 +400,13 @@ impl BigNumber { } #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_bignum_mod_sqr( + self_ptr: *const u64, + modulus_ptr: *const u64, + bignum_ptr: *mut u64, + ) -> u64; + } let mut bignum_ptr = 0u64; unsafe { sol_bignum_mod_sqr( @@ -392,6 +418,7 @@ impl BigNumber { Self(bignum_ptr) } } + /// Square BigNumbers pub fn exp(&self, exponent: &BigNumber) -> Self { #[cfg(not(target_arch = "bpf"))] @@ -412,6 +439,13 @@ impl BigNumber { } #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_bignum_exp( + self_ptr: *const u64, + exponent_ptr: *const u64, + bignum_ptr: *mut u64, + ) -> u64; + } let mut bignum_ptr = 0u64; unsafe { sol_bignum_exp( @@ -446,6 +480,14 @@ impl BigNumber { } #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_bignum_mod_exp( + bignum_ptr: *mut u64, + self_ptr: *const u64, + exponent_ptr: *const u64, + modulus_ptr: *const u64, + ) -> u64; + } let bignum_ptr = &mut 0u64; unsafe { sol_bignum_mod_exp( @@ -458,7 +500,6 @@ impl BigNumber { Self(*bignum_ptr) } } - /// Hashed Generator pub fn hashed_generator(&self, a: &BigNumber, n: &BigNumber, nonce: &[u8]) -> Self { #[cfg(not(target_arch = "bpf"))] @@ -501,6 +542,15 @@ impl BigNumber { } #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_bignum_hashed_generator( + self_ptr: *const u64, + a: *const u64, + n: *const u64, + nonce: *const u64, + hg_ptr: *mut u64, + ) -> u64; + } let mut bignum_ptr = nonce.len() as u64; unsafe { sol_bignum_hashed_generator( @@ -515,7 +565,7 @@ impl BigNumber { } } - /// Hashed Generator + /// Hash to Prime pub fn hash_to_prime(u: &BigNumber, a: &BigNumber, z: &BigNumber, nonce: &[u8]) -> Self { #[cfg(not(target_arch = "bpf"))] { @@ -561,6 +611,15 @@ impl BigNumber { } #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_bignum_hash_to_prime( + u: *const u64, + a: *const u64, + z: *const u64, + nonce: *const u64, + htp_ptr: *mut u64, + ) -> u64; + } let mut bignum_ptr = nonce.len() as u64; unsafe { sol_bignum_hash_to_prime( @@ -581,6 +640,9 @@ impl BigNumber { crate::program_stubs::sol_log(&self.to_string()); #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_log_bignum(bignum_addr: *const u64) -> u64; + } unsafe { sol_log_bignum(&self.0 as *const _ as *const u64) }; } } @@ -638,6 +700,9 @@ impl Drop for BigNumber { } #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_bignum_drop(bignum_ptr: *mut u64) -> u64; + } unsafe { sol_bignum_drop(&mut self.0 as *mut _ as *mut u64); } @@ -660,6 +725,14 @@ pub fn blake3_digest(data: &[u8]) -> Vec { } #[cfg(target_arch = "bpf")] { + extern "C" { + fn sol_blake3_digest( + data_ptr: *const u8, + data_len: *const u64, + digest_ptr: *mut u8, + digest_len: *mut u64, + ) -> u64; + } let data_len = data.len(); let mut digest = [0u8; 32]; let mut digest_len = digest.len();