Skip to content

feat(aztec-nr): add call_self stubs for utility functions#22885

Merged
nchamo merged 6 commits into
merge-train/fairiesfrom
feat/utility-call-self
May 4, 2026
Merged

feat(aztec-nr): add call_self stubs for utility functions#22885
nchamo merged 6 commits into
merge-train/fairiesfrom
feat/utility-call-self

Conversation

@nchamo
Copy link
Copy Markdown
Contributor

@nchamo nchamo commented Apr 30, 2026

Summary

  • Adds CallSelfUtility and create_utility_self_call_stub so contracts can call their own utility functions via self.call_self.fn() (from utility context) and self.utility.call_self.fn() (from private context), mirroring the existing call_self pattern for private functions.
  • Builds on nested utility call support from feat(pxe): support nested utility function calls #22822.

Fixes F-622

@nchamo nchamo requested a review from nventuro as a code owner April 30, 2026 17:16
@nchamo nchamo self-assigned this Apr 30, 2026
1
} else {
x * self.call(NestedUtility::at(self.address).pow_utility(x, n - 1))
x * self.call_self.pow_utility(x, n - 1)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the previous code, just to do this 😅

@nchamo nchamo requested review from benesjan and vezenovm April 30, 2026 18:01
Copy link
Copy Markdown
Contributor

@benesjan benesjan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. Great job!

Is there a plan to document this is docs? Should it be added to this PR?

Comment thread noir-projects/aztec-nr/aztec/src/contract_self/contract_self_private.nr Outdated
// 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> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Image

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_self and call properties, I though that maybe in the future the self.utility property 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just renamed it in 226d330

/// unsafe { self.utility.call_self.some_utility_function(args) }
/// ```
pub call_self: CallSelfUtility,
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@nchamo
Copy link
Copy Markdown
Contributor Author

nchamo commented May 4, 2026

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.
@nchamo nchamo requested a review from benesjan May 4, 2026 13:05
Copy link
Copy Markdown
Contributor

@benesjan benesjan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

Comment thread noir-projects/aztec-nr/aztec/src/contract_self/contract_self_private.nr Outdated
Comment thread noir-projects/aztec-nr/aztec/src/contract_self/contract_self_private.nr Outdated
Copy link
Copy Markdown
Contributor

@benesjan benesjan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

Co-authored-by: Jan Beneš <janbenes1234@gmail.com>
@nchamo nchamo enabled auto-merge (squash) May 4, 2026 16:11
@nchamo nchamo merged commit bfc6f6e into merge-train/fairies May 4, 2026
21 of 25 checks passed
@nchamo nchamo deleted the feat/utility-call-self branch May 4, 2026 16:32
@AztecBot
Copy link
Copy Markdown
Collaborator

AztecBot commented May 4, 2026

✅ Successfully backported to backport-to-v4-next-staging #22924.

chrismarino pushed a commit to chrismarino/aztec-packages that referenced this pull request May 5, 2026
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
AztecBot added a commit that referenced this pull request May 5, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants