* Add ecrecover syscall (#17720)
Co-authored-by: Anton Lisanin <lisanin.anton@gmail.com>
(cherry picked from commit 1f288ce527)
# Conflicts:
# Cargo.lock
# programs/bpf/Cargo.lock
# programs/bpf/tests/programs.rs
# programs/bpf_loader/Cargo.toml
# programs/bpf_loader/src/syscalls.rs
# sdk/program/Cargo.toml
* resolve conflicts
Co-authored-by: s-medvedev <40623263+s-medvedev@users.noreply.github.com>
Co-authored-by: Jack May <jack@solana.com>
This commit is contained in:
74
programs/bpf/Cargo.lock
generated
74
programs/bpf/Cargo.lock
generated
@@ -1318,6 +1318,17 @@ dependencies = [
|
||||
"hmac 0.7.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hmac-drbg"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1"
|
||||
dependencies = [
|
||||
"digest 0.9.0",
|
||||
"generic-array 0.14.3",
|
||||
"hmac 0.8.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "0.2.1"
|
||||
@@ -1566,13 +1577,61 @@ dependencies = [
|
||||
"arrayref",
|
||||
"crunchy",
|
||||
"digest 0.8.1",
|
||||
"hmac-drbg",
|
||||
"hmac-drbg 0.2.0",
|
||||
"rand 0.7.3",
|
||||
"sha2 0.8.2",
|
||||
"subtle 2.2.2",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libsecp256k1"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd1137239ab33b41aa9637a88a28249e5e70c40a42ccc92db7f12cc356c1fcd7"
|
||||
dependencies = [
|
||||
"arrayref",
|
||||
"base64 0.12.3",
|
||||
"digest 0.9.0",
|
||||
"hmac-drbg 0.3.0",
|
||||
"libsecp256k1-core",
|
||||
"libsecp256k1-gen-ecmult",
|
||||
"libsecp256k1-gen-genmult",
|
||||
"rand 0.7.3",
|
||||
"serde",
|
||||
"sha2 0.9.2",
|
||||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libsecp256k1-core"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ee11012b293ea30093c129173cac4335513064094619f4639a25b310fd33c11"
|
||||
dependencies = [
|
||||
"crunchy",
|
||||
"digest 0.9.0",
|
||||
"subtle 2.2.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libsecp256k1-gen-ecmult"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32239626ffbb6a095b83b37a02ceb3672b2443a87a000a884fc3c4d16925c9c0"
|
||||
dependencies = [
|
||||
"libsecp256k1-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libsecp256k1-gen-genmult"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76acb433e21d10f5f9892b1962c2856c58c7f39a9e4bd68ac82b9436a0ffd5b9"
|
||||
dependencies = [
|
||||
"libsecp256k1-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linked-hash-map"
|
||||
version = "0.5.4"
|
||||
@@ -2801,6 +2860,7 @@ version = "1.7.5"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"byteorder 1.3.4",
|
||||
"libsecp256k1 0.5.0",
|
||||
"log",
|
||||
"num-derive 0.3.0",
|
||||
"num-traits",
|
||||
@@ -3066,6 +3126,13 @@ dependencies = [
|
||||
"solana-program 1.7.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-secp256k1-recover"
|
||||
version = "1.7.5"
|
||||
dependencies = [
|
||||
"solana-program 1.7.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-sha"
|
||||
version = "1.7.5"
|
||||
@@ -3417,6 +3484,7 @@ dependencies = [
|
||||
"hex",
|
||||
"itertools 0.9.0",
|
||||
"lazy_static",
|
||||
"libsecp256k1 0.5.0",
|
||||
"log",
|
||||
"num-derive 0.3.0",
|
||||
"num-traits",
|
||||
@@ -3554,7 +3622,7 @@ dependencies = [
|
||||
"hmac 0.10.1",
|
||||
"itertools 0.9.0",
|
||||
"lazy_static",
|
||||
"libsecp256k1",
|
||||
"libsecp256k1 0.3.5",
|
||||
"log",
|
||||
"memmap2",
|
||||
"num-derive 0.3.0",
|
||||
@@ -3612,7 +3680,7 @@ version = "1.7.5"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"digest 0.9.0",
|
||||
"libsecp256k1",
|
||||
"libsecp256k1 0.3.5",
|
||||
"rand 0.7.3",
|
||||
"sha3",
|
||||
"solana-logger 1.7.5",
|
||||
|
||||
@@ -73,6 +73,7 @@ members = [
|
||||
"rust/ro_modify",
|
||||
"rust/ro_account_modify",
|
||||
"rust/sanity",
|
||||
"rust/secp256k1_recover",
|
||||
"rust/sha",
|
||||
"rust/spoof1",
|
||||
"rust/spoof1_system",
|
||||
|
||||
@@ -86,6 +86,7 @@ fn main() {
|
||||
"ro_modify",
|
||||
"ro_account_modify",
|
||||
"sanity",
|
||||
"secp256k1_recover",
|
||||
"sha",
|
||||
"spoof1",
|
||||
"spoof1_system",
|
||||
|
||||
38
programs/bpf/c/src/secp256k1_recover/secp256k1_recover.c
Normal file
38
programs/bpf/c/src/secp256k1_recover/secp256k1_recover.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @brief Secp256k1Recover Syscall test
|
||||
*/
|
||||
#include <solana_sdk.h>
|
||||
|
||||
extern uint64_t entrypoint(const uint8_t *input) {
|
||||
|
||||
uint8_t result[SECP256K1_RECOVER_RESULT_LENGTH];
|
||||
uint8_t expected[] = { 0x42, 0xcd, 0x27, 0xe4, 0x0f, 0xdf, 0x7c, 0x97,
|
||||
0x0a, 0xa2, 0xca, 0x0b, 0x88, 0x5b, 0x96, 0x0f,
|
||||
0x8b, 0x62, 0x8a, 0x41, 0xa1, 0x81, 0xe7, 0xe6,
|
||||
0x8e, 0x03, 0xea, 0x0b, 0x84, 0x20, 0x58, 0x9b,
|
||||
0x32, 0x06, 0xbd, 0x66, 0x2f, 0x75, 0x65, 0xd6,
|
||||
0x9d, 0xbd, 0x1d, 0x34, 0x29, 0x6a, 0xd9, 0x35,
|
||||
0x38, 0xed, 0x86, 0x9e, 0x99, 0x20, 0x43, 0xc3,
|
||||
0xeb, 0xad, 0x65, 0x50, 0xa0, 0x11, 0x6e, 0x5d};
|
||||
|
||||
uint8_t hash[] = { 0xde, 0xa5, 0x66, 0xb6, 0x94, 0x3b, 0xe0, 0xe9,
|
||||
0x62, 0x53, 0xc2, 0x21, 0x5b, 0x1b, 0xac, 0x69,
|
||||
0xe7, 0xa8, 0x1e, 0xdb, 0x41, 0xc5, 0x02, 0x8b,
|
||||
0x4f, 0x5c, 0x45, 0xc5, 0x3b, 0x49, 0x54, 0xd0};
|
||||
uint8_t signature[] = { 0x97, 0xa4, 0xee, 0x31, 0xfe, 0x82, 0x65, 0x72,
|
||||
0x9f, 0x4a, 0xa6, 0x7d, 0x24, 0xd4, 0xa7, 0x27,
|
||||
0xf8, 0xc3, 0x15, 0xa4, 0xc8, 0xf9, 0x80, 0xeb,
|
||||
0x4c, 0x4d, 0x4a, 0xfa, 0x6e, 0xc9, 0x42, 0x41,
|
||||
0x5d, 0x10, 0xd9, 0xc2, 0x8a, 0x90, 0xe9, 0x92,
|
||||
0x9c, 0x52, 0x4b, 0x2c, 0xfb, 0x65, 0xdf, 0xbc,
|
||||
0xf6, 0x8c, 0xfd, 0x68, 0xdb, 0x17, 0xf9, 0x5d,
|
||||
0x23, 0x5f, 0x96, 0xd8, 0xf0, 0x72, 0x01, 0x2d};
|
||||
uint64_t recovery_id = 1;
|
||||
|
||||
uint64_t result_code = sol_secp256k1_recover(hash, recovery_id, signature, result);
|
||||
|
||||
sol_assert(0 == result_code);
|
||||
sol_assert(0 == sol_memcmp(result, expected, SHA256_RESULT_LENGTH));
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
19
programs/bpf/rust/secp256k1_recover/Cargo.toml
Normal file
19
programs/bpf/rust/secp256k1_recover/Cargo.toml
Normal file
@@ -0,0 +1,19 @@
|
||||
[package]
|
||||
name = "solana-bpf-rust-secp256k1-recover"
|
||||
version = "1.7.5"
|
||||
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-secp256k1-recover"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-program = { path = "../../../../sdk/program", version = "=1.7.5" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
44
programs/bpf/rust/secp256k1_recover/src/lib.rs
Normal file
44
programs/bpf/rust/secp256k1_recover/src/lib.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
//! @brief Secp256k1Recover Syscall test
|
||||
|
||||
extern crate solana_program;
|
||||
use solana_program::{custom_panic_default, msg};
|
||||
|
||||
fn test_secp256k1_recover() {
|
||||
use solana_program::secp256k1_recover::secp256k1_recover;
|
||||
|
||||
let expected: [u8; 64] = [
|
||||
0x42, 0xcd, 0x27, 0xe4, 0x0f, 0xdf, 0x7c, 0x97, 0x0a, 0xa2, 0xca, 0x0b, 0x88, 0x5b, 0x96,
|
||||
0x0f, 0x8b, 0x62, 0x8a, 0x41, 0xa1, 0x81, 0xe7, 0xe6, 0x8e, 0x03, 0xea, 0x0b, 0x84, 0x20,
|
||||
0x58, 0x9b, 0x32, 0x06, 0xbd, 0x66, 0x2f, 0x75, 0x65, 0xd6, 0x9d, 0xbd, 0x1d, 0x34, 0x29,
|
||||
0x6a, 0xd9, 0x35, 0x38, 0xed, 0x86, 0x9e, 0x99, 0x20, 0x43, 0xc3, 0xeb, 0xad, 0x65, 0x50,
|
||||
0xa0, 0x11, 0x6e, 0x5d,
|
||||
];
|
||||
|
||||
let hash: [u8; 32] = [
|
||||
0xde, 0xa5, 0x66, 0xb6, 0x94, 0x3b, 0xe0, 0xe9, 0x62, 0x53, 0xc2, 0x21, 0x5b, 0x1b, 0xac,
|
||||
0x69, 0xe7, 0xa8, 0x1e, 0xdb, 0x41, 0xc5, 0x02, 0x8b, 0x4f, 0x5c, 0x45, 0xc5, 0x3b, 0x49,
|
||||
0x54, 0xd0,
|
||||
];
|
||||
let recovery_id: u8 = 1;
|
||||
let signature: [u8; 64] = [
|
||||
0x97, 0xa4, 0xee, 0x31, 0xfe, 0x82, 0x65, 0x72, 0x9f, 0x4a, 0xa6, 0x7d, 0x24, 0xd4, 0xa7,
|
||||
0x27, 0xf8, 0xc3, 0x15, 0xa4, 0xc8, 0xf9, 0x80, 0xeb, 0x4c, 0x4d, 0x4a, 0xfa, 0x6e, 0xc9,
|
||||
0x42, 0x41, 0x5d, 0x10, 0xd9, 0xc2, 0x8a, 0x90, 0xe9, 0x92, 0x9c, 0x52, 0x4b, 0x2c, 0xfb,
|
||||
0x65, 0xdf, 0xbc, 0xf6, 0x8c, 0xfd, 0x68, 0xdb, 0x17, 0xf9, 0x5d, 0x23, 0x5f, 0x96, 0xd8,
|
||||
0xf0, 0x72, 0x01, 0x2d,
|
||||
];
|
||||
|
||||
let public_key = secp256k1_recover(&hash[..], recovery_id, &signature[..]).unwrap();
|
||||
assert_eq!(public_key.to_bytes(), expected);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
|
||||
msg!("secp256k1_recover");
|
||||
|
||||
test_secp256k1_recover();
|
||||
|
||||
0
|
||||
}
|
||||
|
||||
custom_panic_default!();
|
||||
@@ -430,6 +430,7 @@ fn test_program_bpf_sanity() {
|
||||
("relative_call", true),
|
||||
("sanity", true),
|
||||
("sanity++", true),
|
||||
("secp256k1_recover", true),
|
||||
("sha", true),
|
||||
("struct_pass", true),
|
||||
("struct_ret", true),
|
||||
@@ -451,6 +452,7 @@ fn test_program_bpf_sanity() {
|
||||
("solana_bpf_rust_param_passing", true),
|
||||
("solana_bpf_rust_rand", true),
|
||||
("solana_bpf_rust_sanity", true),
|
||||
("solana_bpf_rust_secp256k1_recover", true),
|
||||
("solana_bpf_rust_sha", true),
|
||||
]);
|
||||
}
|
||||
@@ -1281,6 +1283,7 @@ fn assert_instruction_count() {
|
||||
("relative_call", 10),
|
||||
("sanity", 174),
|
||||
("sanity++", 174),
|
||||
("secp256k1_recover", 357),
|
||||
("sha", 694),
|
||||
("struct_pass", 8),
|
||||
("struct_ret", 22),
|
||||
@@ -1302,7 +1305,8 @@ fn assert_instruction_count() {
|
||||
("solana_bpf_rust_param_passing", 46),
|
||||
("solana_bpf_rust_rand", 498),
|
||||
("solana_bpf_rust_sanity", 917),
|
||||
("solana_bpf_rust_sha", 29099),
|
||||
("solana_bpf_rust_secp256k1_recover", 306),
|
||||
("solana_bpf_rust_sha", 29131),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user