-
Notifications
You must be signed in to change notification settings - Fork 295
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
chore: fixing @safety
warnings
#11094
base: master
Are you sure you want to change the base?
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
//@safety TODO(https://github.com/AztecProtocol/aztec-packages/issues/8985): Fix this. | ||
// WARNING: This is insecure and should be temporary! | ||
// The oracle repacks the arguments and returns a new args_hash. | ||
// new_args = [selector, ...old_args], so as to make it suitable to call the public dispatch function. | ||
// We don't validate or compute it in the circuit because a) it's harder to do with slices, and | ||
// b) this is only temporary. | ||
enqueue_public_function_call_internal( | ||
contract_address, | ||
function_selector, | ||
args_hash, | ||
counter, | ||
is_static_call, | ||
) |
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.
@fcarreiro this is an old issue from october that doesn't seem to have much activity or tracking - is there any blocker to getting this done?
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.
Maybe it's a good idea to add tracking, you are right. The pointed ticket is tracking something else which is considered done.
Regarding a solution: TBH IDK how to solve it, and currently the AVM team is quite busy with other stuff. IDK if we'd be able to come back to this until just after Ignition (especially since it's not really an AVM thing).
Possible solutions: (1) The easy way to make this secure, IIRC, is to constrain the hashes there in place. Something like assert(old_hash == hash([a,b,c]))
and assert(new_hash == hash([selector,a,b,c])
. This would blow up the constraints and when I was doing this everyone was chipping away constraints so I thought it wouldn't fly.
(2) Something that I tried was to change the the private interfaces (macros) and call methods to take a slice. Then I could do the same as I did in public. This didn't work because sizes need to be known at comptime sadly.
(3) The other possible solution (more elegant from some PoV and less from other) is to change all the users of the "call with hash" method to include the selector themselves. IIRC from a discussion with Palla, the major offenders and only real need for passing the hash are the contract (?) entry points which then kind of call other functions with an already given set of params. Selectors are now an aztec-nr/js only concept but IIRC then it would be ok to change the JS code to insert the selector appropiately.
This is all from the top of my mind so there might be mistakes. Please add that info if you create a ticket, thanks!
is_static_call, | ||
); | ||
let args_hash = unsafe { | ||
//@safety TODO(https://github.com/AztecProtocol/aztec-packages/issues/8985): Fix this. |
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.
Can we add some whitespace and do // @safety
? It looks very odd otherwise
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.
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.
@@ -95,7 +95,7 @@ fn __derive_generators<let N: u32, let M: u32>( | |||
// Same as from_field but: | |||
// does not assert the limbs are 128 bits | |||
// does not assert the decomposition does not overflow the EmbeddedCurveScalar | |||
fn from_field_unsafe(scalar: Field) -> EmbeddedCurveScalar { | |||
pub fn from_field_unsafe(scalar: Field) -> EmbeddedCurveScalar { |
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 don't think the Noir team would necessarily be happy about exposing this in their stdlib - did you check with them?
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.
No, decided to go ahead and then tag Tom for a review as the change is easy to revert.
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 would prefer to keep this as an internal implementation detail to the stdlib. If you need something similar then you can vendor it into aztec-nr.
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 would require me to copy not only from_field_unsafe
but also compute_decomposition which seems like quite a lot of code to copy and I feel like it does not really belong to Aztec.nr (it feels too low-level).
But maybe we could make the API std nicer by moving the from_field_unsafe
func to EmbeddedCurveScalar
just like was done for from_field?
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.
compute_decomposition is a very small function though?
Regardless, the noir stdlib is a very conservative library as breaking changes are a breaking change to the language itself. We're not going to be exposing this function oublically for that reason.
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.
@TomAFrench As you please. I will revert this change as the scope of the PR is already quite big and don't want to make it bigger.
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.
Regardless, the noir stdlib is a very conservative library as breaking changes are a breaking change to the language itself.
I feel like in this case this might not be that big of a deal because we are exposing the function and if we did the change I proposed we would be moving a function which was not intended for external use. So the breaking change would be only for users that used the func anyway just like we did in aztec-packages.
I would also argue that us needing this function is a good sign that it's desirable to expose.
But the best approach might be to just change the API such that we don't need the function. Which could be done by having an MSM func that takes in the values from the smaller field and then does the conversion on its own. This would also improve safety since we rely on MSM to constrain the limbs.
@TomAFrench WDYT?
d579beb
to
e29c345
Compare
e29c345
to
26d8be5
Compare
noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/scheduled_delay_change.nr
Outdated
Show resolved
Hide resolved
Merging master as I want to check if failures in another branch are from master. |
50c83c0
to
d9308ca
Compare
noir-projects/noir-protocol-circuits/crates/types/src/constants.nr
Outdated
Show resolved
Hide resolved
noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/sort_by_counter.nr
Outdated
Show resolved
Hide resolved
noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/get_sorted_tuple.nr
Outdated
Show resolved
Hide resolved
...oir-protocol-circuits/crates/types/src/utils/arrays/assert_split_transformed_value_arrays.nr
Outdated
Show resolved
Hide resolved
noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays.nr
Outdated
Show resolved
Hide resolved
noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays.nr
Outdated
Show resolved
Hide resolved
noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays.nr
Outdated
Show resolved
Hide resolved
noir-projects/noir-protocol-circuits/crates/types/src/utils/arrays/assert_combined_array.nr
Outdated
Show resolved
Hide resolved
...ates/types/src/utils/arrays/assert_exposed_sorted_transformed_value_array/get_order_hints.nr
Outdated
Show resolved
Hide resolved
9461346
to
48fb467
Compare
ca3ec19
to
35f4b12
Compare
Aztec.nr
and protocol circuits @safety
warnings
35f4b12
to
b7b7b66
Compare
Aztec.nr
and protocol circuits @safety
warnings@safety
warnings
Note that the format of safety comments is in the process of changing. |
@TomAFrench @nventuro could I get an approval here or are we waiting for new Noir sync? I've already addressed all of Nico's comments here and it now contains only safety warnings so I think this should be fine to merge. I am having too many PRs open... |
c9df6c8
to
7e6e87e
Compare
As soon as ci is unfucked we're going to be merging a change to the safety comment format so i think we should either hold off until that's in or just preemptively switch to the new format . |
The new comment format is now in Aztec packages |
e1f8440
to
fc91f1f
Compare
Sets the L1 tx utils timeout to the end of the L2 slot.
3e094bc
to
80d9ab4
Compare
Fixes #11087
Note for reviewer
I originally addressed a bunch of other stuff in this PR but as @nventuro pointed out it became too messy so I separated those changes into a PR up the stack.
Merging currently blocked by this nargo fmt bug