Add Keccak256 syscall and sdk support (#16498)
This commit is contained in:
19
programs/bpf/rust/sha/Cargo.toml
Normal file
19
programs/bpf/rust/sha/Cargo.toml
Normal file
@@ -0,0 +1,19 @@
|
||||
[package]
|
||||
name = "solana-bpf-rust-sha"
|
||||
version = "1.7.0"
|
||||
description = "Solana BPF test program written in Rust"
|
||||
authors = ["Solana Maintainers <maintainers@solana.foundation>"]
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
license = "Apache-2.0"
|
||||
homepage = "https://solana.com/"
|
||||
documentation = "https://docs.rs/solana-bpf-rust-sha"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-program = { path = "../../../../sdk/program", version = "=1.7.0" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
43
programs/bpf/rust/sha/src/lib.rs
Normal file
43
programs/bpf/rust/sha/src/lib.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
//! @brief SHA Syscall test
|
||||
|
||||
extern crate solana_program;
|
||||
use solana_program::{custom_panic_default, msg};
|
||||
|
||||
fn test_sha256_hasher() {
|
||||
use solana_program::hash::{hashv, Hasher};
|
||||
let vals = &["Gaggablaghblagh!".as_ref(), "flurbos".as_ref()];
|
||||
let mut hasher = Hasher::default();
|
||||
hasher.hashv(vals);
|
||||
assert_eq!(hashv(vals), hasher.result());
|
||||
}
|
||||
|
||||
fn test_keccak256_hasher() {
|
||||
use solana_program::keccak::{hashv, Hasher};
|
||||
let vals = &["Gaggablaghblagh!".as_ref(), "flurbos".as_ref()];
|
||||
let mut hasher = Hasher::default();
|
||||
hasher.hashv(vals);
|
||||
assert_eq!(hashv(vals), hasher.result());
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
||||
msg!("sha");
|
||||
|
||||
test_sha256_hasher();
|
||||
test_keccak256_hasher();
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
custom_panic_default!();
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_sha() {
|
||||
test_sha256_hasher();
|
||||
test_keccak256_hasher();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user