From f8a2cba8be6cc807a8488a918e75108c8db82c47 Mon Sep 17 00:00:00 2001 From: thomaslavaur Date: Mon, 8 Sep 2025 11:38:26 +0200 Subject: [PATCH] minor fix in names and python --- circom_circuits/Blend/poq.circom | 2 +- .../Mantle/generate_inputs_for_pol.py | 2 + circom_circuits/Mantle/poc.circom | 74 +++++++++++++++++++ circom_circuits/Mantle/pol.circom | 2 +- 4 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 circom_circuits/Mantle/poc.circom diff --git a/circom_circuits/Blend/poq.circom b/circom_circuits/Blend/poq.circom index 2cb4a17..a8385f1 100644 --- a/circom_circuits/Blend/poq.circom +++ b/circom_circuits/Blend/poq.circom @@ -133,5 +133,5 @@ template ProofOfQuota(nLevelsPK, nLevelsPol, bitsQuota) { } // Instantiate with chosen depths: 20 for core PK tree, 25 for PoL secret slot tree -component main { public [ session, core_quota, leader_quota, core_root, pol_ledger_aged, K_part_one, K_part_two ] } +component main { public [ session, core_quota, leader_quota, core_root, K_part_one, K_part_two, pol_epoch_nonce, pol_t0, pol_t1, pol_ledger_aged ] } = ProofOfQuota(20, 25, 20); \ No newline at end of file diff --git a/circom_circuits/Mantle/generate_inputs_for_pol.py b/circom_circuits/Mantle/generate_inputs_for_pol.py index 3899005..2925cf5 100755 --- a/circom_circuits/Mantle/generate_inputs_for_pol.py +++ b/circom_circuits/Mantle/generate_inputs_for_pol.py @@ -225,6 +225,8 @@ t1_constant = F(0x104bfd09ebdd0a57772289d0973489b62662a4dc6f09da8b4af3c5cfb1dcdd t0 = F(int(t0_constant) // total_stake) t1 = F(p- (int(t1_constant) // total_stake**2)) +print(t0) + value = F(total_stake / 100) threshold = (t0 + t1 * value) * value diff --git a/circom_circuits/Mantle/poc.circom b/circom_circuits/Mantle/poc.circom new file mode 100644 index 0000000..5a79e2f --- /dev/null +++ b/circom_circuits/Mantle/poc.circom @@ -0,0 +1,74 @@ +//test +pragma circom 2.1.9; + +include "../hash_bn/poseidon2_hash.circom"; +include "../hash_bn/merkle.circom"; +include "../misc/constants.circom"; + +template derive_voucher_nullifier(){ + signal input secret_voucher; + signal output out; + + component hash = Poseidon2_hash(2); + component dst = VOUCHER_NF(); + hash.inp[0] <== dst.out; + hash.inp[1] <== secret_voucher; + + out <== hash.out; +} + +template derive_reward_voucher(){ + signal input secret_voucher; + signal output out; + + component hash = Poseidon2_hash(2); + component dst = REWARD_VOUCHER(); + hash.inp[0] <== dst.out; + hash.inp[1] <== secret_voucher; + + out <== hash.out; +} + +template proof_of_claim(){ + signal input secret_voucher; + signal input voucher_merkle_path[32]; + signal input voucher_merkle_path_selectors[32]; + signal input mantle_tx_hash; + signal input voucher_root; + + signal output voucher_nullifier; + + //derive the reward voucher + component reward_voucher = derive_reward_voucher(); + reward_voucher.secret_voucher <== secret_voucher; + + //Check reward voucher membership + //First check selectors are indeed bits + for(var i = 0; i < 32; i++){ + voucher_merkle_path_selectors[i] * (1 - voucher_merkle_path_selectors[i]) === 0; + } + //Then check the proof of membership + component reward_membership = proof_of_membership(32); + for(var i = 0; i < 32; i++){ + reward_membership.nodes[i] <== voucher_merkle_path[i]; + reward_membership.selector[i] <== voucher_merkle_path_selectors[i]; + } + reward_membership.root <== voucher_root; + reward_membership.leaf <== reward_voucher.out; + + reward_membership.out === 1; + + + //derive the reward nullifier + component reward_nullifier = derive_voucher_nullifier(); + reward_nullifier.secret_voucher <== secret_voucher; + voucher_nullifier <== reward_nullifier.out; + + + + // dummy constraint to avoid unused public input to be erased after compilation optimisation + signal dummy; + dummy <== mantle_tx_hash * mantle_tx_hash; +} + +component main {public [voucher_root,mantle_tx_hash]}= proof_of_claim(); \ No newline at end of file diff --git a/circom_circuits/Mantle/pol.circom b/circom_circuits/Mantle/pol.circom index 719fe33..f4c24fb 100644 --- a/circom_circuits/Mantle/pol.circom +++ b/circom_circuits/Mantle/pol.circom @@ -247,4 +247,4 @@ template proof_of_leadership(secret_depth){ } -component main {public [sl,epoch_nonce,t0,t1,ledger_aged,ledger_latest,P_lead_part_one,P_lead_part_two]}= proof_of_leadership(25); \ No newline at end of file +//component main {public [sl,epoch_nonce,t0,t1,ledger_aged,ledger_latest,P_lead_part_one,P_lead_part_two]}= proof_of_leadership(25); \ No newline at end of file