chore: Refactor epilogue to run as much code as possible before fees are computed #1698
Merged
chore: Refactor epilogue to run as much code as possible before fees are computed #1698
Conversation
bobbinth
approved these changes
Aug 7, 2025
Contributor
bobbinth
left a comment
There was a problem hiding this comment.
Looks good! Thank you! I left a few small comments inline.
Also, I wonder how this changes our current estimate of the "cycles after fee computed" - but maybe we can check this in future PRs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Refactors the epilogue to run as much code as possible before fees are computed. The motivation is that every operation that runs after
compute_feehas to be included in the total cycle count determined bycompute_feeand so we have to calculate them. Therefore, making this as simple as possible is a high priority.Changes
compute_feewhich makes it possible to compute the number of cycles that section takes.new_nonce > old_noncecheck, because we're already checking this in the account delta computation by asserting that if the nonce wasn't incremented, storage and vault delta must be empty. This allows us to move this check before compute_fee as well, as it no longer depends on having theFINAL_ACCOUNT_COMMITMENT.compute_fee.compute_feeand so the account vault state that is set as the initial output vault still hasFEE_ASSETin it. Since we're not movingFEE_ASSETto an output note, we don't have to account for it in the output vault at all and the asset preservation check is essentially bypassed. That's a bit subtle, but I've added comments to explain this where it made sense.Follow-up:
account::compute_current_storage_commitment. That way, we can pre-compute this value beforecompute_feeis called, and when we call it again as part ofaccount::compute_current_commitment(to compute the final account commitment) we are guaranteed to hit the cached value because storage doesn't change as part of the fee code. That should make it possible to statically compute the number of cycles thataccount::compute_current_commitmentwill take. Wanted to double-check that this is fine to do.account_delta::compute_commitmentbeforecompute_feeas well, but this has additional implications mentioned in Calculate number of cycles aftercompute_fee#1688, so that will be part of a follow-up PR.With that, all other code that runs after
compute_feeare simple instructions, and so computing the number of cycles should be much easier than before.part of #1688