Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secp256k1 and Ed25519 native programs don't fail when a wrong signature is passed #27

Open
GuidoDipietro opened this issue Aug 8, 2024 · 6 comments

Comments

@GuidoDipietro
Copy link

Some tests don't work as expected with Bankrun regarding Secp256k1 and Ed25519 signature verification.

Test case

  • Have two instructions in a tx: sigIx and customIx
    • sigIx is either a Secp256k1 or Ed25519 instruction that validates a signature
    • customIx is a custom program instruction that performs instruction introspection on the earlier to check the programId, accounts and data
  • Provide invalid data to sigIx; namely, a signature S and pubkey P, such that the private key associated to P was NOT the signer of the message M, i.e. the signature S corresponds to a malicious signer P'

Expected result

  • Even though customIx checks that sigIx had the same message and pubkey as expected, the signature is invalid. For this reason, we expect the sigIx to have failed, therefore rejecting the entire transaction.

Reproducible result with RPC testing

Error Transaction precompile verification failure InvalidAccountIndex is raised.
Apparently, this is what we get when the sigIx instruction fails.
It seems that this is a known issue, but at least the transaction fails.

Reproducible result with Bankrun testing

The transactions succeeds.


See examples in this repository.

@GuidoDipietro
Copy link
Author

Currently, I have no way to test that case with Bankrun. I found no workaround at all.

@kevinheavey
Copy link
Owner

Could you check if you have the same issue in Rust using solana-program-test? Need to identifiy which part of the stack the problem lives in

@GuidoDipietro
Copy link
Author

I managed to reproduce this on solana-program-test! I'm very surprised that nobody had caught this before.
Either there's an additional config field to set somewhere which I'm completely missing, or this is broken.

Here's an example which you can run to see the transaction doesn't fail when it should.

Could you confirm this is not working as expected?

Logs:

[2024-08-09T15:36:53.322604146Z INFO  solana_program_test] "signatures" SBF program from /home/gedos/solana-ed25519-secp256k1-sig-verification/target/deploy/signatures.so, modified 10 minutes, 10 seconds, 504 ms, 302 µs and 346 ns ago
[2024-08-09T15:36:53.353807753Z DEBUG solana_runtime::message_processor::stable_log] Program DHxesXA69rUmz5AJ1CnLCQezUzQR5j7KKTwTp1zZPc9j invoke [1]
[2024-08-09T15:36:53.354035755Z DEBUG solana_runtime::message_processor::stable_log] Program log: Instruction: VerifyEd25519
[2024-08-09T15:36:53.354142045Z DEBUG solana_runtime::message_processor::stable_log] Program DHxesXA69rUmz5AJ1CnLCQezUzQR5j7KKTwTp1zZPc9j consumed 3162 of 400000 compute units
[2024-08-09T15:36:53.354186920Z DEBUG solana_runtime::message_processor::stable_log] Program DHxesXA69rUmz5AJ1CnLCQezUzQR5j7KKTwTp1zZPc9j success
   Doc-tests signatures

running 1 test
test test_id ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s


running 1 test
test test_program ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.03s


running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

@GuidoDipietro
Copy link
Author

Perhaps this is related:
solana-labs/solana#17961

Could I be encoding something wrong? I noticed the message I'm signing is not hashed and also longer than a hash of it

@wedancedalot
Copy link

wedancedalot commented Nov 26, 2024

@GuidoDipietro how did you manage to run Ed25519SigVerify inside solana-program-test? which version did you use?
I'm trying to replicate your issue and keep receiving an Unsupported program id error. Also there's no way to do a solana program dump as it's not a BPF program

upd: nevermind, already found your test case, reproduced it locally too

@GuidoDipietro
Copy link
Author

For the record, I had to use regular test frameworks (i.e. standard Anchor way) to test this as it was impossible to determine if the sig verify was succeeding or not using Bankrun

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants