-
Notifications
You must be signed in to change notification settings - Fork 265
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: misc unsafe improvements (#8803)
Continuation of the safety efforts: I removed the `unconstrained` property from some functions that are actually always safe to call (e.g. logs), improved documentation a bit, and expanded on some `unsafe` callsites explaining why what we're doing is correct. This was originally much larger, covering `unsafe_rand` and `get_key_validation_request`, but I left those out as things got a bit out of hand.
- Loading branch information
Showing
14 changed files
with
181 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,34 @@ | ||
#[oracle(packArgumentsArray)] | ||
unconstrained fn pack_arguments_array_oracle<let N: u32>(_args: [Field; N]) -> Field {} | ||
/// Notifies the simulator that `args` will later be used at some point during execution, referenced by their hash. This | ||
/// allows the simulator to know how to respond to this future request. | ||
/// | ||
/// This is only used during private execution, since in public it is the VM itself that keeps track of arguments. | ||
pub fn pack_arguments(args: [Field]) { | ||
// This oracle call returns nothing: we only call it for its side effects. It is therefore always safe to call. When | ||
// unpacking however the caller must check that the returned value is indeed the preimage. | ||
unsafe { | ||
pack_arguments_oracle_wrapper(args) | ||
}; | ||
} | ||
|
||
#[oracle(packArguments)] | ||
unconstrained fn pack_arguments_oracle(_args: [Field]) -> Field {} | ||
/// Same as `pack_arguments`, but using arrays instead of slices. | ||
pub fn pack_arguments_array<let N: u32>(args: [Field; N]) { | ||
// This oracle call returns nothing: we only call it for its side effects. It is therefore always safe to call. When | ||
// unpacking however the caller must check that the returned value is indeed the preimage. | ||
unsafe { | ||
pack_arguments_array_oracle_wrapper(args) | ||
}; | ||
} | ||
|
||
/// - Pack arguments (array version) will notify the simulator that these arguments will be used later at | ||
/// some point in the call. | ||
/// - When the external call is made later, the simulator will know what the values unpack to. | ||
/// - This oracle will not be required in public vm functions, as the vm will keep track of arguments | ||
/// itself. | ||
unconstrained pub fn pack_arguments_array<let N: u32>(args: [Field; N]) -> Field { | ||
pack_arguments_array_oracle(args) | ||
unconstrained fn pack_arguments_oracle_wrapper(args: [Field]) { | ||
let _ = pack_arguments_oracle(args); | ||
} | ||
|
||
/// - Pack arguments (slice version) will notify the simulator that these arguments will be used later at | ||
/// some point in the call. | ||
/// - When the external call is made later, the simulator will know what the values unpack to. | ||
/// - This oracle will not be required in public vm functions, as the vm will keep track of arguments | ||
/// itself. | ||
unconstrained pub fn pack_arguments(args: [Field]) -> Field { | ||
pack_arguments_oracle(args) | ||
unconstrained fn pack_arguments_array_oracle_wrapper<let N: u32>(args: [Field; N]) { | ||
let _ = pack_arguments_array_oracle(args); | ||
} | ||
|
||
#[oracle(packArguments)] | ||
unconstrained fn pack_arguments_oracle(_args: [Field]) -> Field {} | ||
|
||
#[oracle(packArgumentsArray)] | ||
unconstrained fn pack_arguments_array_oracle<let N: u32>(_args: [Field; N]) -> Field {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.