feat: New Instruction addi
"Add-Immediate"
#313
Merged
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 adds an instruction
addi
which takes an immediate argument and adds it to the top of the stack. This addresses a pattern identified by @aszepieniec but with a different solution. The main motivation is to anticipate computing the AIR circuits on an out-of-domain row located at a dynamically known address. The merits of this PR should be considered in combination of future PRs that accomplish that feat.The word dynamic is key, because the current auto-generated tasm code hardcodes the location of the out-of-domain row to a statically known address. While that solution is more efficient in terms of tasm instruction count, it is also less versatile. In particular, it requires static memory layouts for all proofs to be verified by a program. This requirement makes certain patterns impossible, such as verifying proofs in a dynamic loop.
This instruction reduces the cost of switching to dynamic out-of-domain row locations.
In order to get the right address on top of the stack:
push [static_address]
dup x push [static_offset] add
dup x addi [static_offset]