Skip to content

Commit

Permalink
libraries: darkpool: VerificationKeys: Generate proof-linking vkeys (#60
Browse files Browse the repository at this point in the history
)

* codegen: vkeys: Add linking vkeys to codegen script

* libraries: darkpool: VerificationKeys: Generate proof-linking vkeys

* Verifier: Use generated linking vkeys in `verifyMatchBundle`
  • Loading branch information
joeykraut authored Mar 7, 2025
1 parent 19dffe8 commit 4f8ad9c
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 15 deletions.
1 change: 1 addition & 0 deletions codegen/vkeys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
reference-impl-common = { package = "common", path = "../../test/rust-reference-impls/common" }
renegade-circuits = { package = "circuits", git = "https://github.com/renegade-fi/renegade.git" }
renegade-circuit-types = { package = "circuit-types", git = "https://github.com/renegade-fi/renegade.git" }
renegade-constants = { package = "constants", git = "https://github.com/renegade-fi/renegade.git" }

# === EVM === #
alloy = "0.11"
Expand Down
13 changes: 12 additions & 1 deletion codegen/vkeys/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use clap::Parser;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use vkeys::Circuit;
use vkeys::{Circuit, LinkingInstance};

const CONTRACT_NAME: &str = "VerificationKeys";

Expand Down Expand Up @@ -42,6 +42,17 @@ fn generate_solidity_contract() -> Result<String> {
add_constant(&mut contract, &const_name, &abi_bytes);
}

// Push all linking vkeys to the contract string
let linking_instances = LinkingInstance::all();
for instance in linking_instances.iter() {
let name = instance.name();
println!("Generating vkey for {}", name);
let const_name = format!("{}_VKEY", name);
let vkey = instance.vkey();
let abi_bytes = vkey.abi_encode();
add_constant(&mut contract, &const_name, &abi_bytes);
}

// Close contract
contract.push_str("}\n");
Ok(contract)
Expand Down
75 changes: 71 additions & 4 deletions codegen/vkeys/src/vkeys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@
use std::fmt::{self, Display};

use reference_impl_common::abi_types::VerificationKey;
use reference_impl_common::abi_types::{ProofLinkingVK, VerificationKey};
use renegade_circuit_types::traits::SingleProverCircuit;
use renegade_circuits::zk_circuits::{
valid_commitments::SizedValidCommitments, valid_fee_redemption::SizedValidFeeRedemption,
proof_linking::{
get_commitments_match_settle_group_layout, get_reblind_commitments_group_layout,
},
valid_commitments::SizedValidCommitments,
valid_fee_redemption::SizedValidFeeRedemption,
valid_malleable_match_settle_atomic::SizedValidMalleableMatchSettleAtomic,
valid_match_settle::SizedValidMatchSettle,
valid_match_settle_atomic::SizedValidMatchSettleAtomic,
valid_offline_fee_settlement::SizedValidOfflineFeeSettlement, valid_reblind::SizedValidReblind,
valid_wallet_create::SizedValidWalletCreate, valid_wallet_update::SizedValidWalletUpdate,
valid_offline_fee_settlement::SizedValidOfflineFeeSettlement,
valid_reblind::SizedValidReblind,
valid_wallet_create::SizedValidWalletCreate,
valid_wallet_update::SizedValidWalletUpdate,
};
use renegade_constants::{MAX_BALANCES, MAX_ORDERS, MERKLE_HEIGHT};

/// The circuit to generate a verification key for
#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -98,6 +105,52 @@ impl Circuit {
}
}

/// Represents all the linking instances in the Renegade circuits
#[derive(Debug, Clone, Copy)]
pub enum LinkingInstance {
/// The proof link between `VALID REBLIND` and `VALID COMMITMENTS`
ValidReblindCommitments,
/// The proof link between `VALID COMMITMENTS` and `VALID MATCH SETTLE` for the first party
ValidCommitmentsMatchSettle0,
/// The proof link between `VALID COMMITMENTS` and `VALID MATCH SETTLE` for the second party
ValidCommitmentsMatchSettle1,
}

impl LinkingInstance {
/// Generate a verification key for the linking instance
pub fn vkey(&self) -> ProofLinkingVK {
match self {
Self::ValidReblindCommitments => generate_reblind_commitments_link_vkey(),
Self::ValidCommitmentsMatchSettle0 => {
generate_commitments_match_settle_link_vkey(0 /* party */)
}
Self::ValidCommitmentsMatchSettle1 => {
generate_commitments_match_settle_link_vkey(1 /* party */)
}
}
}

/// Get the name of the linking instance
pub fn name(&self) -> &'static str {
match self {
Self::ValidReblindCommitments => "VALID_REBLIND_COMMITMENTS_LINK",
Self::ValidCommitmentsMatchSettle0 => "VALID_COMMITMENTS_MATCH_SETTLE_LINK0",
Self::ValidCommitmentsMatchSettle1 => "VALID_COMMITMENTS_MATCH_SETTLE_LINK1",
}
}

/// Get all linking instances
pub fn all() -> Vec<Self> {
vec![
Self::ValidReblindCommitments,
Self::ValidCommitmentsMatchSettle0,
Self::ValidCommitmentsMatchSettle1,
]
}
}

// --- Helpers --- //

/// Generate the verification keys for all circuits
///
/// Returns a map from the circuit name to the verification key
Expand All @@ -106,3 +159,17 @@ fn generate_vkey_for_circuit<T: SingleProverCircuit>() -> VerificationKey {
let vkey = VerificationKey::from(vk.as_ref().clone());
vkey
}

/// Generate the linking verification key for the `VALID REBLIND <-> VALID COMMITMENTS` link
fn generate_reblind_commitments_link_vkey() -> ProofLinkingVK {
let group_layout =
get_reblind_commitments_group_layout::<MAX_BALANCES, MAX_ORDERS, MERKLE_HEIGHT>().unwrap();
ProofLinkingVK::from(group_layout)
}

/// Generate the linking verification key for the `VALID COMMITMENTS <-> VALID MATCH SETTLE` link
fn generate_commitments_match_settle_link_vkey(party: u64) -> ProofLinkingVK {
let group_layout =
get_commitments_match_settle_group_layout::<MAX_BALANCES, MAX_ORDERS>(party).unwrap();
ProofLinkingVK::from(group_layout)
}
20 changes: 10 additions & 10 deletions src/Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,43 +136,43 @@ contract Verifier is IVerifier {
returns (ProofLinkingInstance[] memory instances)
{
instances = new ProofLinkingInstance[](NUM_MATCH_LINKING_PROOFS);
ProofLinkingVK memory reblindCommitmentsVk =
abi.decode(VerificationKeys.VALID_REBLIND_COMMITMENTS_LINK_VKEY, (ProofLinkingVK));
ProofLinkingVK memory commitmentsMatchSettleVk0 =
abi.decode(VerificationKeys.VALID_COMMITMENTS_MATCH_SETTLE_LINK0_VKEY, (ProofLinkingVK));
ProofLinkingVK memory commitmentsMatchSettleVk1 =
abi.decode(VerificationKeys.VALID_COMMITMENTS_MATCH_SETTLE_LINK1_VKEY, (ProofLinkingVK));

// Party 0: VALID REBLIND -> VALID COMMITMENTS
instances[0] = ProofLinkingInstance({
wire_comm0: matchProofs.validReblind0.wire_comms[0],
wire_comm1: matchProofs.validCommitments0.wire_comms[0],
proof: matchLinkingProofs.validReblindCommitments0,
vk: dummyProofLinkingVk()
vk: reblindCommitmentsVk
});

// Party 0: VALID COMMITMENTS -> VALID MATCH SETTLE
instances[1] = ProofLinkingInstance({
wire_comm0: matchProofs.validCommitments0.wire_comms[0],
wire_comm1: matchProofs.validMatchSettle.wire_comms[0],
proof: matchLinkingProofs.validCommitmentsMatchSettle0,
vk: dummyProofLinkingVk()
vk: commitmentsMatchSettleVk0
});

// Party 1: VALID REBLIND -> VALID COMMITMENTS
instances[2] = ProofLinkingInstance({
wire_comm0: matchProofs.validReblind1.wire_comms[0],
wire_comm1: matchProofs.validCommitments1.wire_comms[0],
proof: matchLinkingProofs.validReblindCommitments1,
vk: dummyProofLinkingVk()
vk: reblindCommitmentsVk
});

// Party 1: VALID COMMITMENTS -> VALID MATCH SETTLE
instances[3] = ProofLinkingInstance({
wire_comm0: matchProofs.validCommitments1.wire_comms[0],
wire_comm1: matchProofs.validMatchSettle.wire_comms[0],
proof: matchLinkingProofs.validCommitmentsMatchSettle1,
vk: dummyProofLinkingVk()
vk: commitmentsMatchSettleVk1
});
}

/// @dev Create a dummy proof linking verification key
/// @dev TODO: Remove this
function dummyProofLinkingVk() internal pure returns (ProofLinkingVK memory vk) {
vk = ProofLinkingVK({ link_group_generator: BN254.ScalarField.wrap(0), link_group_offset: 0, link_group_size: 0 });
}
}
6 changes: 6 additions & 0 deletions src/libraries/darkpool/VerificationKeys.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ library VerificationKeys {
hex"0000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000005200000000000000000000000000000000000000000000000000000000000000012f8dd1f1a7583c42c4e12a44e110404c73ca6c94813f85835da4fb7bb1301d4a1ee678a0470a75a6eaa8fe837060498ba828a3703b311d0f77f010424afeb0252042a587a90c187b0a087c03e29c968b950b1db26d5c82d666905a6895790c0a2e2b91456103698adf57b799969dea1c8f739da5d8d40dd3eb9222db7c81e881076cc791ee8d2bdcf8bfd7876dc2b996c6244473ad8e89c0ced954030f033f0d254537be8c24df6a68ed6ea3dba1c6663a0b40d581296d41b44a2cd2a3073f8b2aa884fdfdc83333131ae5c78687c5c5219f5869fae7b42b98e1281b36a4aaa61a29da69bc473b5b0df067e3def860adcf16c30993805f0b6a5337108259f568228a3c436b6e7d588c02cd692fe27ceb27b77f149f4a98c99633c228f99ff73223e26a94849b03fda66ac28e5deda67ddd52de5a0675861dee67f277a9ea73851f2ee52b4b1be7f1e27137904abed9a153538bc8b54d8a2f41755dbf1ebfad3d1185991d91f4b296e9f5ad9a209708b0854f2b53847b90af18f437404fb0a5c0263d0b4fa997a3449d24f6a4171ecccbb5756082d580e3b73018ab3aa0f1d4a030234cb055d1c6e5acc075d547d78d25f2d7a54b36bf63214064f2923645c3f90590815b478965af61e0266ac86ff2f288d2830cecf6dc0632d9bbcd0801580310791499d1377f278317fe8c2d895836bd304fc868709a8134e97337b568a311098a8de7a4def1387b977430196a791aafff50b45f596fd4af7122e410c619f42d2d78b96ebb2e57854a23d5c547a3d88232fa2f60e61ddfc7bc53be3b098dcd255250770ef540f1afc10c63de19de76ddb3ccaeccfaae47336a8a018159c83b0519323e7a61548137653b2d6d1cab2b485a71174e7b5b3526f9b186b124ae3c26985f429d049ee37ccb001e89a7e7442d27ec00124b324773597c944a9753d307e2baeb62120f7a643d459a341d103d26315c3a2c3e8a700a21c52fafd708302136b1d4f52892ff944e22b3ab619628e3e9338b3a7ee5047aa41a1565b0d4f713a71f26239ee3c38af5285cd95db608f59a72b27eee3c41ba0eba44bc0b8582262b2c70c7b86c434484bb1ddec5be43e311c134abda7ff90557fa0a7917c54e2a76fc2b85954af7ecd19eaf9e9e1a89f9daddc101abcd63456b08e3d2ad8b4c2c8f51779898f1515e37a34e03821ea066eb9c03d666d231224aae53d74bcf711f2b2a29fb0bb388811efb64f6553ed64729c8f00f768c4f6d35efe94e3ed8f425c7e2516498eeb907bdfff38e5f486ccf1207b39f8c95ba4045e13b365780af1f27938e16043ace863773f7368559b82cb4475686e47ae772a71ade8cd1091323fd00ae6e14ad7bb7173952fdb74635dc7662992fed8c7c5f3164e2388a17010f18302e7f65eb03edfe93d95be2d62b585877febe817adf79a6b50a5e2785721c0a2fa657ac41b8e20fb8518e5b5d6a43c3e9d8f6517f0a5cab464fee146b2b01422062aac1a64dcf222d52faa8dcc4d28103a2d4024115fdeb43683813ffa21c91092309e2d1369a94ad9ce5724c2aede97f4cc0841d9b4a6fc151c645708a298a6d37c2ca07a655a35fcb43a656aa8faee88deaf248c69d1fca7efaa3346a10a3d8e25341ead2c5f9e54460f7eee1f95a7ea4e08a34c0d8834a776c807aa11620b078744d94f2dd766f3ea97feff2f63565d69eb7a636c91ad7d65159471704d6401365e6b614c8fb672dcd31f32371bf6d3e57844f182cb3b9a44b3c74dc15e2578ea933925c7b9b058f1423eff2ce2092e841e375179417eb93c17a403f000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000021800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c212c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b30441fd1b5d3370482c42152a8899027716989a6996c2535bc9f7fee8aaef79e26186a2d65ee4d2f9c9a5b91f86597d35f192cd120caf7e935d8443d1938e23d054793348f12c0cf5622c340573cb277586319de359ab9389778f689786b1e481970ea81dd6992adfbc571effb03503adbbb6a857f578403c6c40e22d65b3c02";
bytes public constant VALID_FEE_REDEMPTION_VKEY =
hex"0000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000004f00000000000000000000000000000000000000000000000000000000000000012f8dd1f1a7583c42c4e12a44e110404c73ca6c94813f85835da4fb7bb1301d4a1ee678a0470a75a6eaa8fe837060498ba828a3703b311d0f77f010424afeb0252042a587a90c187b0a087c03e29c968b950b1db26d5c82d666905a6895790c0a2e2b91456103698adf57b799969dea1c8f739da5d8d40dd3eb9222db7c81e881125d6897dd1106753f8595f034aae5edc3c9578f44f78a1749b9e48c547caa790754696d9fc753deda1ab8643674f7c4d1efc38388f06239d2198b09fbadd2a6057f5d100bf53713fc0772170422cfc7ee0910b9f2877ed09c37540800d6dd4d1d496108b4e8da54c08d1d59f45c7fa8893821c419912a60ef959fb4ca1dc0411f66c73552f99b904e7d4c2a55c2bffef19154d55423fb6707f757a94e6153ae1e046dc291b76f7bac93ce3d4b80af5bf3939bc33db6f08f1bf3d268c8f7dd6c07faf4b10982ace7e67697d0f0c4ac4916c86812b689d774b88e2d2622e087e529ed555aa667c7aeb94be48881c5394479a305204b5be28f7e0c862d0ff6e3661d6e0862cab841269d91a03ef4b7f9d5a0889878943104c4494d284ce9a863b41702d213f263da5c96b763ade5d0392c457e7c95bf3decc71bef72034c72d0851d864c6bcee8a5387d95cf856c2a285bc83b0f8073260940de5f4b34dc7f11c91c5664c817d3632ff373f2afcc53f33d17550c78c09dca3e7f806cb649405b3f07545f6cc5b9a644a7fe29c49d683736f75940f718e701179c0e1f4d6d6c20d61a7f75eddaf25d2ffab70ecb15f88507580796c0a8ebb3101dcaf00e0dc6b34a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e1015f60d8d5486fd5bd00c497e6a3a594d9d708bd6105b1294610733bc7ab42319c5131ae091c8dad0cc21d89291800981bf377e02df8d7b481bd618dcdac70169393678521e6e37b4f7876c0cb95d5da7d63ef5f9af57843a748d325504ed0381c941e8e8aac89566744d637aebc46f45ed9a3c9e372de0fa2430cfb2eb8622d87c3a2f34fd06d0cb3bc1ad05243acb464a5dafb8175007d74ee784249ea71f3dac3d7fd1ad54d6e7ce0ac20d89ce6bfb7733845fd85600ae33a7212a1f100bde232aa5382062d734734f22f6b94abbf9220421631cda5b5f25275e9c75a003728801c24e14e8e1a6ffbf84c0726674e529f1421c8930890d55b0b6b0c3572527029873643cf02615355af5d314423b2433ab4eb0342380ea46d6c8b0300403d3c117267acc4433a17947b68096f499122fd929018c14b4cb84d594c3b6632c83aca0960d3bfab66df5bcf43784da2916230d694c5bd78d85ba984c3e0d572ab5b6b6ace3c1247858f4bf7ed772c7fb6d9fb3cd88e40a01a618412649198c2e32773fd400f724825dd32b1169df95f474b7ac75a2f48969741d896d56e490182b4faedb715d92e3fb3adc1d65c5d6dcc91ff1711fb08f689ad1fe64ce1590137bc69deb709336de4ca1c538a847133e9d4166995ded30721ab134a475d652036b508264769a6714aeb30aa6db6067fb95028b6418a8eaa47b450072f04e36000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000021800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c212c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b30441fd1b5d3370482c42152a8899027716989a6996c2535bc9f7fee8aaef79e26186a2d65ee4d2f9c9a5b91f86597d35f192cd120caf7e935d8443d1938e23d054793348f12c0cf5622c340573cb277586319de359ab9389778f689786b1e481970ea81dd6992adfbc571effb03503adbbb6a857f578403c6c40e22d65b3c02";
bytes public constant VALID_REBLIND_COMMITMENTS_LINK_VKEY =
hex"0931d596de2fd10f01ddd073fd5a90a976f169c76f039bb91c4775720042d43a0000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000008c";
bytes public constant VALID_COMMITMENTS_MATCH_SETTLE_LINK0_VKEY =
hex"0931d596de2fd10f01ddd073fd5a90a976f169c76f039bb91c4775720042d43a00000000000000000000000000000000000000000000000000000000000000e70000000000000000000000000000000000000000000000000000000000000054";
bytes public constant VALID_COMMITMENTS_MATCH_SETTLE_LINK1_VKEY =
hex"0931d596de2fd10f01ddd073fd5a90a976f169c76f039bb91c4775720042d43a00000000000000000000000000000000000000000000000000000000000000930000000000000000000000000000000000000000000000000000000000000054";
}

0 comments on commit 4f8ad9c

Please sign in to comment.