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

Add ability for programs to check the processed instruction stack #22437

Closed
jackcmay opened this issue Jan 11, 2022 · 13 comments · Fixed by #22859
Closed

Add ability for programs to check the processed instruction stack #22437

jackcmay opened this issue Jan 11, 2022 · 13 comments · Fixed by #22859

Comments

@jackcmay
Copy link
Contributor

Problem

There are certain scenarios where instructions (top-level or via CPI) would like to know what the last instruction processed was. Some examples are verification of assert instructions or to check memo instructions

Proposed Solution

Make at least the last executed instruction available to programs. With the option of expanding to to a list of all past processed instructions in the tx. There has already been work done in this general direction so hopefully, this will not be very disruptive.

@CriesofCarrots
Copy link
Contributor

I think we may need this in v1.9 timeframe. Will that be possible?

@jackcmay
Copy link
Contributor Author

I think we can make that happen

@Lichtso
Copy link
Contributor

Lichtso commented Jan 13, 2022

"processed instruction stack" is ambiguous, do you mean (in terms of flamegraph diagram axes):

  • X-axis: The list / sequence of recorded instructions
  • Y-axis: The invocation / CPI stack

The former is only used by the bank and the later will be exposed in ABIv2 per default (no syscall necessary).

@jackcmay
Copy link
Contributor Author

jackcmay commented Jan 13, 2022

An ordered list of all the instructions that have been processed before the current one (including CPI) is my understanding. And the target is v1.9

@Lichtso
Copy link
Contributor

Lichtso commented Jan 13, 2022

So a mixture of the two. The thing is, the frames below the current one in the CPI stack are not finished / processed yet. They are just suspended and waiting for the upper ones to finish. Thus, these are two separate concepts that can not be mixed (at least not directly). Also the order of mixing a sequence and a stack will be messed up, because a lower frame would come before the current one in the CPI stack but after the current one in the recorded sequence.

@mvines
Copy link
Member

mvines commented Jan 13, 2022

The immediate need is to discover the previous sibling CPI instruction. Use case:

  • Program A invokes B by CPI
  • Program A invokes C by CPI
  • C can discover that A previously invoked B

@CriesofCarrots
Copy link
Contributor

I think for our current purposes, just the sequence of recorded instructions would be sufficient, assuming it works within an instruction on the CPIs called at that level.

@jackcmay
Copy link
Contributor Author

Yeah, that's my understanding, what about non-cpi sibling instructions.

For example, given the call flow:

A
B -> C
B -> D

You want D to see C and A, but not B?

@CriesofCarrots
Copy link
Contributor

You want D to see C and A, but not B?

I think D seeing C and A would be the most generically useful. But for our purposes, it would work if D only saw C.

@jackcmay
Copy link
Contributor Author

And at the end B would see D and C?

@CriesofCarrots
Copy link
Contributor

And at the end B would see D and C?

Yes? Again, not strictly necessary for our purposes, but seems like it could be generically useful.

@github-actions
Copy link
Contributor

This issue has been automatically locked since there has not been any activity in past 7 days after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 30, 2022
@jstarry
Copy link
Member

jstarry commented May 4, 2022

Note that this feature will not work as expected on testnet and devnet if a transaction contains precompile instructions until the following issue is resolved: #24705

@joncinque joncinque moved this to Closed in SPL Token 22 Apr 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Status: Closed
5 participants