Skip to content

Commit d0beb6d

Browse files
committed
Merge branch 'main' into feat/dummy-signed-pod
2 parents 5743e29 + 3ea0d5b commit d0beb6d

File tree

29 files changed

+874
-549
lines changed

29 files changed

+874
-549
lines changed

book/src/custom.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ On the backend, custom predicates are defined in _groups_. A group can contain
1414

1515
The definition of a custom predicate might also be called an _operation_ or _deduction rule_. It includes two (or, potentially, say, five) statement templates as conditions. The arguments to the statement templates are decomposed as (origin, key) pairs: if statements are allowed to have arity at most 4, then the statement templates in a deduction rule will have at most 8 arguments (4 origins and 4 keys). The same holds for the output statement.
1616

17-
Each argument (origin or key) to an statement template is either a wildcard or a literal. In the backend, the wildcard arguments will be identified as *1, *2, *3, ....
17+
Each argument (origin or key) to an statement template is either a wildcard or a literal. In the backend, the wildcard arguments will be identified as ?1, ?2, ?3, ....
1818

1919
## Examples
2020

@@ -32,7 +32,7 @@ For a custom statement, the "reason" includes the following witnesses and verifi
3232
- the definition of the statement, serialized (see [examples](./customexample.md))
3333
- if the statement is part of a group, the definition of the full group, serialized
3434
- verify that the hash of the definition is the statement ID
35-
- the definition will have some number of "wildcards" (*1, *2, ...) as arguments to statement templates; a value for each wildcard must be provided as a witness (each will be either an origin ID or key)
35+
- the definition will have some number of "wildcards" (?1, ?2, ...) as arguments to statement templates; a value for each wildcard must be provided as a witness (each will be either an origin ID or key)
3636
- the circuit must substitute the claimed values for the wildcards, and the resulting statements (true statements with origins and keys) will appear as witnesses
3737
- the circuit must verify that all the input statement templates (with origins and keys) appear in the previous statements (in higher rows of the table)
3838
- the circuit also substitutes the claimed values for the wildcards in the output statement, and verifies that it matches the claimed output statement

book/src/customexample.md

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@
22
# Ethdos custom predicate, using binary AND and OR: example of a recursive group
33

44
```
5-
eth_dos_distance(src_or, src_key, dst_or, dst_key, distance_or, distance_key) = or<
6-
eth_dos_distance_ind_0(src_or, src_key, dst_or, dst_key, distance_or, distance_key),
7-
eth_dos_distance_base(src_or, src_key, dst_or, dst_key, distance_or, distance_key)
8-
>
9-
10-
eth_dos_distance_base(src_or, src_key, dst_or, dst_key, distance_or, distance_key) = and<
11-
eq(src_or, src_key, dst_or, dst_key),
12-
ValueOf(distance_or, distance_key, 0)
13-
>
14-
15-
16-
eth_dos_distance_ind_0(src_or, src_key, dst_or, dst_key, distance_or, distance_key) = and<
17-
eth_dos_distance(src_or, src_key, intermed_or, intermed_key, shorter_distance_or, shorter_distance_key)
18-
19-
// distance == shorter_distance + 1
20-
ValueOf(one_or, one_key, 1)
21-
SumOf(distance_or, distance_key, shorter_distance_or, shorter_distance_key, one_or, one_key)
22-
23-
// intermed is a friend of dst
24-
eth_friend(intermed_or, intermed_key, dst_or, dst_key)
25-
>
5+
eth_dos_distance(src_or, src_key, dst_or, dst_key, distance_or, distance_key) = OR(
6+
eth_dos_distance_ind_0(?src_or, ?src_key, ?dst_or, ?dst_key, ?distance_or, ?distance_key),
7+
eth_dos_distance_base(?src_or, ?src_key, ?dst_or, ?dst_key, ?distance_or, ?distance_key)
8+
)
9+
10+
eth_dos_distance_base(src_or, src_key, dst_or, dst_key, distance_or, distance_key) = AND(
11+
Equal(?src_or[?src_key], ?dst_or[?dst_key]),
12+
ValueOf(?distance_or[?distance_key], 0)
13+
)
14+
15+
eth_dos_distance_ind_0(src_or, src_key, dst_or, dst_key, distance_or, distance_key, private: intermed_or, intermed_key, shorter_distance_or, shorter_distance_key, one_or, one_key) = AND(
16+
eth_dos_distance(?src_or, ?src_key, ?intermed_or, ?intermed_key, ?shorter_distance_or, ?shorter_distance_key)
17+
18+
// distance == shorter_distance + 1
19+
ValueOf(?one_or[?one_key], 1)
20+
SumOf(?distance_or[?distance_key], ?shorter_distance_or[?shorter_distance_key], ?one_or[?one_key])
21+
22+
// intermed is a friend of dst
23+
eth_friend(?intermed_or, ?intermed_key, ?dst_or, ?dst_key)
24+
)
2625
```
2726

2827
This group includes three statements.
@@ -31,10 +30,10 @@ When the definition is serialized for hashing, the statements are renamed to SEL
3130

3231
With this renaming and the wildcards, the first of the three definitions becomes:
3332
```
34-
SELF.1( *1, *2, *3, *4, *5, *6 ) = or<
35-
SELF.2( *1, *2, *3, *4, *5, *6 ) ,
36-
SELF.3( *1, *2, *3, *4, *5, *6 )
37-
>
33+
SELF.1(?1, ?2, ?3, ?4, ?5, ?6) = OR(
34+
SELF.2(?1, ?2, ?3, ?4, ?5, ?6)
35+
SELF.3(?1, ?2, ?3, ?4, ?5, ?6)
36+
)
3837
```
3938
and similarly for the other two definitions.
4039

