Synthetic demo datademo

Every block, transaction, address and hash on this chain is generated from a fixed seed. None of them exists on any network, and none of these values can be looked up anywhere else. The execution trace is real — it is a recorded Noir program — but it is not the execution of the transaction it is published under.

Verified source

0xe744…90c9

0xe74420fe9977452d71a247465e6a134f816290c9

Verification

Code hash
0xb9a4710e19dd94ccdce3a83aab37f94c92dc183b
Status
full match
Provider
demo-vendored
Compiler
nargo 1.0.0-beta.26
Language
noir
Bundle
sha1:c0d7102d8a80da741a5db0cc8f8d174e0cc894af

Sources

Nargo.toml7 lines
1[package]
2name = "tour_loops"
3type = "bin"
4authors = ["BlockTracer capability tour"]
5
6[dependencies]
7
Prover.toml3 lines
1rows = "3"
2cols = "4"
3
src/main.nr84 lines
1// TOUR: loops and iteration
2//
3// The subject is the loop rail. Everything here exists so that a reader who
4// opens this program sees iterations they can move between one at a time, and
5// values that DIFFER from one iteration to the next — a loop whose variables
6// never change is a rail with nothing on it.
7//
8// Three shapes, because the rail has to cope with all three:
9// * a flat `for` with a carried accumulator,
10// * a `for` nested inside a `for`, so an iteration of the outer rail
11// contains a whole inner rail,
12// * a `while` whose bound is computed, so the iteration count is not
13// readable off the source.
14
15mod sieve;
16
17unconstrained fn triangular(n: u32) -> u32 {
18 // A flat loop with one carried variable. Iteration i adds i, so the
19 // accumulator takes a different value on every rung of the rail and the
20 // sequence 0, 0, 1, 3, 6, 10 ... is derivable from the source alone.
21 let mut acc: u32 = 0;
22 for i in 0..n {
23 acc = acc + i;
24 }
25 acc
26}
27
28unconstrained fn grid_sum(rows: u32, cols: u32) -> u32 {
29 // Nested loops. The outer rail has `rows` rungs; each one contains an
30 // inner rail of `cols` rungs. `row_total` resets at the top of every outer
31 // iteration, which is the thing per-iteration navigation makes visible and
32 // a single "current value" cannot show.
33 let mut total: u32 = 0;
34 for r in 0..rows {
35 let mut row_total: u32 = 0;
36 for c in 0..cols {
37 row_total = row_total + (r * cols + c);
38 }
39 total = total + row_total;
40 }
41 total
42}
43
44unconstrained fn collatz_steps(start: u32) -> u32 {
45 // A `while` whose trip count depends on the values, not on the bounds.
46 // Reading the source tells you what each step does; only the recording
47 // tells you how many there were.
48 let mut n = start;
49 let mut steps: u32 = 0;
50 while n != 1 {
51 if n % 2 == 0 {
52 n = n / 2;
53 } else {
54 n = 3 * n + 1;
55 }
56 steps = steps + 1;
57 }
58 steps
59}
60
61unconstrained fn first_gap(limit: u32) -> u32 {
62 // `break` and `continue` in one loop, so the rail has to show iterations
63 // that did nothing and an iteration that ended the loop early.
64 let mut found: u32 = 0;
65 for candidate in 2..limit {
66 if candidate % 2 == 0 {
67 continue;
68 }
69 if !sieve::is_prime(candidate) {
70 found = candidate;
71 break;
72 }
73 }
74 found
75}
76
77unconstrained fn main(rows: u32, cols: pub u32) -> pub u32 {
78 let t = triangular(6);
79 let g = grid_sum(rows, cols);
80 let c = collatz_steps(27);
81 let f = first_gap(30);
82 t + g + c + f
83}
84
src/sieve.nr19 lines
1// A second file, so the source pane has more than one document to switch
2// between and the call trace crosses a module boundary.
3
4pub unconstrained fn is_prime(n: u32) -> bool {
5 if n < 2 {
6 false
7 } else {
8 let mut prime = true;
9 let mut d: u32 = 2;
10 while d * d <= n {
11 if n % d == 0 {
12 prime = false;
13 }
14 d = d + 1;
15 }
16 prime
17 }
18}
19
This is a circuit, not a contract. It declares no ABI and no storage layout, so there is no interface list and no slot mapping to show. The source above is the whole of what it publishes.

Deployments

This code is deployed at one address. Any other address running the same bytecode would appear here too, already verified.