feat(aztec-nr): add call_self stubs for utility functions#22885
Conversation
| 1 | ||
| } else { | ||
| x * self.call(NestedUtility::at(self.address).pow_utility(x, n - 1)) | ||
| x * self.call_self.pow_utility(x, n - 1) |
There was a problem hiding this comment.
All the previous code, just to do this 😅
| // not allow passing `&mut PrivateContext` (held by `ContractSelfPrivate`) into unconstrained code. | ||
| // This struct holds no mutable references, so it can be passed freely into `unconstrained` | ||
| // functions. | ||
| pub struct ContractPrivateUtility<CallSelfUtility> { |
There was a problem hiding this comment.
The only thing I am unsure about in this PR is the name of this struct. It's purpose is to essentially group call_self and call (that I assume will be added in the future) such that we can have the self.utility.call_self and self.utility.call API.
AI feedback:
I agree that PrivateUtilityCalls is nice. If you agree with the rename would drop "gateway" from the docs as it feels like unnecessarily introduced complex term there (we don't use gateway anywhere else in this context).
There was a problem hiding this comment.
I initially called it PrivateUtilityCalls, but then moved to ContractPrivateUtility for two reasons:
- Consistency with
ContractSelfPrivate,ContractSelfPublic,ContractSelfUtility - Because even though it currently only contains
call_selfandcallproperties, I though that maybe in the future theself.utilityproperty might contain something else
I can go back to PrivateUtilityCalls if you prefer, but wanted to share my thought process. But I will remove "gateway" though
There was a problem hiding this comment.
Consistency with ContractSelfPrivate, ContractSelfPublic, ContractSelfUtility
Those structs are quite a different thing so having the name consistent with it doesn't make sense (those structs contain a bunch of complex stuff while this is only a simple wrapper around call and call_self for utility functions).
Because even though it currently only contains call_self and call properties, I though that maybe in the future the self.utility property might contain something else
I can't think of anything we would want to put on the struct so unless you have something in mind would not optimize for that scenario.
| /// unsafe { self.utility.call_self.some_utility_function(args) } | ||
| /// ``` | ||
| pub call_self: CallSelfUtility, | ||
| } |
There was a problem hiding this comment.
Do we have some issue that tracks calling of utility functions on other contracts? (that would lead to introduction of pub call here?)
I think it makes sense to link it here since as it currently stands this struct seems a bit redundant (like why not just have self.call_utility if there is nothing else but call_self on the struct?).
There was a problem hiding this comment.
We had to add the .utility struct in #22822 because of the following (it's documented a few lines above):
// Implemented as a separate struct (rather than inlined in ContractSelfPrivate) because Noir does
// not allow passing `&mut PrivateContext` (held by `ContractSelfPrivate`) into unconstrained code.
// This struct holds no mutable references, so it can be passed freely into `unconstrained`
// functions.
We currently support self.utility.call, but I wanted to add self.utility.call_self() stub for consistency with other contexts. Also, we currently only support same-contract utility calls, but we want to add cross-contract utility calls with F-29
|
I created F-627 to document everything, since we need to iron out some details |
Rename the `CallSelfUtility` type parameter to `CallSelf` to match the same type used in `ContractSelfUtility`, and update doc comments for clarity.
Co-authored-by: Jan Beneš <janbenes1234@gmail.com>
|
✅ Successfully backported to backport-to-v4-next-staging #22924. |
BEGIN_COMMIT_OVERRIDE chore: fix kv-store browser tests hangs (AztecProtocol#22721) feat: kv-store sqlite backend with page level encryption (AztecProtocol#22759) fix: install node 22 for aztec-cli acceptance test (AztecProtocol#22917) fix(kv-store): exclude @aztec/sqlite3mc-wasm from vitest optimizeDeps (AztecProtocol#22929) feat(txe): add tx private logs to tx side effects oracle (AztecProtocol#22889) feat(aztec-nr): add call_self stubs for utility functions (AztecProtocol#22885) END_COMMIT_OVERRIDE
BEGIN_COMMIT_OVERRIDE docs: add map and state variable docs (#22824) fix: e2e compat should not fail for contracts added after legacy stables (#22900) chore: fix kv-store browser tests hangs (#22721) feat: kv-store sqlite backend with page level encryption (#22759) fix: install node 22 for aztec-cli acceptance test (#22917) feat: backport kv-store sqlite encryption (#22759) to v4-next (#22927) fix(docs): correct llms.txt links for versioned developer docs (#22819) feat(docs): improve discoverability of Aztec.nr API reference docs (#22861) feat(docs): backport improve discoverability of Aztec.nr API reference docs (#22861) to v4-next (#22931) feat(aztec-nr): add call_self stubs for utility functions (#22885) docs: add map and state variable docs (backport #22824) (#22880) refactor: `getPackageVersion` fn cleanup (#22941) fix(ci): skip acceptance test for canary -commit. tags (#22951) fix: closing db, correct stub side effects (#22939) END_COMMIT_OVERRIDE
Summary
CallSelfUtilityandcreate_utility_self_call_stubso contracts can call their own utility functions viaself.call_self.fn()(from utility context) andself.utility.call_self.fn()(from private context), mirroring the existingcall_selfpattern for private functions.Fixes F-622