Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit d380210

Browse files
Merge pull request #48 from NilFoundation/zkllvm-outdated-info
Zkllvm outdated info
2 parents 2c31d80 + 5b81f1d commit d380210

File tree

14 files changed

+1613
-658
lines changed

14 files changed

+1613
-658
lines changed

sidebar-zkllvm.js

+34-38
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default {
3333
type: 'category',
3434
label: 'Getting started',
3535
collapsible: true,
36-
collapsed: false,
36+
collapsed: true,
3737
items: [
3838
{
3939
type: 'doc',
@@ -121,20 +121,12 @@ export default {
121121
label: 'Unrolling loops',
122122
id: 'best-practices-limitations/unrolling-loops'
123123
},
124-
]
125-
},
126-
{
127-
type: 'category',
128-
label: 'Circuit development',
129-
collapsible: true,
130-
collapsed: true,
131-
items: [
132124
{
133125
type: 'doc',
134-
label: 'Standard library',
135-
id: 'circuit-development/standalone-clang',
136-
},
137-
],
126+
label: 'Structs and enums in Rust',
127+
id: 'best-practices-limitations/rust-derive'
128+
}
129+
]
138130
},
139131
{
140132
type: 'category',
@@ -144,24 +136,38 @@ export default {
144136
items: [
145137
{
146138
type: 'doc',
147-
label: 'First circuit with hashes',
148-
id: 'tutorials/hashes'
149-
},
150-
{
151-
type: 'doc',
152-
label: 'EsDSA signature verifications',
153-
id: 'tutorials/eddsa'
154-
},
155-
{
156-
type: 'doc',
157-
label: 'Merkle tree commitment schemes',
158-
id: 'tutorials/merkle-tree'
139+
label: 'Primer',
140+
id: 'use-cases/primer'
159141
},
160142
{
161-
type: 'doc',
162-
label: 'Constructing a zkBridge',
163-
id: 'tutorials/zkbridge'
143+
type: 'category',
144+
label: 'Construct a zkBridge',
145+
collapsible: true,
146+
collapsed: true,
147+
items: [
148+
{
149+
type: 'doc',
150+
label: 'Write a circuit with hashes',
151+
id: 'use-cases/zk-bridge/hashes'
152+
},
153+
{
154+
type: 'doc',
155+
label: 'Verify EdDSA signatures',
156+
id: 'use-cases/zk-bridge/eddsa'
157+
},
158+
{
159+
type: 'doc',
160+
label: 'Create a Merkle tree commitment scheme',
161+
id: 'use-cases/zk-bridge/merkle-tree'
162+
},
163+
{
164+
type: 'doc',
165+
label: 'Write an algorithm for state-proof verification',
166+
id: 'use-cases/zk-bridge/zkbridge'
167+
},
168+
]
164169
},
170+
165171
]
166172
},
167173
{
@@ -170,21 +176,11 @@ export default {
170176
collapsible: true,
171177
collapsed: true,
172178
items: [
173-
{
174-
type: 'doc',
175-
label: 'Contributing',
176-
id: 'misc/contributing'
177-
},
178179
{
179180
type: 'doc',
180181
label: 'Code of conduct',
181182
id: 'misc/code-of-conduct'
182183
},
183-
{
184-
type: 'doc',
185-
label: 'Contact',
186-
id: 'misc/contact'
187-
},
188184
]
189185
},
190186
],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Structs and enums in Rust
2+
3+
Whenever a Rust circuit is compiled, `rustc` applies various optimizations to reduce its memory usage.
4+
5+
Among these memory optimizations is [**reordering fields in structs and enums to avoid unnecessary 'paddings' in circuit IRs**](https://doc.rust-lang.org/nomicon/repr-rust.html). Consider the following example:
6+
7+
```rust
8+
use ark_pallas::Fq;
9+
10+
type BlockType = [Fq; 2];
11+
12+
pub struct BlockDataType {
13+
prev_block_hash: BlockType,
14+
data: BlockType,
15+
validators_signature: i32,
16+
validators_key: u64,
17+
}
18+
```
19+
20+
The public input representation of the `BlockDataType` struct would look as follows:
21+
22+
```json
23+
"struct": [
24+
{
25+
"array": [{"field": 1}, {"field": 1}]
26+
},
27+
{
28+
"array": [{"field": 3}, {"field": 1}]
29+
},
30+
{
31+
"int": 1
32+
},
33+
{
34+
"int": 1
35+
}
36+
]
37+
```
38+
39+
When compiling the `BlockDataType` struct, `rustc` may reorder its fields.
40+
41+
When `assigner` is called on a circuit with this struct, the circuit IR would conflict with the public input as the field order in the IR and the public input file would no longer match.
42+
43+
To avoid this problem, use the `#[repr(C)]` directive:
44+
45+
```rust
46+
47+
use ark_pallas::Fq;
48+
49+
type BlockType = [Fq; 2];
50+
51+
#[repr(C)]
52+
pub struct BlockDataType {
53+
prev_block_hash: BlockType,
54+
data: BlockType,
55+
validators_signature: i32,
56+
validators_key: u64,
57+
}
58+
```
59+
60+
If this directive is included, Rust will treat structs and enums as C-like types, meaning that `rustc` will never reorder fields in them.

zkllvm/circuit-development/standalone-clang.md

-25
This file was deleted.

zkllvm/misc/contact.md

-5
This file was deleted.

zkllvm/misc/contributing.md

-3
This file was deleted.

zkllvm/tutorials/01-hashes.md

-183
This file was deleted.

0 commit comments

Comments
 (0)