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:
Sean Young
2021-09-03 22:35:38 +01:00
parent d461a9ac10
commit 8b9e472a6c
17 changed files with 577 additions and 13 deletions

View File

@ -0,0 +1 @@
crate::declare_id!("Ed25519SigVerify111111111111111111111111111");

View File

@ -1,5 +1,6 @@
#![allow(clippy::integer_arithmetic)]
use crate::clock::DEFAULT_MS_PER_SLOT;
use crate::ed25519_program;
use crate::message::Message;
use crate::secp256k1_program;
use log::*;
@ -32,20 +33,22 @@ impl FeeCalculator {
note = "Please do not use, will no longer be available in the future"
)]
pub fn calculate_fee(&self, message: &Message) -> u64 {
let mut num_secp256k1_signatures: u64 = 0;
let mut num_signatures: u64 = 0;
for instruction in &message.instructions {
let program_index = instruction.program_id_index as usize;
// Message may not be sanitized here
if program_index < message.account_keys.len() {
let id = message.account_keys[program_index];
if secp256k1_program::check_id(&id) && !instruction.data.is_empty() {
num_secp256k1_signatures += instruction.data[0] as u64;
if (secp256k1_program::check_id(&id) || ed25519_program::check_id(&id))
&& !instruction.data.is_empty()
{
num_signatures += instruction.data[0] as u64;
}
}
}
self.lamports_per_signature
* (u64::from(message.header.num_required_signatures) + num_secp256k1_signatures)
* (u64::from(message.header.num_required_signatures) + num_signatures)
}
}

View File

@ -13,6 +13,7 @@ pub mod bpf_loader_deprecated;
pub mod bpf_loader_upgradeable;
pub mod clock;
pub mod decode_error;
pub mod ed25519_program;
pub mod entrypoint;
pub mod entrypoint_deprecated;
pub mod epoch_schedule;