feat: add ed25519 signature verify program
Solang requires a method for verify ed25519 signatures. Add a new builtin program at address Ed25519SigVerify111111111111111111111111111 which takes any number of ed25519 signature, public key, and message. If any of the signatures fails to verify, an error is returned. The changes for the web3.js package will go into another commit, since the tests test against a released solana node. Adding web3.js ed25519 testing will break CI.
This commit is contained in:
29
programs/bpf/Cargo.lock
generated
29
programs/bpf/Cargo.lock
generated
@ -287,6 +287,26 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
version = "1.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72957246c41db82b8ef88a5486143830adeb8227ef9837740bdec67724cf2c5b"
|
||||
dependencies = [
|
||||
"bytemuck_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck_derive"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e215f8c2f9f79cb53c8335e687ffd07d5bfcb6fe5fc80723762d0be46e7cc54"
|
||||
dependencies = [
|
||||
"proc-macro2 1.0.24",
|
||||
"quote 1.0.6",
|
||||
"syn 1.0.67",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "0.5.3"
|
||||
@ -2898,6 +2918,13 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-ed25519-program"
|
||||
version = "1.8.0"
|
||||
dependencies = [
|
||||
"solana-sdk",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-faucet"
|
||||
version = "1.8.0"
|
||||
@ -3209,6 +3236,7 @@ dependencies = [
|
||||
"serde_derive",
|
||||
"solana-compute-budget-program",
|
||||
"solana-config-program",
|
||||
"solana-ed25519-program",
|
||||
"solana-frozen-abi 1.8.0",
|
||||
"solana-frozen-abi-macro 1.8.0",
|
||||
"solana-logger 1.8.0",
|
||||
@ -3237,6 +3265,7 @@ dependencies = [
|
||||
"borsh-derive",
|
||||
"bs58 0.4.0",
|
||||
"bv",
|
||||
"bytemuck",
|
||||
"byteorder 1.4.3",
|
||||
"chrono",
|
||||
"derivation-path",
|
||||
|
26
programs/ed25519/Cargo.toml
Normal file
26
programs/ed25519/Cargo.toml
Normal file
@ -0,0 +1,26 @@
|
||||
[package]
|
||||
name = "solana-ed25519-program"
|
||||
description = "Solana Ed25519 program"
|
||||
version = "1.8.0"
|
||||
homepage = "https://solana.com/"
|
||||
documentation = "https://docs.rs/solana-ed25519-program"
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
authors = ["Solana Maintainers <maintainers@solana.foundation>"]
|
||||
license = "Apache-2.0"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
solana-sdk = { path = "../../sdk", version = "=1.8.0" }
|
||||
|
||||
[dev-dependencies]
|
||||
bytemuck = { version = "1.7.2", features = ["derive"] }
|
||||
ed25519-dalek = "=1.0.1"
|
||||
rand = "0.7.0"
|
||||
solana-logger = { path = "../../logger", version = "=1.8.0" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["lib"]
|
||||
name = "solana_ed25519_program"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
55
programs/ed25519/src/lib.rs
Normal file
55
programs/ed25519/src/lib.rs
Normal file
@ -0,0 +1,55 @@
|
||||
use solana_sdk::{
|
||||
instruction::InstructionError, process_instruction::InvokeContext, pubkey::Pubkey,
|
||||
};
|
||||
|
||||
pub fn process_instruction(
|
||||
_program_id: &Pubkey,
|
||||
_data: &[u8],
|
||||
_invoke_context: &mut dyn InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
// Should be already checked by now.
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod test {
|
||||
use rand::{thread_rng, Rng};
|
||||
use solana_sdk::{
|
||||
ed25519_instruction::new_ed25519_instruction,
|
||||
feature_set::FeatureSet,
|
||||
hash::Hash,
|
||||
signature::{Keypair, Signer},
|
||||
transaction::Transaction,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[test]
|
||||
fn test_ed25519() {
|
||||
solana_logger::setup();
|
||||
|
||||
let privkey = ed25519_dalek::Keypair::generate(&mut thread_rng());
|
||||
let message_arr = b"hello";
|
||||
let mut instruction = new_ed25519_instruction(&privkey, message_arr);
|
||||
let mint_keypair = Keypair::new();
|
||||
let feature_set = Arc::new(FeatureSet::all_enabled());
|
||||
|
||||
let tx = Transaction::new_signed_with_payer(
|
||||
&[instruction.clone()],
|
||||
Some(&mint_keypair.pubkey()),
|
||||
&[&mint_keypair],
|
||||
Hash::default(),
|
||||
);
|
||||
|
||||
assert!(tx.verify_precompiles(&feature_set).is_ok());
|
||||
|
||||
let index = thread_rng().gen_range(0, instruction.data.len());
|
||||
instruction.data[index] = instruction.data[index].wrapping_add(12);
|
||||
let tx = Transaction::new_signed_with_payer(
|
||||
&[instruction],
|
||||
Some(&mint_keypair.pubkey()),
|
||||
&[&mint_keypair],
|
||||
Hash::default(),
|
||||
);
|
||||
assert!(tx.verify_precompiles(&feature_set).is_err());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user