-
Notifications
You must be signed in to change notification settings - Fork 240
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
Reduce constraint count of a function call #7092
Comments
I've been looking into this and I see that we call hash on private call stack item in 2 places:
And it looks that in the kernel it checks that the hash which traveled all the way from app circuit matches the computed hash. I would need a feedback from someone who knows the kernel's better to check whether we could optimize this. @iAmMichaelConnor do you have a clue here? If not I would wait for Alvaro to come back and bother him on Monday. I don't know this part of code that well. |
I think it's ok to hash just the When A calls B, a call stack item is a way to ensure consistency between the data A sent and consumed, and the data B received and returned. I don't think any of the other public inputs of function B are important to enable that check; just the It'd be great if @LeilaWang, you could validate that this optimisation works, and whether this change would conflict badly with the PR you're currently working on. |
It's a good idea! We only need to check
|
Good point re the data bus. Why can't the PrivateCallRequest be: struct PrivateCallRequest {
contract_address,
function_data, // not sure what's in here?
call_context,
// caller_context, // not this
args_hash,
returns_hash,
// start_side_effect_counter, // not this
// end_side_effect_counter, // not this
} I figured the other data that I've commented-out is available to the kernel circuit through other public inputs? |
They need to be in the call request because they are the data the caller expects in each nested call.
start and end counters: they need to be in the request because the caller has to enforce the counter range of a nested call, which affects the order of the side effects from the caller and from the nested call. If they are not checked, then I can basically move a nested call, i.e. I can pretend a child function is called after the caller's 3rd side effect instead of the 1st. |
@LeilaWang, for public calls, we are currently hashing As part of #7285, I use pedersen_hash([
self.contract_address.to_field(),
self.public_inputs.call_context.hash(),
self.function_data.hash(),
self.public_inputs.args_hash,
self.public_inputs.returns_hash,
self.public_inputs.start_side_effect_counter as Field,
self.public_inputs.end_side_effect_counter as Field,
], GENERATOR_INDEX__CALL_STACK_ITEM) for the private call stack item hash. And for public I was thinking that: std::hash::pedersen_hash_with_separator([
item.contract_address.to_field(),
item.public_inputs.call_context.hash(),
item.function_data.hash(),
item.public_inputs.args_hash,
item.public_inputs.returns_hash,
item.public_inputs.start_side_effect_counter as Field,
item.public_inputs.end_side_effect_counter as Field,
item.public_inputs.start_gas_left.da_gas as Field,
item.public_inputs.start_gas_left.l2_gas as Field,
item.public_inputs.end_gas_left.da_gas as Field,
item.public_inputs.end_gas_left.l2_gas as Field,
], GENERATOR_INDEX__CALL_STACK_ITEM) Should do the job. Very similar values, mainly with the gas values as well, but I don't know if they are actually needed like this. I don't really know about something like the hashes etc. But maybe you or @dbanks12 would be able to provide more data on if this is a fair change? With both changes and the argshash size change the entrypoint goes all the way down to 125K 😎 |
For public call, we don't need to include:
|
Pasting my comment from slack:
A function call adds 200k constraints to an app circuit? That's surprising.
Edit: ok I've looked at the code and can see it's hashing all fields of a flattened PrivateCircuitPublicInputs. (Links in reverse order)
aztec-packages/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr
Line 53 in d4921a0
aztec-packages/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_call_stack_item.nr
Line 59 in d4921a0
aztec-packages/noir-projects/aztec-nr/aztec/src/context/private_context.nr
Line 488 in d4921a0
I can think of some potential optimisations:
cc @LeilaWang @LHerskind - not sure whose remit this falls under :)
The text was updated successfully, but these errors were encountered: