Skip to content

Instantly share code, notes, and snippets.

@onurinanc
Created July 11, 2024 10:14
Show Gist options
  • Save onurinanc/db42dc2ca4014942e2a592ea80e16057 to your computer and use it in GitHub Desktop.
Save onurinanc/db42dc2ca4014942e2a592ea80e16057 to your computer and use it in GitHub Desktop.
permutation_via_bus.asm
use std::prover::Query;
use std::convert::fe;
use std::protocols::permutation_via_bus::permutation;
use std::math::fp2::from_base;
use std::prover::challenge;
machine Main with degree: 8 {
let alpha = from_base(challenge(0, 1));
let beta = from_base(challenge(0, 2));
col fixed first_four = [1, 1, 1, 1, 0, 0, 0, 0];
// Two pairs of witness columns, claimed to be permutations of one another
// (when selected by first_four and (1 - first_four), respectively)
col witness a1(i) query Query::Hint(fe(i));
col witness a2(i) query Query::Hint(fe(i + 42));
col witness b1(i) query Query::Hint(fe(7 - i));
col witness b2(i) query Query::Hint(fe(7 - i + 42));
let permutation_constraint = Constr::Permutation(
(Option::Some(first_four), Option::Some(1 - first_four)),
[(a1, b1), (a2, b2)]
);
// TODO: Functions currently cannot add witness columns at later stages,
// so we have to manually create it here and pass it to permutation().
col witness stage(1) z1;
col witness stage(1) z2;
let is_first: col = std::well_known::is_first;
permutation(is_first, 1, [z1], [z2], alpha, beta, permutation_constraint);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment