vm.rs 23 KB

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