Replies: 1 comment 5 replies
-
|
As far as code updates go, I think there are a few things to think through:
|
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This discussion is started to... well, discuss two things:
How is the account code being updated right now
The general rule which is followed during the transaction is that the code commitment stored in the account data block could be changed only in the epilogue, after all the user code has been executed (as opposed to the other commitments which could be updated during the execution).
In fact we have only two actual values for the code commitment: it is
NEW_CODE_ROOTstored in the bookkeeping section and theACCOUNT_CODE_COMMITMENTstored in the account data block.In
memory.masmfile we have the following getter/setter pairs:get_new_acct_code_commitment+set_new_acct_code_commitment-> work with theNEW_CODE_ROOTvalue.get_acct_code_commitment+set_acct_code_commitment-> work with the code commitment in the account data block.get_init_account_code_commitment(set_acct_code_commitmentprocedure is used as a setter here) -> work with the code commitment in the account data block.Note
Since the code commitment could be updated only in the epilogue, the getters and setters for the current and initial values are doing exactly the same, returning the exact same value.
The user facing API (in
miden::account) consists of two procedures:get_initial_code_commitmentandget_code_commitment, which return the same value from the account data block. Ourapi.masmfile contains two corresponding procedures for them. For now user doesn't have an ability to modify the account code and, hence, obtain the "current" code commitment.The pipeline of the code update looks like so:
prologue.masmwe set the new code commitment (NEW_CODE_ROOT) to the value from the current (initial) code commitment (ACCOUNT_CODE_COMMITMENT), making the new code commitment to have an initial commitment as a "default" value.account::set_codeprocedure. Looks like inside this procedure the new code commitment had to be calculated and theNEW_CODE_ROOThad to be set to this newly computed value. TheACCOUNT_CODE_COMMITMENTvalue remains unchanged.epilogue.masmduring the transaction finalization we update the code commitment: we set the code commitment form the account data block (ACCOUNT_CODE_COMMITMENT) to the potentially updated new code commitment (NEW_CODE_ROOT), so that the new code commitment will be initial in the next transaction.Refactor proposals
1. Update the
NEW_CODE_ROOTIMO it will be less confusing if we leave only the "initial" and "current" commitment notions, so the
NEW_CODE_ROOTcould become theCURRENT_CODE_ROOT(with the renaming of the corresponding getters/setters) — it will contain the latest code commitment and will be updated the same way as the account storage commitment (using the caching feature with the dirty flag).2. Merge the "initial" and the "current" procedures
The procedures, which now have "Initial" and "current" meaning (but essentially doing the same) should be merged so that there will be only one pair of the "initial" getters/setters in the memory and just one "initial" getter in the API (
CURRENT_CODE_ROOTwill play the role of the "current" value instead).The saddest thing here is that everything I wrote above could be useless, since any idea of how can we implement the code update I have will require to rework this setup.
For now the biggest (probably stupid) question is why do we have to preserve the account code commitment in the account data block during the transaction? I think understanding of this rule will help me to understand what else could be reworked and what should remain the same.
Important
We should remember that because any account procedure potentially could have the access to the account storage, any addition/deletion/update of the procedure should be followed by the corresponding storage change.
Beta Was this translation helpful? Give feedback.
All reactions