moloch_anchor_ethereum/lib.rs
1//! Ethereum Anchoring for Moloch.
2//!
3//! This crate provides an Ethereum implementation of the `AnchorProvider` trait,
4//! allowing Moloch chain state to be anchored to Ethereum and EVM-compatible chains.
5//!
6//! # Anchoring Methods
7//!
8//! This provider supports multiple anchoring methods:
9//!
10//! 1. **Calldata Anchoring** (Default)
11//! - Embeds commitment in transaction input data
12//! - Most cost-effective for pure anchoring
13//! - Data: `[MOLOCH_SELECTOR (4)] [commitment_hash (32)] [chain_id_hash (8)]`
14//!
15//! 2. **Contract Event Anchoring**
16//! - Emits events from a dedicated anchor contract
17//! - Better for on-chain verification
18//! - Supports batch anchoring
19//!
20//! # Example
21//!
22//! ```ignore
23//! use moloch_anchor_ethereum::{EthereumProvider, EthereumConfig, Chain};
24//!
25//! let config = EthereumConfig::new("https://eth.llamarpc.com", Chain::Mainnet)
26//! .with_private_key("0x...");
27//!
28//! let provider = EthereumProvider::new(config).await?;
29//!
30//! // Anchor a commitment
31//! let tx = provider.submit(&commitment).await?;
32//!
33//! // Wait for confirmations
34//! let proof = provider.wait_for_confirmations(&tx.tx_id, 12).await?;
35//! ```
36
37#![deny(unsafe_code)]
38#![warn(missing_docs, rust_2018_idioms)]
39
40mod config;
41mod error;
42mod provider;
43
44pub use config::{AnchorMethod, Chain, EthereumConfig};
45pub use error::{EthereumError, Result};
46pub use provider::EthereumProvider;
47
48/// Function selector for Moloch anchor calls (first 4 bytes of keccak256("anchor(bytes32,bytes8)")).
49pub const MOLOCH_SELECTOR: [u8; 4] = [0x4d, 0x4f, 0x4c, 0x43]; // "MOLC" for simplicity
50
51/// Default number of confirmations for finality.
52pub const DEFAULT_CONFIRMATIONS: u64 = 12;
53
54/// Anchor data size: selector(4) + commitment(32) + chain_id(8) = 44 bytes.
55pub const ANCHOR_DATA_SIZE: usize = 44;