-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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
[verifier] allow &TxContext in entry functions #7043
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
53b30c9
to
8a3afb9
Compare
@tnowacki, interestingly, this change causes a compiler crash via
I think this is because there was test code that still passed the now-redundant context:
Stack trace was
Will try to create a smaller repro and submit an issue in the Move repo, but flagging here just in case. |
a368977
to
6e5ff66
Compare
/// - optional one-time witness type (see one_time_witness verifier pass) passed by value in the first | ||
/// position | ||
/// | ||
/// For transaction entry points | ||
/// - The function must have `is_entry` true | ||
/// - The function must have at least one parameter: &mut TxContext (see `is_tx_context`) | ||
/// - The function may have an optional &mut TxContext or &TxContext (see `is_tx_context`) parameter |
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.
From Issue description and this comment, it's not clear if we assume the input to an entry function can be any of &mut TxContext or &TxContext
or we can even omit TxContext
completely. (probably the word "optional" here causes that confusion)
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.
Updated the PR description and will fix the comment as well.
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.
LGTM! Love the legibility improvement for entry functions.
Err(format!( | ||
"Expected last (and at most second) parameter for {}::{} to be &mut {}::{}::{}, but found {}", | ||
"Expected last (and at most second) parameter for {}::{} to be &mut {}::{}::{} or &{}::{}::{}, but found {}", | ||
module.self_id(), | ||
INIT_FN_NAME, | ||
SUI_FRAMEWORK_ADDRESS, | ||
TX_CONTEXT_MODULE_NAME, | ||
TX_CONTEXT_STRUCT_NAME, | ||
SUI_FRAMEWORK_ADDRESS, | ||
TX_CONTEXT_MODULE_NAME, | ||
TX_CONTEXT_STRUCT_NAME, | ||
format_signature_token(view, ¶meters[0]), | ||
)) |
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.
Consider re-using the earlier parameters?
Err(format!( | |
"Expected last (and at most second) parameter for {}::{} to be &mut {}::{}::{}, but found {}", | |
"Expected last (and at most second) parameter for {}::{} to be &mut {}::{}::{} or &{}::{}::{}, but found {}", | |
module.self_id(), | |
INIT_FN_NAME, | |
SUI_FRAMEWORK_ADDRESS, | |
TX_CONTEXT_MODULE_NAME, | |
TX_CONTEXT_STRUCT_NAME, | |
SUI_FRAMEWORK_ADDRESS, | |
TX_CONTEXT_MODULE_NAME, | |
TX_CONTEXT_STRUCT_NAME, | |
format_signature_token(view, ¶meters[0]), | |
)) | |
Err(format!( | |
"Expected last (and at most second) parameter for {0}::{1} to be &mut {2}::{3}::{4} or &{2}::{3}::{4}, but found {5}", | |
module.self_id(), | |
INIT_FN_NAME, | |
SUI_FRAMEWORK_ADDRESS, | |
TX_CONTEXT_MODULE_NAME, | |
TX_CONTEXT_STRUCT_NAME, | |
format_signature_token(view, ¶meters[0]), | |
)) |
6e5ff66
to
15f716c
Compare
This makes it possible to see whether an entry function may create new objects just by looking at the type signature. Tweaked the verifier to alow this, and updated some framework and example code accordingly.
15f716c
to
6ed7fe0
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.
I think we need to update the comments in crates/sui-verifier/src/one_time_witness_verifier.rs
too. which refers to &mut TxContext
in some of it's error messages.
Similarly, should we allow &TxContext
in init
?
At one point, I removed the necessity of the transaction context at all in init
but then decided that was silly since then your init
can't do anything meaningful. Thoughts?
Previously, we required entry functions that need a
TxContext
to take a&mut TxContext
input. But anentry
function that only reads the epoch or transaction sender does not need&mut
. This change makes it possible to see whether an entry function may create new objects just by looking at the type signature. The new policy is thus:entry
functions need not include aTxContext
inputTxContext
input, it can declare either&TxContext
or&mut TxContext
according to its needs.Tweaked the verifier to alow this, and updated some framework and example code accordingly.