solana-developers / solana-cookbook

https://solanacookbook.com/
606 stars 340 forks source link

ED25519 signature verification #211

Open ronanyeah opened 2 years ago

ronanyeah commented 2 years ago

I am trying to figure out if signature verification is possible onchain. If it is I will create an example for the cookbook.

I have tried to implement it with various ed25519 rust crates but keep running out of CPU: Screenshot from 2022-01-17 22-31-46

I think this file is relevant, but relates to the SDK (which is offchain only): https://github.com/solana-labs/solana/blob/master/sdk/src/ed25519_instruction.rs

ronanyeah commented 2 years ago

I'm hoping to achieve something like this:

fn verify(message: &[u8; 32], sig_bytes: &[u8; 64], signer: &Pubkey) -> bool {
    let signature = Signature::new(sig_bytes);
    let keypair = Signer::new(signer.to_bytes());
    let result = keypair.verify(message, &signature);
    result.is_ok()
}
jacobcreech commented 2 years ago

@ronanyeah you should be able to achieve this with the ed25519 program https://docs.solana.com/developing/runtime-facilities/programs#ed25519-program

CPI to that program within yours and you're good

ronanyeah commented 2 years ago

Thanks! I'm currently porting this file from Transaction::new_signed_with_payer to use CPI, invoke(...) etc.

ronanyeah commented 2 years ago

Apparently this program doesn't work for CPI for GPU reasons: Program failed to complete: Program Ed25519SigVerify111111111111111111111111111 not supported by inner instructions

https://github.com/solana-labs/solana/issues/19843

Apparently the correct approach is to verify the signature in a separate instruction, then walk through the instructions in your program code using Sysvar1nstructions1111111111111111111111111 to confirm the signature value.

ZafarMansoori commented 9 months ago

I want to verify multiple signature in solana smart contract how can i do this . i am able to verify signle signature in smart contract . but how can i verify multiple signature