-
Notifications
You must be signed in to change notification settings - Fork 15
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
[SOLVED]: Why can't we verify through a CPI? #6
Comments
Hello! I will briefly explain how this works and hopefully that will help answer both questions: In Solana, a program that can verify Ed25519 signatures exists. This program can indeed verify (message, signature, pubkey), validating that the private key associated to that public key produced that signature over the given message. This is common procedure and works just as you know from Ethereum. You can see this part of the code here. The problem is that this program can verify signatures, but we cannot invoke it from our own program through a CPI! (Or, at least, by the time I created this example, and I assume this is still the same). Now the question is: how can we add custom logic in our program in order to assert that the instruction that was added before is indeed one that helps us prove that the signature that we want to verify was indeed verified correctly? What we are basically doing is sending this:
And checking from "Instruction 2" that "Instruction 1" has everything that we expect it to have. Therefore, we need to solve this problem: how do we check that a previous instruction in the group has what we expect it to? By doing that, we recover the raw Instruction, which is made of three fields: pub struct Instruction {
pub program_id: Pubkey,
pub accounts: Vec<AccountMeta>,
pub data: Vec<u8>,
} By checking, then, those three fields (in verify_ed25519_ix), we can assert that somebody sent exactly the instruction we needed in the same group! As checking the Now that you understand this, refer to the I understand this might be shocking to see. How can verifying a custom signature be so complicated?! But I guess the answer is: Solana is meant to be a torture device for developers. If you need any further help let me know! |
I edited the name of the issue to help anybody that is trying to find this. Hope you don't mind |
Not at all. Thanks for your reply. |
@GuidoDipietro I have just try scep256k1 test on devnet, it failed. |
Hey. As I did it my tests started failing since I was catching the error in a rather weird way. See here how I changed it for my tests to work now. I think that you can do this to help yours run too. Let me know! |
Yeah, it success after changing the error match content in |
In past days, I was thinking about why we can do sig verification by invoke secp256k1_program or ed25519_program through CPI. |
@code-brewer I had the same question, if you dig into the solana source, you'll find that you can't invoke because it results in a no-op (even if you could). This is unfortunately by design, the pre-compiled programs run outside the svm. For more info: Also here: |
After read your
check_ed25519_data
function, I wonder, Isn't it suffice to do verify {msg, signature, pubkey} without IX data ? To my expecience on Ethereum, we can recover public key from signature, and compare it agaistpubkey
Your Tx compose from 2 instructions, first one is sig verification IX. I think this first IX do verification also, then, why do we need to check sig again in second IX ?
The text was updated successfully, but these errors were encountered: