On-chain Ed25519 and Secp256k1 signature verification using instruction introspection.
Built for checking Solana and Ethereum signatures, with examples (see tests).
Solana does not have a way to implement Ed25519 or Secp256k1 sig verification on-chain on custom programs. That's why the native Ed25519Program and native Secp256k1Program exist, which have a set of instructions that can, amongst other things, verify signatures for those curves.
Therefore, the way to build custom instructions that "do" sig verification is by actually sending a transaction made of (at least) two instructions, and checking that the native program instruction was sent.
In doing so, these are the possible outcomes:
solana_program
provides us with the load_instruction_at_checked
function on the Instructions Sysvar
, that allows us to recover the raw fields of an instruction at a given index (fields are program_id, accounts, data
).
In order for us to check that that instruction was constructed properly, we need to inspect the data byte array manually.
Install Anchor first.
There are two test files with the same concepts: one, signing using a Solana keypair (Ed25519 signatures); the other one, using an Ethereum Wallet (Secp256k1 signatures).
yarn install
anchor build
yarn test --skip-build