-
Notifications
You must be signed in to change notification settings - Fork 60
zkvm: non-copyable Program, Expression and Constraint #304
Conversation
Can you add a test showing that a contract trying to duplicate a program fails? (The tests checking that normal transactions succeed will now check that normal program outputting succeeds, but there is no failure case check here). |
4acbb6d
to
56e394c
Compare
@cathieyun added tests for Program, Expression and Constraint. Expanded the scope of this PR to extend to Expressions and Constraints. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several minor suggestions, spec changes look 💯 overall. (Have not closely reviewed the code changes.)
|
||
|
||
### Data type | ||
|
||
A _data type_ is a variable-length byte array used to represent signatures, proofs and programs. | ||
A _data type_ is a variable-length byte array used to represent [commitments](#pedersen-commitment), [scalars](#scalar), signatures and proofs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repeating some feedback from an earlier round of review on this spec: "type" is being used in a confusing way here. You can talk about "the data type" or "an instance of type data" but not "a data type." Consider:
An object of the data type is a variable-length byte array...
(Same thing with "program type" below.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about renaming it into String
in some other PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds great. 👍
@@ -1298,29 +1314,33 @@ Fails if the `prevoutput` is not a [data type](#data-type) with exact encoding o | |||
_items... predicate_ **output:_k_** → ø | |||
|
|||
1. Pops [`predicate`](#predicate) from the stack. | |||
2. Pops `k` items from the stack. | |||
2. Pops `k` [portable items](#portable-types) from the stack. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the top k
items includes a non-portable item, is that an error or is it skipped? I know you intend it to be an error, but I think it's a little ambiguous as written.
I think the original wording ("Pops k
items from the stack") plus the new "fails if" text below is fine.
|
||
|
||
#### contract | ||
|
||
_items... pred_ **contract:_k_** → _contract_ | ||
|
||
1. Pops [predicate](#predicate) `pred` from the stack. | ||
2. Pops `k` items from the stack. | ||
2. Pops `k` [portable items](#portable-types) from the stack. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment.
@@ -1362,45 +1382,47 @@ _contract(P) proof prog_ **call** → _results..._ | |||
7. Places the [payload](#contract-payload) on the stack (last item on top). | |||
8. Set the `prog` as current. | |||
|
|||
Fails if the top two items are not [data](#data-type) or the third from top is not a [contract](#contract-type). | |||
Fails if: | |||
1. `prog` is not a [program type](#program-type), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment about "a program type," "a data type," and "a contract type." I'd much prefer "a program," "a data item," and "a contract."
Co-Authored-By: Bob Glickstein <bobg@users.noreply.github.com>
This adds a non-copyable type
Program
which is separate fromData
type. Instructionscall
anddelegate
expect Program type, instructiondup
fails if used with a Program.Also, the
Expression
andConstraint
are made non-copyable and non-droppable. Variables are left to be copyable, so they can participate in constraints and then be used in the construction of Values.Rationale is covered in #301 & #306.
Closes #301
Closes #306