BEP-3 defines a protocol for atomic swaps on BNB Chain, allowing two parties to exchange native or BEP-2 assets across different blockchains without a centralized intermediary. The standard specifies the exact mechanics of a Hash Time-Locked Contract (HTLC), which uses a cryptographic hashlock and a timelock to guarantee that the swap either completes fully for both parties or refunds both parties after a timeout. This eliminates counterparty risk in cross-chain trading.

BEP-3 Atomic Swap Standard
What is BEP-3?
A specification for Hash Time-Locked Contracts (HTLCs) that enables trustless, peer-to-peer asset exchange between BNB Chain and other compatible blockchains.
The specification mandates a strict sequence of actions: one party initiates the swap by creating an HTLC containing a hash of a secret, the other party claims the funds by revealing the secret, and if the secret is not revealed before the deadline, the original depositor can reclaim their assets. For builders, implementing BEP-3 correctly requires precise handling of the sha256 preimage, the absolute timelock, and the cross-chain message format defined in the standard. A mismatch in any of these parameters between the two chains can lead to a permanent loss of funds or a failure to complete the swap.
Wallets, DEXs, and cross-chain application developers integrating native atomic swap functionality must implement BEP-3's HTLC interface. The standard's security model depends entirely on the correctness of the timelock and hashlock logic, making it a critical target for formal verification and security review. Chainscore Labs can review HTLC implementations for edge cases in timelock validation, secret management, and cross-chain compatibility to prevent fund-locking vulnerabilities.
BEP-3 Quick Facts
A technical reference table for the Hash Time-Locked Contract (HTLC) standard enabling trustless cross-chain asset swaps on BNB Chain.
| Field | Value | Why it matters |
|---|---|---|
BEP Standard | BEP-3 | Defines the canonical interface for HTLCs on BNB Chain, which all compatible wallets and DEXs must implement. |
Core Mechanism | Hash Time-Locked Contract (HTLC) | Uses hashlock and timelock primitives to guarantee atomicity: either both parties complete the swap or both receive a refund. |
Trust Model | Trustless, peer-to-peer | Eliminates counterparty risk without requiring a third-party custodian or centralized exchange. |
Primary Actors | DEX builders, wallet providers, cross-chain bridge developers | These teams must implement the BEP-3 specification to enable native cross-chain trading functionality. |
Cross-Chain Scope | BNB Chain and any other chain supporting HTLCs with compatible hash functions | Interoperability depends on both chains supporting the same hash algorithm and timelock logic. |
Critical Security Parameters | Hashlock preimage secrecy, timelock duration, refund logic | Incorrect implementation of these parameters can lead to fund loss, indefinite locking, or griefing attacks. |
Operational Dependency | Participants must remain online to claim or refund before expiry | Wallets and relayers need robust monitoring to detect pending swaps and execute claims within the timelock window. |
Specification Status | Verify against the canonical BEP-3 specification on the BNB Chain GitHub | Implementers must reference the final, accepted specification to ensure compatibility with the wider ecosystem. |
HTLC Mechanism and Contract Logic
The core contract logic enabling atomic swaps on BNB Chain through hashlock and timelock enforcement.
BEP-3 defines a Hash Time-Locked Contract (HTLC) as the foundational primitive for trustless cross-chain asset exchanges on BNB Chain. The mechanism binds two parties across independent ledgers without requiring a centralized intermediary. An initiator locks assets into a contract on BNB Chain, generating a cryptographic hash of a secret s. A counterparty on the other chain can then lock their assets using the same hash. The swap completes atomically: if the initiator reveals the secret s to claim the counterparty's assets, the counterparty can extract s from that transaction and use it to claim the BNB Chain side. If either party abandons the swap, timelocks ensure assets are refundable after a predefined expiry, preventing permanent capital loss.
The contract logic enforces two critical constraints. The hashlock requires the claimant to provide a preimage that hashes to the agreed-upon value, ensuring only the secret holder can unlock the funds. The timelock creates a race condition where the claim must occur before a block height or timestamp deadline. On BNB Chain, the HTLC implementation uses SHA-256 for hashing and supports both native BNB and BEP-2/BEP-20 tokens, with the contract address acting as an escrow. Operators must carefully configure the timelock delta between the two chains to account for block time variance and confirmation latency, ensuring the initiator has sufficient time to reveal the secret on the counterparty chain before the BNB Chain refund window opens.
Builders integrating BEP-3 HTLCs must handle several operational edge cases. If a contract is deployed with an insufficient timelock delta, the initiator risks losing the secret without claiming the counterparty's assets—a partial-fill scenario that breaks atomicity. Wallets and DEX interfaces must monitor both chains for Claimed and Refunded events to correctly update user balances and prevent double-spend attempts. Chainscore Labs can review HTLC implementations for timelock parameter safety, hashlock collision resistance, and cross-chain event monitoring logic to ensure atomic swap integrations remain secure under mainnet conditions.
Who Is Affected
DEX & Swap Builders
Teams building native cross-chain DEXs or swap interfaces are the primary implementers. You must correctly implement the full HTLC lifecycle: HTLT, Claim, and Refund.
Key actions:
- Ensure your contract logic enforces the exact hashlock and timelock constraints defined in the spec.
- Validate that the
randomNumberHashcomputation matches the off-chain counterparty's expected algorithm. - Implement robust monitoring for
HTLTevents to detect counterparty funding. - Design your refund mechanism to be safe against race conditions where a claim and refund could be submitted in the same block.
Chainscore can review your HTLC implementation for timelock and hashlock security, ensuring cross-chain swap integrity.
Implementation and Integration Impact
Practical guidance for teams implementing BEP-3 atomic swaps, covering contract security, timelock management, and cross-chain compatibility requirements.
Timelock Parameter Selection
The security of an atomic swap depends on the relative durations of the initiator's and participant's timelocks. The initiator must have a longer refund window than the participant to prevent a scenario where the initiator refunds after the participant has claimed. Teams must also account for block time variance and potential chain congestion on both BSC and the counterparty chain. Incorrect parameterization can lead to permanent fund loss. Chainscore can model timelock safety margins for your specific cross-chain pair.
Cross-Chain Compatibility Verification
While BEP-3 is designed for interoperability, subtle differences in opcode pricing, precompile behavior, or block timestamp semantics between BSC and the counterparty chain can break swap logic. Implementers must verify that the same hash function (SHA-256) and the same timelock enforcement mechanism behave identically on both chains. This is especially critical when swapping with non-EVM chains. Chainscore can perform a comparative analysis of your HTLC contracts across target execution environments.
Wallet and DEX Integration Requirements
Wallets integrating BEP-3 must manage the full swap lifecycle: initiating with a secret hash, monitoring the counterparty chain for a claim transaction, and submitting the preimage to finalize the swap. DEXs building on atomic swaps need robust event listeners to detect HTLC funding, claims, and refunds. Failure to monitor the counterparty chain in real-time can result in a user's secret being revealed without their claim being executed locally. Chainscore can review your event monitoring and transaction submission architecture.
Secret Management and Key Security
The cryptographic secret used in the hashlock is the single point of trust in an atomic swap. If the secret is generated with insufficient entropy, is reused across swaps, or is exposed during the signing process, an attacker can claim funds on both chains. Implementations must use cryptographically secure random number generation and ensure the secret is never logged, transmitted in plaintext, or stored in a recoverable format before the swap is complete. Chainscore can audit your secret lifecycle management.
Relayer and Watchtower Operations
For user experience, many atomic swap implementations rely on relayers to submit claim or refund transactions on behalf of users. These relayers must be designed with strict authorization controls to prevent theft of the secret or unauthorized fund movement. A compromised relayer can drain all in-flight swaps. Teams should also consider watchtower services that monitor for timelock expiry and automatically trigger refunds. Chainscore can assess the security model of your relayer network and authorization scheme.
Security and Operational Risk Matrix
Evaluates the security, operational, and integration risks that wallets, DEXs, and cross-chain protocols must manage when implementing or relying on the BEP-3 atomic swap standard.
| Area | Failure Mode | Affected Actors | Severity | Mitigation and Validation |
|---|---|---|---|---|
Timelock Configuration | Insufficient timelock duration allows a counterparty to claim funds on one chain and refund on the other before the swap completes. | DEX builders, wallet providers, cross-chain application developers | Critical | Implement configurable timelocks based on target chain block times and congestion. Review against canonical BEP-3 specification. |
Hashlock Secret Management | Weak randomness or premature disclosure of the secret allows an attacker to claim funds on both chains without fulfilling the swap. | Wallet providers, users, DEX operators | Critical | Use cryptographically secure random number generation. Audit secret generation, storage, and disclosure logic. Chainscore can review secret lifecycle management. |
Cross-Chain Replay Attacks | A valid HTLC claim transaction on one chain is replayed on another chain with a compatible address format, leading to unintended fund release. | Exchanges, custodians, bridge operators | High | Enforce unique chain IDs in transaction payloads. Verify replay protection mechanisms are active on all integrated chains. |
Contract State Inconsistency | A node or RPC provider returns stale or forked state, causing a wallet to incorrectly display an HTLC as refundable or claimable. | Wallet providers, RPC infrastructure teams, users | High | Query multiple nodes and require a minimum number of confirmations before acting on HTLC state. Implement circuit breakers for RPC anomalies. |
Smart Contract Vulnerability | A bug in the HTLC contract implementation (e.g., reentrancy, overflow) allows an attacker to drain locked funds or lock them permanently. | Protocol developers, DEX builders, auditors | Critical | Conduct a dedicated security audit of the HTLC implementation. Chainscore can perform a focused review of timelock and hashlock logic. |
Refund Path Liveness | A user or automated system fails to submit the refund transaction before the timelock expires, permanently losing access to the locked asset. | Users, market makers, automated trading bots | Medium | Build robust, redundant refund relayers with monitoring and alerting. Simulate refund scenarios under high network congestion. |
Counterparty Liveness | The initiating party never reveals the secret, forcing the other party to wait for the full timelock period to expire before refunding, locking capital. | Users, market makers, liquidity providers | Medium | Set appropriate timelocks that balance capital efficiency with counterparty risk. Monitor for griefing patterns and blacklist malicious peers. |
HTLC Implementation Review Checklist
A technical checklist for teams implementing Hash Time-Locked Contracts (HTLCs) per the BEP-3 standard. This review focuses on the security-critical interplay between hashlock and timelock mechanisms, cross-chain compatibility, and edge cases that can lead to permanent fund loss or griefing attacks.
Verify that the hashlock is constructed using a cryptographically secure hash function (SHA-256) and that the preimage is validated correctly on both chains.
- What to check: The contract must store the exact 32-byte hash provided by the initiator. The
claimfunction must hash the supplied preimage and compare it strictly against the stored hash. Confirm that no other data (e.g., addresses, amounts) is mixed into the preimage hash unless explicitly required by a higher-level protocol. - Why it matters: A mismatch in hashing algorithms or a failure to validate the preimage correctly allows a counterparty to claim funds without revealing the secret, breaking the atomicity guarantee. If the preimage is not validated on-chain, the swap is not trustless.
- Readiness signal: Unit tests demonstrate that a correct preimage successfully claims the contract and that an incorrect preimage is rejected with a clear error. Fuzz testing confirms no hash collision or preimage truncation vulnerabilities exist.
Canonical Resources
Use these resources to validate BEP-3 Atomic Swap implementations, track specification changes, and review HTLC assumptions before exposing cross-chain swap flows to users.
Implementation Review Checklist
Maintain an internal checklist that turns BEP-3 into testable controls: cryptographically strong preimage generation, exact hash algorithm agreement, timeout ordering with a safety buffer, chain reorg tolerance, fee availability for claim and refund transactions, replay protection, idempotent backend processing, and alerting for swaps approaching expiry. Chainscore Labs can review HTLC implementations against these controls and help teams identify refund races, stuck-fund paths, and unsafe assumptions in wallet or DEX automation.
Looking to build on a specific blockchain?
We build smart contracts, DeFi applications, wallets, tokenization platforms, and blockchain infrastructure across the major ecosystems teams choose today. That includes Ethereum, Arbitrum, Optimism, Polygon, Avalanche, Solana, Sui, Aptos, Hedera, Stellar, and NEAR, with support for additional EVM and non-EVM networks based on your product requirements.
EVM ecosystems
- Ethereum
- Arbitrum
- Optimism
- Polygon
- Avalanche
- Cronos

