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

token / ata: Use upgradeable loader to save copies during CPI #26823

Closed
joncinque opened this issue Jul 27, 2022 · 5 comments
Closed

token / ata: Use upgradeable loader to save copies during CPI #26823

joncinque opened this issue Jul 27, 2022 · 5 comments
Assignees

Comments

@joncinque
Copy link
Contributor

Problem

When executable accounts are passed into a program for CPI, their entire program data is copied over as well. This can create overhead for programs using the non-upgradeable loader. Programs using the upgradeable loader aren't affected, since only 36 bytes are in the program account.

The token / associated-token-account use the non-upgradeable loader, which makes them susceptible to this issue.

They should use the upgradeable loader (as finalized programs, of course)! The current upgrade method, however, only swaps the program accounts, which would cause an issue for the program data account associated with the program, since that's derived from the program address.

Proposed Solution

During the next upgrade, use the upgradeable loader for the program, and in the runtime, move the program and program data accounts.

@joncinque joncinque self-assigned this Jul 27, 2022
@github-actions github-actions bot added the stale [bot only] Added to stale content; results in auto-close after a week. label Jul 28, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 7, 2023
@joncinque
Copy link
Contributor Author

I believe this isn't required because all programs, even ones on the old loader, don't have their bytecode copied in and out of instruction contexts during CPI. @Lichtso can you confirm?

@joncinque joncinque reopened this Aug 7, 2023
@Lichtso
Copy link
Contributor

Lichtso commented Aug 7, 2023

The bytecode is not copied during CPI for the program that is being called.
For instruction accounts however the content is copied (even if it is a program).

@joncinque
Copy link
Contributor Author

joncinque commented Aug 7, 2023

Ah I think I see, so if I have:

my program -> some other program -> Token program

When my program CPIs into some other program and provides the token program as an instruction account, then the bytecode for token program is copied into some other program, correct? If so, would there be a benefit to moving the token program to the upgradeable loader?

@github-actions github-actions bot removed the stale [bot only] Added to stale content; results in auto-close after a week. label Aug 8, 2023
@Lichtso
Copy link
Contributor

Lichtso commented Aug 8, 2023

When my program CPIs into some other program and provides the token program as an instruction account, then the bytecode for token program is copied into some other program, correct?

Correct.

If so, would there be a benefit to moving the token program to the upgradeable loader?

All loaders behave the same in terms of what they copy, so no benefit there.
The account data direct mapping feature however will solve this across all loaders.

@joncinque
Copy link
Contributor Author

Ah ok, sounds like this is very closable then, thanks!

@joncinque joncinque closed this as not planned Won't fix, can't repro, duplicate, stale Aug 8, 2023
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

2 participants