book/src/custompred.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ The syntax of a custom operation is best explained with an example.
1111
Original example with anchored keys, origins, and keys.
1212
| Args | Condition | Output |
1313
|------------|-----------------------------------------|----|
14-
| pod: Origin, <br> good_boy_issuers: AnchoredKey::MerkleRoot, <br> receiver: AnchoredKey | ValueOf(AK(pod, "_type"), SIGNATURE), <br> Contains(good_boy_issuers, AK(pod,"_signer")), <br> Equals(AK(pod, "friend"), receiver) | GoodBoy(receiver, good_boy_issuers) |
14+
| pod: Origin, <br> good_boy_issuers: AnchoredKey::MerkleRoot, <br> receiver: AnchoredKey | ValueOf(?pod["_type"], SIGNATURE), <br> Contains(?good_boy_issuers, ?pod["_signer"]), <br> Equals(?pod["friend"], ?receiver) | GoodBoy(?receiver, ?good_boy_issuers) |
1515

1616
Compiled example with only origins and keys.
1717
| Args | Condition | Output |
1818
|------------|-----------------------------------------|----|
19-
| pod: Origin, <br> good_boy_issuers_origin: Origin, <br> good_boy_issuers_key: Key::MerkleRoot, <br> receiver_origin: Origin, <br> receiver_key: Key | ValueOf(AK(pod, "_type"), SIGNATURE), <br> Contains(AK(good_boy_issuers_origin, good_boy_issuers_key), AK(pod,"_signer")), <br> Equals(AK(pod, "friend"), AK(receiver_origin, receiver_key)) | GoodBoy(AK(receiver_origin, receiver_key), AK(good_boy_issuers_origin, good_boy_issuers_key)) |
19+
| pod: Origin, <br> good_boy_issuers_origin: Origin, <br> good_boy_issuers_key: Key::MerkleRoot, <br> receiver_origin: Origin, <br> receiver_key: Key | ValueOf(pod["_type"]), SIGNATURE), <br> Contains(?good_boy_issuers_origin[?good_boy_issuers_key], ?pod["_signer"]), <br> Equals(?pod["friend"], ?receiver_origin[?receiver_key]) | GoodBoy(?receiver_origin[?receiver_key]), ?good_boy_issuers_origin[?good_boy_issuers_key]) |
2020

2121
A custom operation accepts as input a number of statements (the `Condition`);
2222
each statement has a number of arguments, which may be constants or anchored keys; and an [anchored key](./anchoredkeys.md) in turn can optionally be decomposed as a pair of an Origin and a Key.
2323

24-
In the "original example" above, the anchored keys `good_boy_issuers` and `receiver` are not broken down, but `AK(pod, "_type"), AK(pod, "_signer"), AK(pod, "friend")` are. The purpose of breaking them down, in this case, is to force the three anchored keys to come from the same pod.
24+
In the "original example" above, the anchored keys `good_boy_issuers` and `receiver` are not broken down, but `?pod["_type"], ?pod["_signer"], pod["friend"]` are. The purpose of breaking them down, in this case, is to force the three anchored keys to come from the same pod.
2525

2626
In the "compiled example", all the anchored keys have been broken down into origins and keys.
2727

@@ -35,18 +35,18 @@ On the back end the "compiled example" deduction rule is converted to a sort of
3535

3636
| Args | Condition | Output |
3737
|------------|-----------------------------------------|----|
38-
| *1 (pod), <br> *2 (good_boy_issuers_origin), <br> *3 (good_boy_issuers_key), <br> *4 (receiver_origin), <br> *5 (receiver_key) | ValueOf(AK(*1, "_type"), SIGNATURE), <br> Contains(AK(*2, *3), AK(*1,"_signer")), <br> Equals(AK(*1, "friend"), AK(*4, *5)) | GoodBoy(AK(*4, *5), AK(*2, *3)) |
38+
| ?1 (pod), <br> ?2 (good_boy_issuers_origin), <br> ?3 (good_boy_issuers_key), <br> ?4 (receiver_origin), <br> ?5 (receiver_key) | ValueOf(?1["_type"]), SIGNATURE), <br> Contains(?2[?3], ?1["_signer"]), <br> Equals(?1["friend"], ?4[?5]) | GoodBoy(?4[?5], ?2[?3]) |
3939

4040
If you want to apply this deduction rule to prove a `GoodBoy` statement,
4141
you have to provide the following witnesses in-circuit.
4242

4343
- Copy of the deduction rule
44-
- Values for *1, *2, *3, *4, *5.
45-
- Copy of the three statements in the deduction rule with *1, *2, *3, *4, *5 filled in
44+
- Values for ?1, ?2, ?3, ?4, ?5.
45+
- Copy of the three statements in the deduction rule with ?1, ?2, ?3, ?4, ?5 filled in
4646
- Indices of the three statements `ValueOf`, `Contains`, `Equals` in the list of previous statements.
4747

4848
And the circuit will verify:
49-
- *1, *2, *3, *4, *5 were correctly substituted into the statements
49+
- ?1, ?2, ?3, ?4, ?5 were correctly substituted into the statements
5050
- The three statements `ValueOf`, `Contains`, `Equals` do indeed appear at the claimed indices.
5151

5252
[^operation]: In previous versions of these docs, "operations" were called "deduction rules".

0 commit comments

Comments
 (0)