Skip to content
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

Plonk backend #31

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f367703
Add dusk-plonk crate
ilitteri Jan 16, 2023
c384f2e
Abstract marlin backend
ilitteri Jan 16, 2023
72ffad6
Add helper functions
ilitteri Jan 16, 2023
10c8993
Start plonk implementation
ilitteri Jan 16, 2023
6ce6aac
cargo clippy
ilitteri Jan 16, 2023
8a91525
Add round functions definitions
ilitteri Jan 16, 2023
fe9bd6d
Type aliased Plonk Error
ilitteri Jan 16, 2023
b350a67
cargo fmt
ilitteri Jan 16, 2023
8ce479f
Pass the composer as parameter
ilitteri Jan 16, 2023
b68cac7
Implement add round key
ilitteri Jan 16, 2023
be052c9
Merge branch 'master' of github.com:lambdaclass/zk_encryption_circuit…
ilitteri Jan 18, 2023
a6c4fb7
Add TODO
ilitteri Jan 19, 2023
b711222
Update Plonk backend API
ilitteri Jan 19, 2023
fd6b5ad
Implement shift rows
ilitteri Jan 19, 2023
8a90920
Implement `MixColumns`
ilitteri Jan 19, 2023
007049d
Implement `kary_xor`
ilitteri Jan 19, 2023
e662842
Add a unit test for each step
ilitteri Jan 19, 2023
ee9e4d6
Add substitution table
ilitteri Jan 19, 2023
a9b43dc
Cleanup a little
ilitteri Jan 19, 2023
d9b8a23
Implement `SubBytes`
ilitteri Jan 20, 2023
cfbfd6f
Fix `MixColumns`
ilitteri Jan 23, 2023
63903ab
Add `component_select` when using `gate_eq`
ilitteri Jan 23, 2023
6e44bd9
Implement `KeyExpansion` (it is bugged)
ilitteri Jan 23, 2023
ac473fc
Fix `KeyExpansion`
ilitteri Jan 23, 2023
e9dbd94
Cleanup
ilitteri Jan 23, 2023
c8ae51f
Clippy cleanup
ilitteri Jan 24, 2023
3d8c77f
Handle message as blocks
ilitteri Jan 24, 2023
ce4d3cb
Add integration test
ilitteri Jan 24, 2023
75138df
cargo clippy
ilitteri Jan 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 116 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ rand = "0.8.5"
log = "0.4"
env_logger = "0.10.0"

dusk-plonk = "0.13"

[profile.bench]
opt-level = 3
debug = false
Expand Down
16 changes: 8 additions & 8 deletions src/aes_circuit.rs → src/aes_circuit/marlin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ pub fn lookup_table(cs: ConstraintSystemRef) -> Result<Vec<UInt8Gadget>> {

#[cfg(test)]
mod tests {
use crate::aes_circuit;
use crate::marlin;
use ark_r1cs_std::{prelude::AllocVar, R1CSVar};
use ark_relations::r1cs::ConstraintSystem;
use simpleworks::gadgets::{ConstraintF, UInt8Gadget};
Expand Down Expand Up @@ -723,7 +723,7 @@ mod tests {
0x48, 0x08,
];

let after_add_round_key = aes_circuit::add_round_key(&plaintext, &secret_key).unwrap();
let after_add_round_key = marlin::add_round_key(&plaintext, &secret_key).unwrap();

assert_eq!(
after_add_round_key.value().unwrap(),
Expand All @@ -748,7 +748,7 @@ mod tests {
0x26, 0x4c,
];

let mixed_column_vector = aes_circuit::mix_columns(&value_to_mix, cs.clone()).unwrap();
let mixed_column_vector = marlin::mix_columns(&value_to_mix, cs.clone()).unwrap();

assert_eq!(
mixed_column_vector.value().unwrap(),
Expand Down Expand Up @@ -787,7 +787,7 @@ mod tests {
value_to_shift.get(11).unwrap(),
];

let res = aes_circuit::shift_rows(&value_to_shift, cs.clone());
let res = marlin::shift_rows(&value_to_shift, cs.clone());
for (index, byte) in res.unwrap().iter().enumerate() {
assert_eq!(byte.value(), expected.get(index).unwrap().value());
}
Expand All @@ -797,7 +797,7 @@ mod tests {
#[test]
fn test_one_round_sub_bytes_circuit() {
let cs = ConstraintSystem::<ConstraintF>::new_ref();
let lookup_table = aes_circuit::lookup_table(cs.clone()).unwrap();
let lookup_table = marlin::lookup_table(cs.clone()).unwrap();
let value_to_substitute = UInt8Gadget::new_witness_vec(
ark_relations::ns!(cs, "value_to_mix"),
&[
Expand All @@ -813,7 +813,7 @@ mod tests {
];

let substituted_value =
aes_circuit::substitute_bytes(&value_to_substitute, &lookup_table).unwrap();
marlin::substitute_bytes(&value_to_substitute, &lookup_table).unwrap();

assert_eq!(
substituted_value.value().unwrap(),
Expand All @@ -824,7 +824,7 @@ mod tests {
#[test]
fn key_expansion_circuit() {
let cs = ConstraintSystem::<ConstraintF>::new_ref();
let lookup_table = aes_circuit::lookup_table(cs.clone()).unwrap();
let lookup_table = marlin::lookup_table(cs.clone()).unwrap();
let secret_key = UInt8Gadget::new_witness_vec(
cs.clone(),
&[
Expand All @@ -833,7 +833,7 @@ mod tests {
],
)
.unwrap();
let result = aes_circuit::derive_keys(&secret_key, &lookup_table, cs).unwrap();
let result = marlin::derive_keys(&secret_key, &lookup_table, cs).unwrap();

assert_eq!(
result.get(10).unwrap().value().unwrap(),
Expand Down
2 changes: 2 additions & 0 deletions src/aes_circuit/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod marlin;
pub mod plonk;
Loading