-
Notifications
You must be signed in to change notification settings - Fork 20
p-token: Fix review comments #32
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
Conversation
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.
Looks great! Mostly small things
76bd300
to
64bd48f
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.
Just a couple of last bits, then this is good to go on my side
_data: PhantomData, | ||
}), | ||
2 if *bytes.get_unchecked(1) == 0 => Ok(&*(bytes.as_ptr() as *const SetAuthority)), | ||
34 => Ok(&*(bytes.as_ptr() as *const SetAuthority)), |
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.
Did you mean to remove the if *bytes.get_unchecked(1) == 1
portion to this?
We probably want to keep that to be safe
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 issue is that it disproportionally increases CUs to have it. We could do the check on the accessor method:
pub fn new_authority(&self) -> Option<&Pubkey> {
if self.new_authority.0 == 1 {
Option::Some(&self.new_authority.1)
} else {
Option::None
}
}
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.
Or even return a Result
?
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.
That's fine, but it has to be 1
or 0
or it errors, which means this would need to return Result<Option<&Pubkey>, ProgramError>
instead
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.
Yeah, I think that is the best option. I will test it, but I can't imagine that it would add too much overhead.
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.
We can't do this and the current implementation has a different behaviour than the original one. We need to validate the instruction data before executing any code of the processor, otherwise we can get different results.
I fixed both SetAuthority
and InitializeMint
instruction data validation, adding the validation for the option byte.
34 if *bytes.get_unchecked(33) == 0 => { | ||
Ok(&*(bytes.as_ptr() as *const InitializeMint)) | ||
} | ||
66 => Ok(&*(bytes.as_ptr() as *const InitializeMint)), |
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.
Should this have if *bytes.get_unchecked(33) == 1
like the other one?
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.
Same here, we could have the check on the accessor instead.
64bd48f
to
7981197
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.
Looks great!
7981197
to
bc765ed
Compare
e058e93
to
c12b54f
Compare
Address Jon's comments from #28.
Closes #28