-
Notifications
You must be signed in to change notification settings - Fork 292
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(StateVariables): Ensure that immutable state vars can only be initialized at deployment #4738
Comments
@LHerskind in both of the approaches I don't like that a user would have to manually trigger the populate_is_constructor() function or define the macro. It feels like it's something which should be handled automatically. Is there some reason why we would not internally store in context is_deployment_populated variable which would get used in the context.is_deployment() function to determine whether to perform the check or not? (then we would internally store the is_deployment value as well and set is_deployment_populated to true so that in the next call we don't perform the check). |
We could trigger it whenever, was just that it feels wasteful to do a lot of extra checks if it is just the same. For the case of "are we in constructor" we need to check both membership and non-membership, if we assert one or the other we can get away with just one of them. Right now we are always asserting that it is initialized and the If we want to pass it on, we need to alter the kernels to only pass it along if it is the same contract you are making a call to, e.g., would be a pain if I can deploy, and while in that deployment make calls to other contracts as if I was inside their constructors. |
Will benefit from #5336 |
Closing this one. @nventuro argued that we should allow it to be set whenever, as long as it is not reset. I don't care enough about it, so I'm fine with that, the only real case that made pain between our approaches is maps of immutables which don't seem like something you see often so I'm closing this for now. |
Gets rid of references to #4738 as it is dropped.
Currently it's not enforced that
initialize
methods of immutable state vars are called only during deployment from functions of the deployed contract.We essentially want to add
is_deployment()
function to private and public contexts that returns whether the contract whose address can be obtained viacontext.this_address()
is currently being deployed or is already deployed.This method would then be used from all the initialize methods of immutable vars to assert that we are deploying.
As far as I(@LHerskind) see it, we have two directions to implement this
#[aztec(in_constructor)]
which checks whether we are in the constructor, and make a newis_constructor()
on the context which returns this value.is_constructor()
itself perform the check.The benefit of the macro would be that it can be done more efficiently as we can do just one computation and reuse it for all the other calls to
is_constructor
.I think the macro is the best solution.
As I see it you essentially have the following function:
To do things with
immutables
using public storage, you simple need to runpopulate_is_constructor()
before you try any initialization.Idea without macro:
And with macro:
This will also allow us to get rid of the "scratchmark" that we leave on storage to ensure it is not overwritten.
The text was updated successfully, but these errors were encountered: