-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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-2022: implement CpiGuard #3712
Conversation
bee0b0f
to
dc35edb
Compare
well the first pass on the processor and instruction is basically done. i copied everything from |
ef1154b
to
1e4371a
Compare
alright the hardest part of this entire thing honestly was setting up the ability to test calls to token22 through a cpi intermediary and that is dooone. and i have correct tests for the "cpi guard cant be changed in cpi" bullet point. everything works. next up: add the guards into the token instructions! |
with fresh eyes on this after the weekend, im not sure about my cpi testing strategy. i wrote this like, each testable action gets one passthrough program instruction that performs the required action, obviating the need to use the data array for anything or implement serialization logic. but now im wondering if it wouldnt be better if the passthrough took an arbitrary serialized instruction, parsed, and invoked it, obviating the need for multiple instructions on the passthrough? im gonna keep going like this since i already set the infra up to work this way (and also because the other way is more complicated lol) but maybe something to consider after the feature is done... |
1ddf95f
to
2c415e6
Compare
@joncinque the extension is done, if you wanted to take a peek. the only interesting files are also ty for telling me about |
2c415e6
to
c5d8b4f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic looks great! Just a few little questions and nits
Cargo.toml
Outdated
@@ -39,6 +39,7 @@ members = [ | |||
"token/program-2022", | |||
"token/program-2022-test", | |||
"token/client", | |||
"token/program-2022-test/cpi-caller", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the native mode of program-test, ie the mode set using program_test.prefer_bpf(false)
, should actually work rather than needing to build this in BPF and use it in program-2022-test
. That way, you don't need to worry about building the program separately, and instead just include its processor function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im assuming this is meant to be a comment on my adding my caller program to build.rs
, which i assumed was necessary (and added your instruction padder to it to replace.) will try removing it and see if things still work but if you meant something else lmk
edit: well. it turns out build.rs
doesnt do anything for me in either case. i added a panic to the processor and tests kept passing anyway
it looks like the way things are currently set up, the tests just use whatever version of the instruction padder sbf binary has already been built by hand; my version of build.rs
doesnt force a rebuild if the padder changes, and the tests are definitely not using the processor function as-is (otherwise my tests would be failing in ci because of the get_stack_height()
issue)
im gonna revert my build.rs
changes since it doesnt seem to affect anything either way. i cargo culted this one based on what was already there without any awareness of what it actually is supposed to do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol jk i guess without it in build.rs, ci doesnt build it at all
c5d8b4f
to
a0eb272
Compare
im now based on the instruction padder and using it for tests. ill address the rest of the fixmes and write tests for the remaining fns tomorrow. also since im removing the caller thing iwrote the commit history is fucked so i will be squash merging this (ive become very fond of rebase merging...) |
cb4b4d3
to
07fcb5c
Compare
@joncinque just to clarify when you have a chance:
|
Sorry, I was unclear on this -- I think it's good to leave it as it is
I'm probably missing something here, since I don't totally understand the rationale. If an account has an immutable owner, an outside close authority doesn't threaten or change the immutable ownership of the account. You still can't set a different owner. Or is the concept that the close authority exerts some form of "ownership" over the account? |
yea i guess something like "granting a close authority is tantamount to partial alienation of ownership" but if that doesnt make sense im not like, strongly in favor |
In that case, my vote is to leave it out for now |
alright tests are done, final fixes tomorrow and then we should be good |
ok i think this is done. note again i will be squashing this hstory lol |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great work! only micro things to do with as you please
Pull request has been modified.
c0831c6
to
3d703b5
Compare
also normalize use of "CPI" in production code comments to match internal style
also place all checks after validate_owner, for consistency
looks like this broke the monorepo ci downstream-builds job somehow. it's complaining about the shared object not being available, despite a shiny green "compiling" above and no suspicious log lines in between. 🤷 gonna revert in the meantime. feel free to put it back once resolved EDIT: |
token-2022: implement CPI Guard CPI Guard is an extension to block certain unsafe token operations from being done by programs through CPI
This reverts commit 126fb93.
closes #3694