vm.rs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. use halo2_gadgets::{
  2. ecc::{
  3. chip::{EccChip, EccConfig},
  4. FixedPoint, FixedPointBaseField, FixedPointShort, Point,
  5. },
  6. poseidon::{Hash as PoseidonHash, Pow5Chip as PoseidonChip, Pow5Config as PoseidonConfig},
  7. primitives::poseidon::{ConstantLength, P128Pow5T3},
  8. sinsemilla::{
  9. chip::{SinsemillaChip, SinsemillaConfig},
  10. merkle::{
  11. chip::{MerkleChip, MerkleConfig},
  12. MerklePath,
  13. },
  14. },
  15. utilities::{lookup_range_check::LookupRangeCheckConfig, UtilitiesInstructions},
  16. };
  17. use halo2_proofs::{
  18. circuit::{AssignedCell, Layouter, SimpleFloorPlanner},
  19. plonk,
  20. plonk::{Advice, Circuit, Column, ConstraintSystem, Instance as InstanceColumn},
  21. };
  22. use log::debug;
  23. use pasta_curves::{group::Curve, pallas, Fp};
  24. use super::{
  25. arith_chip::{ArithmeticChip, ArithmeticChipConfig},
  26. even_bits::{EvenBitsChip, EvenBitsConfig, EvenBitsLookup},
  27. greater_than::{GreaterThanChip, GreaterThanConfig, GreaterThanInstruction},
  28. };
  29. pub use super::vm_stack::{StackVar, Witness};
  30. use crate::{
  31. crypto::constants::{
  32. sinsemilla::{OrchardCommitDomains, OrchardHashDomains},
  33. util::gen_const_array,
  34. NullifierK, OrchardFixedBases, OrchardFixedBasesFull, ValueCommitV, MERKLE_DEPTH_ORCHARD,
  35. },
  36. zkas::{decoder::ZkBinary, opcode::Opcode},
  37. };
  38. #[derive(Clone)]
  39. pub struct VmConfig {
  40. primary: Column<InstanceColumn>,
  41. advices: [Column<Advice>; 10],
  42. ecc_config: EccConfig<OrchardFixedBases>,
  43. merkle_cfg1: MerkleConfig<OrchardHashDomains, OrchardCommitDomains, OrchardFixedBases>,
  44. merkle_cfg2: MerkleConfig<OrchardHashDomains, OrchardCommitDomains, OrchardFixedBases>,
  45. sinsemilla_cfg1: SinsemillaConfig<OrchardHashDomains, OrchardCommitDomains, OrchardFixedBases>,
  46. _sinsemilla_cfg2: SinsemillaConfig<OrchardHashDomains, OrchardCommitDomains, OrchardFixedBases>,
  47. poseidon_config: PoseidonConfig<pallas::Base, 3, 2>,
  48. arith_config: ArithmeticChipConfig,
  49. evenbits_config: EvenBitsConfig,
  50. greaterthan_config: GreaterThanConfig,
  51. }
  52. impl VmConfig {
  53. fn ecc_chip(&self) -> EccChip<OrchardFixedBases> {
  54. EccChip::construct(self.ecc_config.clone())
  55. }
  56. /*
  57. fn sinsemilla_chip_1(
  58. &self,
  59. ) -> SinsemillaChip<OrchardHashDomains, OrchardCommitDomains, OrchardFixedBases> {
  60. SinsemillaChip::construct(self.sinsemilla_cfg1.clone())
  61. }
  62. fn sinsemilla_chip_2(
  63. &self,
  64. ) -> SinsemillaChip<OrchardHashDomains, OrchardCommitDomains, OrchardFixedBases> {
  65. SinsemillaChip::construct(self.sinsemilla_cfg2.clone())
  66. }
  67. */
  68. fn merkle_chip_1(
  69. &self,
  70. ) -> MerkleChip<OrchardHashDomains, OrchardCommitDomains, OrchardFixedBases> {
  71. MerkleChip::construct(self.merkle_cfg1.clone())
  72. }
  73. fn merkle_chip_2(
  74. &self,
  75. ) -> MerkleChip<OrchardHashDomains, OrchardCommitDomains, OrchardFixedBases> {
  76. MerkleChip::construct(self.merkle_cfg2.clone())
  77. }
  78. fn poseidon_chip(&self) -> PoseidonChip<pallas::Base, 3, 2> {
  79. PoseidonChip::construct(self.poseidon_config.clone())
  80. }
  81. fn arithmetic_chip(&self) -> ArithmeticChip {
  82. ArithmeticChip::construct(self.arith_config.clone())
  83. }
  84. fn evenbits_chip(&self) -> EvenBitsChip<pallas::Base, 24> {
  85. EvenBitsChip::construct(self.evenbits_config.clone())
  86. }
  87. fn greaterthan_chip(&self) -> GreaterThanChip<pallas::Base, 24> {
  88. GreaterThanChip::construct(self.greaterthan_config.clone())
  89. }
  90. }
  91. #[derive(Clone, Default)]
  92. pub struct ZkCircuit {
  93. constants: Vec<String>,
  94. witnesses: Vec<Witness>,
  95. opcodes: Vec<(Opcode, Vec<usize>)>,
  96. }
  97. impl ZkCircuit {
  98. pub fn new(witnesses: Vec<Witness>, circuit_code: ZkBinary) -> Self {
  99. let constants = circuit_code.constants.iter().map(|x| x.1.clone()).collect();
  100. Self { constants, witnesses, opcodes: circuit_code.opcodes }
  101. }
  102. }
  103. impl UtilitiesInstructions<pallas::Base> for ZkCircuit {
  104. type Var = AssignedCell<Fp, Fp>;
  105. }
  106. impl Circuit<pallas::Base> for ZkCircuit {
  107. type Config = VmConfig;
  108. type FloorPlanner = SimpleFloorPlanner;
  109. fn without_witnesses(&self) -> Self {
  110. Self {
  111. constants: self.constants.clone(),
  112. witnesses: self.witnesses.clone(),
  113. opcodes: self.opcodes.clone(),
  114. }
  115. }
  116. fn configure(meta: &mut ConstraintSystem<pallas::Base>) -> Self::Config {
  117. // Advice columns used in the circuit
  118. let advices = [
  119. meta.advice_column(),
  120. meta.advice_column(),
  121. meta.advice_column(),
  122. meta.advice_column(),
  123. meta.advice_column(),
  124. meta.advice_column(),
  125. meta.advice_column(),
  126. meta.advice_column(),
  127. meta.advice_column(),
  128. meta.advice_column(),
  129. ];
  130. // Fixed columns for the Sinsemilla generator lookup table
  131. let table_idx = meta.lookup_table_column();
  132. let lookup = (table_idx, meta.lookup_table_column(), meta.lookup_table_column());
  133. // Instance column used for public inputs
  134. let primary = meta.instance_column();
  135. meta.enable_equality(primary);
  136. // Permutation over all advice columns
  137. for advice in advices.iter() {
  138. meta.enable_equality(*advice);
  139. }
  140. // Poseidon requires four advice columns, while ECC incomplete addition
  141. // requires six. We can reduce the proof size by sharing fixed columns
  142. // between the ECC and Poseidon chips.
  143. // TODO: For multiple invocations perhaps they could/should be configured
  144. // in parallel rather than sharing?
  145. let lagrange_coeffs = [
  146. meta.fixed_column(),
  147. meta.fixed_column(),
  148. meta.fixed_column(),
  149. meta.fixed_column(),
  150. meta.fixed_column(),
  151. meta.fixed_column(),
  152. meta.fixed_column(),
  153. meta.fixed_column(),
  154. ];
  155. let rc_a = lagrange_coeffs[2..5].try_into().unwrap();
  156. let rc_b = lagrange_coeffs[5..8].try_into().unwrap();
  157. // Also use the first Lagrange coefficient column for loading global constants.
  158. meta.enable_constant(lagrange_coeffs[0]);
  159. // Use one of the right-most advice columns for all of our range checks.
  160. let range_check = LookupRangeCheckConfig::configure(meta, advices[9], table_idx);
  161. // Configuration for curve point operations.
  162. // This uses 10 advice columns and spans the whole circuit.
  163. let ecc_config =
  164. EccChip::<OrchardFixedBases>::configure(meta, advices, lagrange_coeffs, range_check);
  165. // Configuration for the Poseidon hash
  166. let poseidon_config = PoseidonChip::configure::<P128Pow5T3>(
  167. meta,
  168. advices[6..9].try_into().unwrap(),
  169. advices[5],
  170. rc_a,
  171. rc_b,
  172. );
  173. // Configuration for the Arithmetic chip
  174. let arith_config = ArithmeticChip::configure(meta);
  175. // Configuration for the EvenBits chip
  176. let evenbits_config = EvenBitsChip::<pallas::Base, 24>::configure(meta);
  177. // Configuration for the GreaterThan chip
  178. let greaterthan_config = GreaterThanChip::<pallas::Base, 24>::configure(meta);
  179. // Configuration for a Sinsemilla hash instantiation and a
  180. // Merkle hash instantiation using this Sinsemilla instance.
  181. // Since the Sinsemilla config uses only 5 advice columns,
  182. // we can fit two instances side-by-side.
  183. let (sinsemilla_cfg1, merkle_cfg1) = {
  184. let sinsemilla_cfg1 = SinsemillaChip::configure(
  185. meta,
  186. advices[..5].try_into().unwrap(),
  187. advices[6],
  188. lagrange_coeffs[0],
  189. lookup,
  190. range_check,
  191. );
  192. let merkle_cfg1 = MerkleChip::configure(meta, sinsemilla_cfg1.clone());
  193. (sinsemilla_cfg1, merkle_cfg1)
  194. };
  195. let (_sinsemilla_cfg2, merkle_cfg2) = {
  196. let sinsemilla_cfg2 = SinsemillaChip::configure(
  197. meta,
  198. advices[5..].try_into().unwrap(),
  199. advices[7],
  200. lagrange_coeffs[1],
  201. lookup,
  202. range_check,
  203. );
  204. let merkle_cfg2 = MerkleChip::configure(meta, sinsemilla_cfg2.clone());
  205. (sinsemilla_cfg2, merkle_cfg2)
  206. };
  207. VmConfig {
  208. primary,
  209. advices,
  210. ecc_config,
  211. merkle_cfg1,
  212. merkle_cfg2,
  213. sinsemilla_cfg1,
  214. _sinsemilla_cfg2,
  215. poseidon_config,
  216. arith_config,
  217. evenbits_config,
  218. greaterthan_config,
  219. }
  220. }
  221. fn synthesize(
  222. &self,
  223. config: Self::Config,
  224. mut layouter: impl Layouter<pallas::Base>,
  225. ) -> std::result::Result<(), plonk::Error> {
  226. debug!("Entering synthesize()");
  227. // Our stack which holds everything we reference.
  228. let mut stack: Vec<StackVar> = vec![];
  229. // Offset for public inputs
  230. let mut public_inputs_offset = 0;
  231. // Load the Sinsemilla generator lookup table used by the whole circuit.
  232. SinsemillaChip::load(config.sinsemilla_cfg1.clone(), &mut layouter)?;
  233. // Construct the ECC chip.
  234. let ecc_chip = config.ecc_chip();
  235. // Construct the Arithmetic chip.
  236. let arith_chip = config.arithmetic_chip();
  237. // Construct the EvenBits chip.
  238. let eb_chip = config.evenbits_chip();
  239. eb_chip.alloc_table(&mut layouter.namespace(|| "alloc table"))?;
  240. // Construct the GreaterThan chip.
  241. let gt_chip = config.greaterthan_chip();
  242. // This constant one is used for short multiplication
  243. let one = self.load_private(
  244. layouter.namespace(|| "Load constant one"),
  245. config.advices[0],
  246. Some(pallas::Base::one()),
  247. )?;
  248. // Lookup and push the constants onto the stack
  249. for constant in &self.constants {
  250. debug!("Pushing constant `{}` to stack index {}", constant.as_str(), stack.len());
  251. match constant.as_str() {
  252. "VALUE_COMMIT_VALUE" => {
  253. let vcv = ValueCommitV;
  254. let vcv = FixedPointShort::from_inner(ecc_chip.clone(), vcv);
  255. stack.push(StackVar::EcFixedPointShort(vcv));
  256. }
  257. "VALUE_COMMIT_RANDOM" => {
  258. let vcr = OrchardFixedBasesFull::ValueCommitR;
  259. let vcr = FixedPoint::from_inner(ecc_chip.clone(), vcr);
  260. stack.push(StackVar::EcFixedPoint(vcr));
  261. }
  262. "NULLIFIER_K" => {
  263. let nfk = NullifierK;
  264. let nfk = FixedPointBaseField::from_inner(ecc_chip.clone(), nfk);
  265. stack.push(StackVar::EcFixedPointBase(nfk));
  266. }
  267. _ => unimplemented!(),
  268. }
  269. }
  270. // Push the witnesses onto the stack, and potentially, if the witness
  271. // is in the Base field (like the entire circuit is), load it into a
  272. // table cell.
  273. for witness in &self.witnesses {
  274. match witness {
  275. Witness::EcPoint(w) => {
  276. debug!("Witnessing EcPoint into circuit");
  277. let point = Point::new(
  278. ecc_chip.clone(),
  279. layouter.namespace(|| "Witness EcPoint"),
  280. w.as_ref().map(|cm| cm.to_affine()),
  281. )?;
  282. debug!("Pushing EcPoint to stack index {}", stack.len());
  283. stack.push(StackVar::EcPoint(point));
  284. }
  285. Witness::EcFixedPoint(_) => {
  286. unimplemented!()
  287. }
  288. Witness::Base(w) => {
  289. debug!("Witnessing Base into circuit");
  290. let base = self.load_private(
  291. layouter.namespace(|| "Witness Base"),
  292. config.advices[0],
  293. *w,
  294. )?;
  295. debug!("Pushing Base to stack index {}", stack.len());
  296. stack.push(StackVar::Base(base));
  297. }
  298. Witness::Scalar(w) => {
  299. debug!("Pushing Scalar to stack index {}", stack.len());
  300. stack.push(StackVar::Scalar(*w));
  301. }
  302. Witness::MerklePath(w) => {
  303. debug!("Witnessing MerklePath into circuit");
  304. let path: Option<[pallas::Base; MERKLE_DEPTH_ORCHARD]> =
  305. w.map(|typed_path| gen_const_array(|i| typed_path[i].inner()));
  306. debug!("Pushing MerklePath to stack index {}", stack.len());
  307. stack.push(StackVar::MerklePath(path));
  308. }
  309. Witness::Uint32(w) => {
  310. debug!("Pushing Uint32 to stack index {}", stack.len());
  311. stack.push(StackVar::Uint32(*w));
  312. }
  313. Witness::Uint64(w) => {
  314. debug!("Pushing Uint64 to stack index {}", stack.len());
  315. stack.push(StackVar::Uint64(*w));
  316. }
  317. }
  318. }
  319. // And now, work through opcodes
  320. for opcode in &self.opcodes {
  321. match opcode.0 {
  322. Opcode::EcAdd => {
  323. debug!("Executing `EcAdd{:?}` opcode", opcode.1);
  324. let args = &opcode.1;
  325. let lhs: Point<pallas::Affine, EccChip<OrchardFixedBases>> =
  326. stack[args[0]].clone().into();
  327. let rhs: Point<pallas::Affine, EccChip<OrchardFixedBases>> =
  328. stack[args[1]].clone().into();
  329. let ret = lhs.add(layouter.namespace(|| "EcAdd()"), &rhs)?;
  330. debug!("Pushing result to stack index {}", stack.len());
  331. stack.push(StackVar::EcPoint(ret));
  332. }
  333. Opcode::EcMul => {
  334. debug!("Executing `EcMul{:?}` opcode", opcode.1);
  335. let args = &opcode.1;
  336. let lhs: FixedPoint<pallas::Affine, EccChip<OrchardFixedBases>> =
  337. stack[args[1]].clone().into();
  338. let rhs: Option<pallas::Scalar> = stack[args[0]].clone().into();
  339. let (ret, _) = lhs.mul(layouter.namespace(|| "EcMul()"), rhs)?;
  340. debug!("Pushing result to stack index {}", stack.len());
  341. stack.push(StackVar::EcPoint(ret));
  342. }
  343. Opcode::EcMulBase => {
  344. debug!("Executing `EcMulBase{:?}` opcode", opcode.1);
  345. let args = &opcode.1;
  346. let lhs: FixedPointBaseField<pallas::Affine, EccChip<OrchardFixedBases>> =
  347. stack[args[1]].clone().into();
  348. let rhs: AssignedCell<Fp, Fp> = stack[args[0]].clone().into();
  349. let ret = lhs.mul(layouter.namespace(|| "EcMulBase()"), rhs)?;
  350. debug!("Pushing result to stack index {}", stack.len());
  351. stack.push(StackVar::EcPoint(ret));
  352. }
  353. Opcode::EcMulShort => {
  354. debug!("Executing `EcMulShort{:?}` opcode", opcode.1);
  355. let args = &opcode.1;
  356. let lhs: FixedPointShort<pallas::Affine, EccChip<OrchardFixedBases>> =
  357. stack[args[1]].clone().into();
  358. let rhs: AssignedCell<Fp, Fp> = stack[args[0]].clone().into();
  359. let (ret, _) =
  360. lhs.mul(layouter.namespace(|| "EcMulShort()"), (rhs, one.clone()))?;
  361. debug!("Pushing result to stack index {}", stack.len());
  362. stack.push(StackVar::EcPoint(ret));
  363. }
  364. Opcode::EcGetX => {
  365. debug!("Executing `EcGetX{:?}` opcode", opcode.1);
  366. let args = &opcode.1;
  367. let point: Point<pallas::Affine, EccChip<OrchardFixedBases>> =
  368. stack[args[0]].clone().into();
  369. let ret = point.inner().x();
  370. debug!("Pushing result to stack index {}", stack.len());
  371. stack.push(StackVar::Base(ret));
  372. }
  373. Opcode::EcGetY => {
  374. debug!("Executing `EcGetY{:?}` opcode", opcode.1);
  375. let args = &opcode.1;
  376. let point: Point<pallas::Affine, EccChip<OrchardFixedBases>> =
  377. stack[args[0]].clone().into();
  378. let ret = point.inner().y();
  379. debug!("Pushing result to stack index {}", stack.len());
  380. stack.push(StackVar::Base(ret));
  381. }
  382. Opcode::PoseidonHash => {
  383. debug!("Executing `PoseidonHash{:?}` opcode", opcode.1);
  384. let args = &opcode.1;
  385. let mut poseidon_message: Vec<AssignedCell<Fp, Fp>> =
  386. Vec::with_capacity(args.len());
  387. for idx in args {
  388. poseidon_message.push(stack[*idx].clone().into());
  389. }
  390. macro_rules! poseidon_hash {
  391. ($len:expr, $hasher:ident, $output:ident, $cell:ident) => {
  392. let $hasher =
  393. PoseidonHash::<_, _, P128Pow5T3, ConstantLength<$len>, 3, 2>::init(
  394. config.poseidon_chip(),
  395. layouter.namespace(|| "PoseidonHash init"),
  396. )?;
  397. let $output = $hasher.hash(
  398. layouter.namespace(|| "PoseidonHash hash"),
  399. poseidon_message.try_into().unwrap(),
  400. )?;
  401. let $cell: AssignedCell<Fp, Fp> = $output.into();
  402. debug!("Pushing hash to stack index {}", stack.len());
  403. stack.push(StackVar::Base($cell));
  404. };
  405. }
  406. macro_rules! vla {
  407. ($args:ident, $a: ident, $b:ident, $c:ident, $($num:tt)*) => {
  408. match $args.len() {
  409. $($num => {
  410. poseidon_hash!($num, $a, $b, $c);
  411. })*
  412. _ => unimplemented!()
  413. }
  414. };
  415. }
  416. vla!(args, a, b, c, 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16);
  417. }
  418. Opcode::CalculateMerkleRoot => {
  419. debug!("Executing `CalculateMerkleRoot{:?}` opcode", opcode.1);
  420. let args = &opcode.1;
  421. let leaf_pos = stack[args[0]].clone().into();
  422. let merkle_path = stack[args[1]].clone().into();
  423. let leaf = stack[args[2]].clone().into();
  424. let merkle_inputs = MerklePath::construct(
  425. config.merkle_chip_1(),
  426. config.merkle_chip_2(),
  427. OrchardHashDomains::MerkleCrh,
  428. leaf_pos,
  429. merkle_path,
  430. );
  431. let root = merkle_inputs
  432. .calculate_root(layouter.namespace(|| "CalculateMerkleRoot()"), leaf)?;
  433. debug!("Pushing merkle root to stack index {}", stack.len());
  434. stack.push(StackVar::Base(root));
  435. }
  436. Opcode::BaseAdd => {
  437. debug!("Executing `BaseAdd{:?}` opcode", opcode.1);
  438. let args = &opcode.1;
  439. let lhs = stack[args[0]].clone().into();
  440. let rhs = stack[args[1]].clone().into();
  441. let sum = arith_chip.add(layouter.namespace(|| "BaseAdd()"), lhs, rhs)?;
  442. debug!("Pushing sum to stack index {}", stack.len());
  443. stack.push(StackVar::Base(sum));
  444. }
  445. Opcode::BaseMul => {
  446. debug!("Executing `BaseMul{:?}` opcode", opcode.1);
  447. let args = &opcode.1;
  448. let lhs = stack[args[0]].clone().into();
  449. let rhs = stack[args[1]].clone().into();
  450. let product = arith_chip.mul(layouter.namespace(|| "BaseMul()"), lhs, rhs)?;
  451. debug!("Pushing product to stack index {}", stack.len());
  452. stack.push(StackVar::Base(product));
  453. }
  454. Opcode::BaseSub => {
  455. debug!("Executing `BaseSub{:?}` opcode", opcode.1);
  456. let args = &opcode.1;
  457. let lhs = stack[args[0]].clone().into();
  458. let rhs = stack[args[1]].clone().into();
  459. let difference =
  460. arith_chip.sub(layouter.namespace(|| "BaseSub()"), lhs, rhs)?;
  461. debug!("Pushing difference to stack index {}", stack.len());
  462. stack.push(StackVar::Base(difference));
  463. }
  464. Opcode::GreaterThan => {
  465. debug!("Executing `GreaterThan{:?}` opcode", opcode.1);
  466. let args = &opcode.1;
  467. let lhs: AssignedCell<Fp, Fp> = stack[args[0]].clone().into();
  468. let rhs: AssignedCell<Fp, Fp> = stack[args[1]].clone().into();
  469. eb_chip.decompose(layouter.namespace(|| "lhs range check"), lhs.clone())?;
  470. eb_chip.decompose(layouter.namespace(|| "rhs range check"), rhs.clone())?;
  471. let (helper, greater_than) = gt_chip.greater_than(
  472. layouter.namespace(|| "lhs > rhs"),
  473. lhs.into(),
  474. rhs.into(),
  475. )?;
  476. eb_chip.decompose(layouter.namespace(|| "helper range check"), helper.0)?;
  477. debug!("Pushing comparison result to stack index {}", stack.len());
  478. stack.push(StackVar::Base(greater_than.0));
  479. }
  480. Opcode::ConstrainInstance => {
  481. debug!("Executing `ConstrainInstance{:?}` opcode", opcode.1);
  482. let args = &opcode.1;
  483. let var: AssignedCell<Fp, Fp> = stack[args[0]].clone().into();
  484. layouter.constrain_instance(
  485. var.cell(),
  486. config.primary,
  487. public_inputs_offset,
  488. )?;
  489. public_inputs_offset += 1;
  490. }
  491. _ => todo!("Handle gracefully"),
  492. }
  493. }
  494. debug!("Exiting synthesize()");
  495. Ok(())
  496. }
  497. }