-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zkllvm outdated info #48
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2a118e0
primer added, how-to guides cont
SKHDev195 067e97f
added rust info to primer, hashes done
SKHDev195 e2a5311
cpp zkbridge added, need to add rust
SKHDev195 5014585
use cases proofread, rust directives added to limitations
SKHDev195 033eec0
addressed comments in primer
SKHDev195 1765011
addressed comments in hashes
SKHDev195 46ac51e
addressed comments in zkbridge and added logical AND to hashes
SKHDev195 0fc4c84
addressed comments in Rust structs
SKHDev195 e86539c
example fix
SKHDev195 e0cb199
changed final Rust circuit to use refs in most functions, removed som…
SKHDev195 5b81f1d
removed unnecessary directives in Rust structs and enums
SKHDev195 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Structs and enums in Rust | ||
|
||
Whenever a Rust circuit is compiled, `rustc` applies various optimizations to reduce its memory usage. | ||
|
||
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: | ||
|
||
```rust | ||
use ark_pallas::Fq; | ||
|
||
type BlockType = [Fq; 2]; | ||
|
||
pub struct BlockDataType { | ||
prev_block_hash: BlockType, | ||
data: BlockType, | ||
validators_signature: i32, | ||
validators_key: u64, | ||
} | ||
``` | ||
|
||
The public input representation of the `BlockDataType` struct would look as follows: | ||
|
||
```json | ||
"struct": [ | ||
{ | ||
"array": [{"field": 1}, {"field": 1}] | ||
}, | ||
{ | ||
"array": [{"field": 3}, {"field": 1}] | ||
}, | ||
{ | ||
"int": 1 | ||
}, | ||
{ | ||
"int": 1 | ||
} | ||
] | ||
``` | ||
|
||
When compiling the `BlockDataType` struct, `rustc` may reorder its fields. | ||
|
||
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. | ||
|
||
To avoid this problem, use the `#[repr(C)]` directive: | ||
|
||
```rust | ||
|
||
use ark_pallas::Fq; | ||
|
||
type BlockType = [Fq; 2]; | ||
|
||
#[repr(C)] | ||
pub struct BlockDataType { | ||
prev_block_hash: BlockType, | ||
data: BlockType, | ||
validators_signature: i32, | ||
validators_key: u64, | ||
} | ||
``` | ||
|
||
If this directive is included, Rust will treat structs and enums as C-like types, meaning that `rustc` will never reorder fields in them. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary, but maybe for demonstration purposes we can construct smaller example? This one is a bit too big than needed to illustrate the issue and probably it will be a bit harder for users to get the point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I've simplified the example