poc(miden): support a counter contract #1836
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is a proof of concept for supporting a counter contract in Miden Assembly (masm).
Some interesting notes:
1- In Miden, each instruction either expects some input on the stack or takes an argument or both. To support this behavior, I added a
miden_stackvariable inControlFlowGraphof each function, and updated it accordingly in eachExpressionorInstr2- Storage in Miden is not initialized by the contract, the contract only references already existing storage (initialized by the miden client while creating the contract account). In Solang, each storage variable is assgined a
slot. now Solang's built inStorage initalizeronly emits var names with this format:const.STORAGE_SLOT_0=0in which this references the first storage index pre-defined by the account.3- To try this out, create a file named "counter.sol" and insert this code:
Then, compile via:
solang compile counter.sol --target miden --releaseYou then should see the
.masmfile which would look like:To deploy and interact with it, the most straightforward way is miden's rust client:
https://github.com/0xMiden/miden-tutorials/blob/main/rust-client/src/bin/counter_contract_increment.rs