-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathchained-functional-commitment.lurk
56 lines (30 loc) · 1.67 KB
/
chained-functional-commitment.lurk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
;; First, we define a stateful function that adds its input to an internal counter, initialized to 0.
;; The function returns a new counter value and a commitment to a replacement function wrapping the new counter.
!(commit (letrec ((add (lambda (counter x)
(let ((counter (+ counter x)))
(cons counter (commit (add counter)))))))
(add 0)))
;; We chain a next commitment by applying the committed function to a value of 9.
!(chain 0x2b444b40b27bac0dff8416c0f3c708a505a636d86ba66bdbe86497c515afb651 9)
;; The new counter value is 9, and the function returns a new functional commitment.
;; This new commitment is now the head of the chain.
;; Next, we ccreate a proof of this transition.
!(prove)
;; We can verify the proof.
!(verify "supernova_bn256_10_0f54f9e56fa6c436618597c971daa7b525ad80ac48be11226284fd4f8167e60a")
;; Now let's chain another call to the new head, adding 12 to the counter.
!(chain (comm 0x1d10fb6dea15a5865565d571efbcaf535750ab93ba4d9018bd6b7b803e86d986) 12)
;; Now the counter is 21, and we have a new head commitment.
;; Prove it.
!(prove)
;; And verify.
!(verify "supernova_bn256_10_281771b7af2f96cac51cb7579d94f0a6f56e9a9d951b753f8514b2b4ec6ce4db")
;; One more time, we'll add 14 to the head commitment's internal state.
!(chain 0x1a95f14fa34e01ce6cf44b4eb419c59e8b50978618139d9314304979cad1770f 14)
;; 21 + 14 = 35, as expected.
;; Prove.
!(prove)
;; Verify.
!(verify "supernova_bn256_10_22ab68c1fa6e75f54d213a3ada71edd21331bf58826263a79e3fdd32f1c4c62d")
;; Repeat indefinitely.
;; At every step, we have proof that the head commitment was correctly derived from the previous and some input.