Skip to content

Commit 2aaa6f0

Browse files
committed
Implement Edu's comments on custom predicates
1 parent b38c699 commit 2aaa6f0

File tree

7 files changed

+41
-32
lines changed

7 files changed

+41
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
Cargo.lock
33
.DS_Store
44
aardnotes.md
5+
notes

book/src/custom.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ Users of the POD system can introduce _custom predicates_ (previously called _cu
44

55
When a custom predicate is introduced in a MainPod, it becomes available for use in that POD and all PODs that inherit[^inherit] from it.
66

7-
A custom predicate can be defined either _nonrecursively_ or _recursively_ (as part of a "batch"). A nonrecursive custom predicate is defined in terms of previously defined predicates (whether custom or native). A "batch" of custom predicates can be defined _recursively_: the definition of any custom predicate in the batch can use both previously defined predicates and all the predicates in the batch.
7+
On the frontend, a custom predicate is defined as a collection of conjunctions and disjunctions of statements. The definition can be recursive: the definition of a predicate can involve the predicate itself, or the definitions of several predicates can depend on each other.
88

9-
## Custom predicates and their IDs
9+
At the backend level, every definition of a predicate is either a conjunction or a disjunction of statements. To convert a frontend custom predicate to the backend, the middleware may need to introduce _sub-predicates_.
1010

11-
A custom predicate, like a built-in predicate, is identified by a _name_ on the front end and an _identifier_ on the back end. In the non-recursive case, the back-end identifier is defined as a hash of the definition of the custom predicate.
11+
On the backend, custom predicates are defined in _groups_. A group can contain one or more custom predicates and their associated sub-predicates. Recursive definition is only possible within a group: the definition of a predicate in a group can only depend on previously existing predicates, itself, and other predicates in the same group.
1212

13-
### Recursively defined custom predicates
13+
## Custom predicates and their IDs
1414

15+
A custom predicate, like a built-in predicate, is identified by a _name_ on the front end and an _identifier_ on the back end. The identifier is a cryptographic hash of the definition of the group.
1516

1617

1718
[^inherit]: What to call this? One POD "inherits" from another?

book/src/custom1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ 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. (*1, *2, *4 should be OriginIDs for the three origins; *3 and *5 should be key names.)
44+
- Values for *1, *2, *3, *4, *5.
4545
- 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

book/src/custom1b.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,33 @@
55
A _custom predicate_ can be defined in one of two ways:
66

77
- Directly, as either the AND or OR of two pre-existing predicates, or
8-
- Recursively, in a _batch_ of up to 10 custom predicates. Each custom predicate in the batch is either the AND or OR of five predicates which are either pre-existing, or defined in the same batch.
8+
- Recursively, in a _group_ of up to 10 custom predicates. Each custom predicate in the group is either the AND or OR of five predicates which are either pre-existing, or defined in the same group.
99

1010
[Note: We could potentially allow the AND or OR of, say, two predicates instead of five. To make this work, we might need to have access to pod ID as a virtual key, see github issue #60]
1111

1212
## Arguments of custom predicates
1313

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

16-
Each argument (origin or key) to an input statement is either a wildcard or a literal. In the backend, the wildcard arguments will be identified as *1, *2, *3, ....
16+
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, ....
1717

1818
## Examples
1919

2020
See [examples](./customexample.md)
2121

2222
## Hashing and predicate IDs
2323

24-
Each custom predicate is assigned a cryptographic ID as follows:
25-
26-
If it is defined directly: its ID is simply a zk-friendly hash of its definition. The definition is serialized as it will appear in circuit (see below) and hashed.
27-
28-
If it is defined in a batch: The definitions of all statements in the batch are laid out consecutively (see [examples](./customexample.md)) and hashed.
24+
Each custom predicate is defined as part of a _group_ of predicates. The definitions of all statements in the group are laid out consecutively (see [examples](./customexample.md)) and hashed.
2925

3026
## How to prove an application of an operation
3127

3228
A POD contains a "tabular proof", in which each row includes a "statement" and a "reason". The "reason" is everything the circuit needs as a witness to verify the statement.
3329

3430
For a custom statement, the "reason" includes the following witnesses and verifications:
3531
- the definition of the statement, serialized (see [examples](./customexample.md))
36-
- if the statement is part of a batch, the definition of the full batch, serialized
32+
- if the statement is part of a group, the definition of the full group, serialized
3733
- verify that the hash of the definition is the statement ID
38-
- the definition will have some number of "wildcards" (*1, *2, ...) as arguments to input statements; a value for each wildcard must be provided as a witness (each will be either an origin ID or key)
34+
- 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)
3935
- the circuit must substitute the claimed values for the wildcards, and the resulting statements (true statements with origins and keys) will appear as witnesses
40-
- the circuit must verify that all the input statements (with origins and keys) appear in the previous statements (in higher rows of the table)
36+
- 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)
4137
- 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: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

2-
# Ethdos custom predicate, using binary AND and OR: example of a direct definition and a recursive batch
2+
# Ethdos custom predicate, using binary AND and OR: example of a direct definition and a recursive group
33

44
## Direct definition
5+
(DEPRECATED: All predicates must be defined as part of a group.)
56
```
67
eth_friend(src_or, src_key, dst_or, dst_key) = and<
78
// there is an attestation pod that's a SIGNATURE POD
@@ -30,7 +31,7 @@ This backend definition is then hashed in the obvious way.
3031
3132
```
3233

33-
## Recursive batch definition
34+
## Recursive group definition
3435

3536
```
3637
eth_dos_distance(src_or, src_key, dst_or, dst_key, distance_or, distance_key) = or<
@@ -56,7 +57,7 @@ eth_dos_distance_ind_0(src_or, src_key, dst_or, dst_key, distance_or, distance_k
5657
>
5758
```
5859

59-
This batch includes three statements.
60+
This group includes three statements.
6061

6162
When the definition is serialized for hashing, the statements are renamed to SELF.1, SELF.2, SELF.3.
6263

@@ -69,11 +70,11 @@ SELF.1( *1, *2, *3, *4, *5, *6 ) = or<
6970
```
7071
and similarly for the other two definitions.
7172

72-
The above definition is serialized in-circuit and hashed with a zk-friendly hash to generate the "batch hash", a unique cryptographic identifier for the batch.
73+
The above definition is serialized in-circuit and hashed with a zk-friendly hash to generate the "group hash", a unique cryptographic identifier for the group.
7374

74-
Then the individual statements in the batch are identified as:
75+
Then the individual statements in the group are identified as:
7576
```
76-
eth_dos_distance = BATCHHASH.1
77-
eth_dos_distance_base = BATCHHASH.2
78-
eth_dos_distance_ind = BATCHHASH.3
77+
eth_dos_distance = groupHASH.1
78+
eth_dos_distance_base = groupHASH.2
79+
eth_dos_distance_ind = groupHASH.3
7980
```

book/src/examples.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,21 @@ statement is_great_boy(great_boy: PubKey, good_boy_issuers: MerkleTree):
136136
# good boy 0 != good boy 1
137137
- neq(friend_pod_0.signer, friend_pod_1.signer)
138138
```
139+
140+
## Attested GreatBoy
141+
142+
An Attested Great Boy Pod is like a Great Boy Pod, but the names of the signers are revealed.
143+
144+
```
145+
statement is_great_boy(great_boy: PubKey, friend0: String, friend1: String, good_boy_issuers: MerkleTree):
146+
- OR():
147+
- AND(friend_pod_0: Pod, friend_pod_1: Pod):
148+
# Two good boys consider this user their friend
149+
- is_friend(friend_pod_0.signer, great_boy)
150+
- is_friend(friend_pod_1.signer, great_boy)
151+
# good boy 0 != good boy 1
152+
- neq(friend_pod_0.signer, friend_pod_1.signer)
153+
# publicize signer names
154+
- value_of(friend_pod_0.name, friend0)
155+
- value_of(friend_pod_1.name, friend1)
156+
```

book/src/notes

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)