The BitcoinDepositor contract is a cross-chain messaging and token reception module designed to handle Bitcoin deposit interactions on the Sui blockchain. It works in conjunction with the Gateway contract to facilitate secure token transfers and message processing from Ethereum (Layer 1) to Sui.
EMITTER_CHAIN_L1
: Identifies the Ethereum blockchain (Chain ID 2)INVALID_CHAIN_ID
: Error code for invalid chain identificationINVALID_SENDER
: Error code for unauthorized message senderMESSAGE_ALREADY_PROCESSED
: Error code for replay attack prevention
Manages the contract's core state:
processed_vaas
: A table tracking processed Verified Action Approvals (VAAs)trusted_emitter
: The authorized Wormhole external address for message emission
An administrative capability object that grants privileged access to contract management functions.
Emitted when a Wormhole message is successfully processed:
vaa_hash
: Hash of the processed VAA
Emitted when a new Bitcoin deposit is initiated:
funding_tx
: Bitcoin funding transaction datadeposit_reveal
: Deposit reveal informationdeposit_owner
: Address of the L2 deposit ownersender
: Sender's external address
Initializes the contract with a default state:
- Creates a
ReceiverState
with an empty trusted emitter address - Transfers an
AdminCap
to the contract deployer
Sets the trusted emitter address for cross-chain communication.
Parameters:
_: &AdminCap
: Administrative capabilitystate: &mut ReceiverState
: Contract stateemitter: vector<u8>
: Wormhole external address of the L1 BitcoinDepositor
Behavior:
- Updates the trusted emitter address in the contract state
Initiates a new Bitcoin deposit process.
Parameters:
funding_tx
: Bitcoin funding transaction datadeposit_reveal
: Deposit reveal informationdeposit_owner
: Address of the L2 deposit owner
Behavior:
- Emits a
DepositInitialized
event with deposit details
Processes incoming cross-chain messages from the Ethereum BitcoinDepositor.
Parameters:
- Multiple state objects including
ReceiverState
,Gateway::GatewayState
, etc. vaa_bytes
: Raw Verified Action Approval (VAA) bytesclock: &Clock
: Current time reference- Other blockchain state and capability objects
Key Processing Steps:
- Verify the VAA's authenticity
- Check that the message hasn't been processed before
- Validate the emitter's chain and address
- Mark the VAA as processed
- Emit a
MessageProcessed
event - Call the Gateway contract to redeem tokens
- Prevents replay attacks by tracking processed VAAs
- Restricts message processing to a specific chain and trusted emitter
- Requires administrative capability for critical configurations
- Leverages Wormhole's cross-chain messaging infrastructure
- Provides a separate
init_test
method for testing purposes - Supports modular initialization with administrative capabilities
Open the terminal and navigate to the project directory. Run the following command to publish the contract:
sui client publish ./ --gas-budget 1000000
After the Bitcoin Depositor contract is initialized, the deployer has to add the trusted emitters, etc.
This contract is licensed under GPL-3.0-only.
- Bitcoin deposit is initiated on Ethereum
- Wormhole relayers transmit the deposit information
receiveWormholeMessages
validates and processes the message- Gateway contract handles token redemption
- Tokens are minted or transferred to the deposit owner on Sui
- Relies on Wormhole for cross-chain messaging
- Integrates with the L2 TBTC Gateway contract
- Uses Sui's object and capability model