Skip to content

feat: implement program hash integrity constraints for continuations - #373

Open
avorylli wants to merge 5 commits into
TritonVM:masterfrom
avorylli:av
Open

feat: implement program hash integrity constraints for continuations#373
avorylli wants to merge 5 commits into
TritonVM:masterfrom
avorylli:av

Conversation

@avorylli

@avorylli avorylli commented Sep 8, 2025

Copy link
Copy Markdown

Add mathematical constraints to prevent program hash overwriting via swap instructions when opstack size ≤ 21.

  • Prevents swap operations from targeting program hash elements (st11-st15) in shallow stacks
  • Provides formal constraint: swap_indicator · (n - 21) · indicator_{i≥11} = 0
  • Resolves TODO in TIP-0008 section (a) Program

@aszepieniec aszepieniec left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution.

The instructions pick and place, which were introduced after this note was written, likewise have the capacity to disturb the program hash. So they should be included also in swap_indicator.

$(n - 21)$ is positive when $n > 21$ (stack is deep enough to protect program hash)

I'm afraid I don't see how the factor $n-21$ activates the constraint when $n \leq 21$. Rather, it looks to me like it disactivates the constraint when $n = 21$ and activates it in all other cases.

I do see how the factor max(0, 21-n) achieves this purpose, but then the question is how to represent max as an arithmetic circuit of low degree.

Comment thread tips/tip-0008/tip-0008.md Outdated

Let $n$ be the current opstack size and let $i$ be the target index. The constraint is:

$$\text{stack\_manip\_indicator} \cdot (21 - n) \cdot \text{indicator}_{i \geq 11} = 0$$

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this constraint is not complete. Counterexample: the instruction is swap 15 when $n = 22$. The constraint evaluates to $P-1 \neq 0$ meaning that this particular instruction in this particular context is not allowed. But it should be allowed because when $n = 22$ there is no risk of disturbing the program hash.

Comment thread tips/tip-0008/tip-0008.md Outdated
Comment on lines +69 to +71
The indicator function $\text{indicator}_{n \leq 21}$ can be implemented as an arithmetic circuit of low degree using the fact that $n$ is bounded by the maximum stack size. Specifically, we can use the constraint:

$$\text{indicator}_{n \leq 21} = \prod_{k=22}^{n_{max}} (n - k)$$

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is correct now, but you've introduced another drawback: the maximum stack size is actually $P-1 = 2^{64} - 2^{32}$ which is huge when it is supposed to be a bound on the degree of an AIR constraint.

@avorylli

avorylli commented Sep 13, 2025

Copy link
Copy Markdown
Author

made it simpler, if you don't like it, then I could probably think of something else to improve the variant before

@jan-ferdinand

Copy link
Copy Markdown
Member

Frankly, I don't think protecting the program's hash digest against modification is necessary. In my mind, the entire program is executed by one entity. There is never any “execution handover”; for example, it is not possible to execute a different program as a subroutine of some sort (other than straight up incorporating that other program, then executing it, which means that it's not a different program).

Summarizing, with the threat model we're currently working with, I don't see additional protection we gain by disallowing write access to the program's hash digest.

In case I misunderstand your, @avorylli, intentions, would you mind opening an issue? There might be other possible solutions to discuss before deciding on a strategy to implement them.

@aszepieniec

Copy link
Copy Markdown
Collaborator

This PR attempts to fill in details in TIP-0008, which proposes a construction for continuations. In that context, there is a notion of handover of execution control between separate entities -- these entities each prove separate chunks of the long-running computation. So we do need to protect the program digest.

@jan-ferdinand

Copy link
Copy Markdown
Member

Oh, I see! I hadn't realized this was about continuations. Thanks for clarifying.

@jan-ferdinand jan-ferdinand reopened this Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants