Skip to main content

EVM ZKP Contract

The EVM ZKP (Zero-Knowledge Proof) Contract leverages zero-knowledge proof technology to enable the verification of Bitcoin transactions within the Ethereum Virtual Machine (EVM) environment.

Diagram

Purpose and Functionality

The primary purpose of the EVM ZKP Contract is to receive, process, and verify zero-knowledge proofs of Bitcoin transactions on EVM-compatible chains.

  • The contract allows users to add new transactions with associated data, UTXOs, prover information, and scripts.
  • It verifies the submitted zero-knowledge proofs using a separate verifier contract, ensuring the validity of Bitcoin transactions.
  • The contract maintains a state of transactions, including their verification status, ownership, and timestamp.
  • Upon successful transaction addition and verification, the contract emits events that can be monitored by other parts of the BeL2 system or external applications.

Importance in the BeL2 Ecosystem

The EVM ZKP Contract is essential for several reasons:

  • It acts as the primary interface for bringing Bitcoin transaction data onto EVM-compatible chains in a verifiable manner.
  • By using zero-knowledge proofs, it allows for the verification of Bitcoin transactions without revealing the full transaction details.
  • The use of zero-knowledge proofs allows for efficient verification of Bitcoin transactions without requiring full Bitcoin node capabilities on EVM chains.

Technical Implementation

The EVM ZKP Contract is implemented as a smart contract written in Solidity.

contract ZkpOrder is Initializable, Ownable2StepUpgradeable {
enum ProofStatus {
toBeVerified,
verified,
verifyFailed
}

struct RawTransaction {
bytes rawData;
bytes[] utxos;
string prover;
bytes script;
ProofStatus status;
address owner;
uint256 timestamp;
}

mapping (bytes32 => RawTransaction) public orders;
IStarkVerifier public verifier;

// ... (events and functions)
}

The contract is designed to be upgradeable, allowing for future improvements without losing state.

It uses OpenZeppelin's Ownable2StepUpgradeable for secure ownership management.

The RawTransaction struct allows for storing various pieces of transaction data.

The contract interacts with an external verifier contract through the IStarkVerifier interface.

Functions like addTransaction, markTransactionVerified, and various getters allow for comprehensive transaction handling.

The contract includes checks for contract addresses, rewrite protection, and ownership verification.

Key Functions

  1. addTransaction: Allows users to add new transactions with associated data.
function addTransaction(bytes memory rawData, bytes[] memory utxos, string memory prover, bytes memory script) external returns (bytes32)
  1. markTransactionVerified: Verifies a transaction using the external verifier contract.
function markTransactionVerified(bytes32 hash) external
  1. setVerifier: Allows the owner to update the verifier contract address.
function setVerifier(address _verifier) external onlyOwner
  1. getOrderDetails: Retrieves detailed information about a transaction, including inputs, outputs, and verification status.
function getOrderDetails(bytes32 hash, string memory network) external view returns (
bytes32,
IStarkVerifier.Input[] memory,
IStarkVerifier.Output[] memory,
bytes memory,
IStarkVerifier.VerifiedStatus)

Interaction with Other Components

  • An external contract (implementing IStarkVerifier) that performs the actual zero-knowledge proof verification.
  • Arbitrator Nodes would typically call the addTransaction function to submit new transactions for verification.
  • Developers use the SDK to interact with this contract when building DApps that require Bitcoin transaction verification.
  • DApps and other smart contracts can query this contract to check the verification status of Bitcoin transactions.