-
Notifications
You must be signed in to change notification settings - Fork 10
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
fix: 🐛 Components CPI caller check #87
base: main
Are you sure you want to change the base?
fix: 🐛 Components CPI caller check #87
Conversation
1975579
to
93962aa
Compare
@iamnamananand996 the PR looks good to me, but we should enforce that the check is now correct. There are 2 integration tests for the CPI check that were passing with the previous implementation. Is there a case where prev check fails and this pass that we can add> |
Hi @GabrielePicco , thanks for pointing out, this a valid check we should add before merging it, I will check for the above suggestion and update this accordingly. |
51432c7
to
0e11c24
Compare
10dd493
to
f05556d
Compare
Hi @GabrielePicco, I check all the test, and regarding the test case you mention 2 integration tests for the CPI check, that are passing. and there where 2 test which where failing, that I have updated. failed test |
5a69de5
to
baaedb3
Compare
Thanks @iamnamananand996 , |
Problem
solana_program::sysvar::instructions::get_instruction_relative
to enforce that they are called from CPI and the identify of the caller, This may contains a bug, since a transaction could contain a valid instruction atindex [0]
, but be malicious.Full description is available: #29 (comment)
Solution
To correctly determine if your program was called via CPI, you should:
Use
get_instruction_relative(-1, ...)
: This will attempt to retrieve the instruction that called the currently executing instruction. If the program was called directly, there will be no instruction at index-1
, and the function will return an error.Check for Errors: If
get_instruction_relative(-1, ...) returns an Err
, it means the program was called directly. If it returnsOk
, you can proceed, knowing it was called via CPI.Closes: [Bug/Investigation] Components CPI caller check #29
cc - @GabrielePicco