Add Keccak256 syscall and sdk support (#16498)

This commit is contained in:
Jack May
2021-05-10 16:16:58 -07:00
committed by GitHub
parent e511c442e6
commit 8eb05d6ed4
17 changed files with 366 additions and 73 deletions

View 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"]

View 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();
}
}