Non-EVM ecosystems
- Solana
- Sui
- Aptos
- Hedera
- Stellar
- NEAR
Additional ecosystems
- Polkadot
- Cosmos
- TON
- Cardano
- Algorand
- Tempo
Also available for Base, appchains, custom EVM networks, and cross-chain product architecture.
Frequently Asked Questions
Common questions from teams implementing, integrating, or reviewing BEP-3 Hash Time-Locked Contracts for cross-chain atomic swaps.
The security of a BEP-3 atomic swap depends entirely on three parameters set at contract creation:
- Hashlock: The hash of a secret preimage. The contract must verify that
sha256(preimage)matches this hash exactly. Any deviation in the hashing function or input encoding breaks the swap. - Timelock: The block height or timestamp after which the sender can reclaim funds. This must be set far enough in the future to allow the counterparty to claim, but not so far that capital is locked indefinitely.
- Recipient address: The only address authorized to claim the funds by revealing the preimage. Sending to an incorrect or uninitialized contract address results in permanent loss.
Teams should also verify that the contract correctly handles the edge case where both claim and refund are callable in the same block—the claim must take priority.
Delivering blockchain solutions for 5+ years.
We have partnered with 50+ leading DeFi protocols, NFT ecosystems, and fintech innovators to build secure, scalable, and capital-efficient blockchain products.
Selected Partners & Clients
“I've been working with Chainscore Labs for last 3+ years, they've consistently delivered with strong ownership across multiple projects. The team is reliable and detail-oriented.”
How to get started?
If you're looking for blockchain integration, ChainScore Labs has 5+ years of experience helping teams build and integrate exchanges, wallets, smart contracts, tokenization solutions, and protocol-connected products, we can help you choose the right path, integrate securely, and get to production faster. Our team consists of experienced blockchain developers and architects who can help you with your blockchain integration needs.
Exploration & Strategy
Define your product goals and choose the right blockchain architecture for your use case.
Architecture & Design
Design the smart contracts, tokenomics, and security parameters of your system.
Development & Integration
Build and integrate with wallets, oracles, and front-end dApps for a seamless experience.
Security & Launch
Comprehensive audits followed by a risk-managed mainnet deployment to protect your users.
Discover our
blockchain development services.
We build production-grade blockchain solutions for top-tier projects across DeFi and Web3.
Need a blockchain engineering team?
Send the project context and we will respond with next steps, scope questions, and a practical path to delivery.


