Skip to content
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

feat(AztecMacro): Let function convey mutability #6078

Closed
Tracked by #5077
LHerskind opened this issue Apr 29, 2024 · 3 comments · Fixed by #6338
Closed
Tracked by #5077

feat(AztecMacro): Let function convey mutability #6078

LHerskind opened this issue Apr 29, 2024 · 3 comments · Fixed by #6338

Comments

@LHerskind
Copy link
Contributor

LHerskind commented Apr 29, 2024

Currently it is not possible for a function to convey to other contracts, that it will not be manipulating state, e.g., that it should be called using a static_call.

It is currently the burden of the caller, to do a static_call when needed, instead of a call.

This means that for contract such as a token, other contracts that need to fetch a balance on that token, must explicitly use a static_call instead of having the interface it uses know that it should be static, if the contract was defined as

#[aztec(static)]
#[aztec(public)]
fn balance_of(owner: AztecAddress) -> U128;

Allowing this data to be easily conveyed makes it much less error prone to build on top, as it is now just required to remember the static at the interface, instead at every time you will make a call.

If a call is made to some user provided "token", and it is not static pain ensures as it could really be calling anything, and the control flow is passed on.

@github-project-automation github-project-automation bot moved this to Todo in A3 Apr 29, 2024
This was referenced Apr 29, 2024
@rahul-kothari
Copy link
Contributor

rahul-kothari commented Apr 29, 2024

Love the idea! I think it is needed but I wonder if there is a better name? I feel like the name should align with whatever is used on AztecjS side

@fcarreiro
Copy link
Contributor

Nice. Would it be possible to limit static (contract) methods to only (external) call other static methods at compile time?

@Thunkar
Copy link
Contributor

Thunkar commented May 10, 2024

Nice. Would it be possible to limit static (contract) methods to only (external) call other static methods at compile time?

@fcarreiro it is very tricky to do at compile time since we don't have "storage modification opcodes", we just push stuff to the context inputs. However the way I've implemented it in #6338 only generates "Static" versions of the CallInterfaces for the functions that are marked as #[aztec(view)], so if users try to use the .call(&mut context) versions, they'll get a compile time error. Nothing prevents them from trying to do a low-level call, that will fail at runtime.

Thunkar added a commit that referenced this issue May 20, 2024
Closes #6078

Introduces the `#[aztec(view)]` (open to different naming, @spalladino
@rahul-kothari ) modifier to functions, that forces them to be executed
in an static context. It also forces generation of a "static only"
`CallInterface` for them, trying to spare users from making regular
calls to them.

~~Need input from the AVM team (@dbanks12 @fcarreiro) on how to
implement the concept in the AVMContext.~~

In order to support direct simulated calls to view functions, the
simulate method has been modified to go through the account entrypoint,
which has led to implementing retrieval of return values through the
whole callstack instead of just taking the latest one.

Also adds the ability to navigate from contract interfaces to their
implementations via LSP!

---------

Co-authored-by: dbanks12 <david@aztecprotocol.com>
@github-project-automation github-project-automation bot moved this from Todo to Done in A3 May 20, 2024
signorecello pushed a commit that referenced this issue May 20, 2024
Closes #6078

Introduces the `#[aztec(view)]` (open to different naming, @spalladino
@rahul-kothari ) modifier to functions, that forces them to be executed
in an static context. It also forces generation of a "static only"
`CallInterface` for them, trying to spare users from making regular
calls to them.

~~Need input from the AVM team (@dbanks12 @fcarreiro) on how to
implement the concept in the AVMContext.~~

In order to support direct simulated calls to view functions, the
simulate method has been modified to go through the account entrypoint,
which has led to implementing retrieval of return values through the
whole callstack instead of just taking the latest one.

Also adds the ability to navigate from contract interfaces to their
implementations via LSP!

---------

Co-authored-by: dbanks12 <david@aztecprotocol.com>
AztecBot pushed a commit to AztecProtocol/barretenberg that referenced this issue May 21, 2024
Closes AztecProtocol/aztec-packages#6078

Introduces the `#[aztec(view)]` (open to different naming, @spalladino
@rahul-kothari ) modifier to functions, that forces them to be executed
in an static context. It also forces generation of a "static only"
`CallInterface` for them, trying to spare users from making regular
calls to them.

~~Need input from the AVM team (@dbanks12 @fcarreiro) on how to
implement the concept in the AVMContext.~~

In order to support direct simulated calls to view functions, the
simulate method has been modified to go through the account entrypoint,
which has led to implementing retrieval of return values through the
whole callstack instead of just taking the latest one.

Also adds the ability to navigate from contract interfaces to their
implementations via LSP!

---------

Co-authored-by: dbanks12 <david@aztecprotocol.com>
AztecBot pushed a commit to AztecProtocol/aztec-nr that referenced this issue May 21, 2024
Closes AztecProtocol/aztec-packages#6078

Introduces the `#[aztec(view)]` (open to different naming, @spalladino
@rahul-kothari ) modifier to functions, that forces them to be executed
in an static context. It also forces generation of a "static only"
`CallInterface` for them, trying to spare users from making regular
calls to them.

~~Need input from the AVM team (@dbanks12 @fcarreiro) on how to
implement the concept in the AVMContext.~~

In order to support direct simulated calls to view functions, the
simulate method has been modified to go through the account entrypoint,
which has led to implementing retrieval of return values through the
whole callstack instead of just taking the latest one.

Also adds the ability to navigate from contract interfaces to their
implementations via LSP!

---------

Co-authored-by: dbanks12 <david@aztecprotocol.com>
superstar0402 added a commit to superstar0402/aztec-nr that referenced this issue Aug 16, 2024
Closes AztecProtocol/aztec-packages#6078

Introduces the `#[aztec(view)]` (open to different naming, @spalladino
@rahul-kothari ) modifier to functions, that forces them to be executed
in an static context. It also forces generation of a "static only"
`CallInterface` for them, trying to spare users from making regular
calls to them.

~~Need input from the AVM team (@dbanks12 @fcarreiro) on how to
implement the concept in the AVMContext.~~

In order to support direct simulated calls to view functions, the
simulate method has been modified to go through the account entrypoint,
which has led to implementing retrieval of return values through the
whole callstack instead of just taking the latest one.

Also adds the ability to navigate from contract interfaces to their
implementations via LSP!

---------

Co-authored-by: dbanks12 <david@aztecprotocol.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants