Integration Examples
How ZKontract leverages zk_escrow_v2.aleo for trustless bounty payments
Overview
ZKontract is a decentralized bounty platform built on Aleo that uses zk_escrow_v2.aleo as its core payment infrastructure. This integration demonstrates the versatility and composability of the escrow protocol.
🔗 Key Integration Point:
ZKontract's main program (zkontract_v2.aleo
) imports and calls zk_escrow_v2.aleo functions to manage bounty payments securely.
How ZKontract Uses ZK Escrow v2
Bounty Creation
When a user posts a bounty on ZKontract, they deposit credits into an escrow through thepost_bounty
function.
async transition post_bounty( caller: address, bounty_id: u64, creator_address: address, payment_amount: u64 ) -> Future { assert_eq(caller, creator_address); assert(payment_amount > 0u64); assert(bounty_id > 0u64); // Create escrow - set creator as recipient for potential cancellation let escrow_future: Future = zk_escrow_v2.aleo/create_escrow( bounty_id, creator_address, payment_amount ); return finalize_post_bounty(escrow_future, bounty_id, creator_address, payment_amount); }
Proposal Submission
Contributors submit proposals for bounties through a separate submission system. Proposal data is stored off-chain (S3), while the escrow remains locked on-chain.
- ✅ Proposal ID and metadata stored in database
- ✅ Files uploaded to S3 storage
- ✅ Escrow remains locked until bounty owner decides
Accepting Proposal (Payment)
When the bounty creator accepts a proposal, ZKontract calls the escrow'srelease
function to pay the contributor.
async transition accept_proposal( caller: address, bounty_id: u64, proposal_id: u64, creator_address: address, payment_amount: u64, proposer_address: address ) -> Future { assert_eq(caller, creator_address); // Only creator can accept assert(payment_amount > 0u64); let composite_proposal_id: u64 = bounty_id * 1000000u64 + proposal_id; // Release escrow to proposer let release_future: Future = zk_escrow_v2.aleo/release( bounty_id, payment_amount, proposer_address // Contributor receives payment ); return finalize_accept_proposal(release_future, bounty_id, composite_proposal_id); }
Cancelling Bounty (Refund)
If the bounty creator wants to cancel before accepting a proposal, they can retrieve their funds using the cancel_bounty_escrow
function.
async transition cancel_bounty_escrow( caller: address, bounty_id: u64, payment_amount: u64 ) -> Future { assert(bounty_id > 0u64); assert(payment_amount > 0u64); // Cancel escrow - return funds to the bounty creator let cancel_future: Future = zk_escrow_v2.aleo/cancel( bounty_id, payment_amount, caller // Creator gets refund ); return finalize_cancel_bounty_escrow(cancel_future, bounty_id, caller); }
System Architecture
Benefits of This Integration
🔒Security Through Separation
By using a dedicated, audited escrow contract, ZKontract inherits battle-tested payment security without reimplementing complex logic.
🧩Composability
The modular design allows other projects to use zk_escrow_v2.aleo for their own use cases, creating a shared payment infrastructure.
⚡Gas Efficiency
Reusing an existing contract reduces deployment costs and ensures optimized transaction fees for all escrow operations.
🔄Upgradability
If the escrow contract receives updates or improvements, all integrated projects can benefit without changing their code.
Import Declaration
The ZKontract contract imports zk_escrow_v2.aleo at the top of the file:
import zk_escrow_v2.aleo; program zkontract_v2.aleo { // Bounty mappings and logic... async transition post_bounty( caller: address, bounty_id: u64, creator_address: address, payment_amount: u64 ) -> Future { // Create escrow for this bounty let escrow_future: Future = zk_escrow_v2.aleo/create_escrow( bounty_id, creator_address, payment_amount ); return finalize_post_bounty( escrow_future, bounty_id, creator_address, payment_amount ); } }