The Whitechain Bridge is a cross-chain bridge solution that enables secure token and coin transfers between Whitechain and other blockchain networks. This repository contains smart contracts for EVM-compatible networks, implementing a robust bridge architecture with advanced security features.
The bridge solution consists of two main smart contracts:
- Mapper Smart Contract: Manages token mappings between different chains
- Bridge Smart Contract: Handles cross-chain token and coin transfers
- Extends the Ownable interface and exposes a method
addTokenthat can be used only by theowner - Whitechain team uses a private key that belongs to the
ownerof the smart contract to set all required tokens via calling theaddTokenmethod
- A user navigates to the bridging screen in Whitechain Wallet to perform a bridge operation, selects the desired chains and tokens, and their amount
- Whitechain Wallet collects all selected data and makes a request to the backend, where this data is used to create a message and sign it with a dedicated private key
- The signed message is returned to the wallet, and the user signs a transaction to the Bridge Smart Contract
- Bridge Smart Contract exposes the
bridgeTokensmethod, which is executed - The
bridgeTokensmethod checks the signature and compares it with theownervalue - The
bridgeTokensmethod checks that selected bridge operation is valid against tokens config set in the Mapper smart contract - After all validations, the
bridgeTokensmethod emits an eventDeposit - Whitechain Bridge backend is listening for the
Depositevent from theBridgesmart contract on the origin chain and stores information about the bridging operation in a database - Whitechain Bridge backend executes the
receiveTokensmethod of theBridgesmart contract on the target chain receiveTokensusesonlyOwnermodifier to check that the transaction is executed by our backend with a dedicated private keyreceiveTokenssends tokens/coin to the address specified by a user and emitsWithdrawal- Whitechain Bridge backend is listening for the
Withdrawalevent from theBridgesmart contract and updates information in a database that the bridging operation is completed
bridge-contracts/
├── ether/ # Ethereum network contracts
│ ├── contracts/ # Solidity contracts
│ │ ├── main/ # Production contracts
│ │ └── tests/ # Test contracts
│ ├── test/ # TypeScript tests
│ ├── scripts/ # Deployment and utility scripts
│ ├── docs/ # Generated documentation
│ └── ignition/ # Hardhat Ignition deployment configs
├── tron/ # Tron network contracts
│ ├── contracts/ # Solidity contracts
│ │ ├── main/ # Production contracts
│ └── test/ # TypeScript tests
└── docs/ # Tron network contracts
└── README.md # Whitechain Bridge high-level overview
- Reentrancy Protection: Uses OpenZeppelin's ReentrancyGuard
- Signature Validation: ECDSA signature verification for all bridge operations
- Replay Attack Prevention: Tracks used message hashes
- Cross-chain Token Mapping: Supports token mappings between different chains
- Lock/Burn and Unlock/Mint: Flexible token handling mechanisms
- Native Coin Support: Handles both ERC20 tokens and native coins
- Configurable Transfer Methods: Supports both direct transfer and safe transfer methods
- UUPS Proxy Pattern: All contracts are upgradeable using OpenZeppelin's UUPS pattern
- Storage Gap: Reserved storage slots for future upgrades
- Ownership Transfer: Secure ownership transfer mechanisms
The main contract for cross-chain token transfers with the following key features:
- Cross-chain token and coin transfers
- ECDSA signature validation
- Gas fee accumulation
- Event emission for backend monitoring
Manages token mappings between chains with:
- Token registration and configuration
- Deposit and withdrawal type management
- Chain-specific token address mapping
- Token validation for bridge operations
- Mainnet: Production Ethereum network
- Sepolia: Sepolia testnet
- Localhost: Local development network
- Mainnet: Production Whitechain network
- Testnet: Whitechain testnet
- Devnet: Whitechain development network
- Mainnet: Production Tron network
- Nile: Nile testnet
- Node.js (v16 or higher)
- npm or yarn
- Hardhat (for Ethereum contracts)
- Tronbox (for Tron contracts)
cd ether
npm installcd tron
npm installcd ether
npm run compile
cd tron
npm run compilecd ether
npm run test
cd tron
npm run testcd ether
npm run prettier
npm run solhintLocalhost:
cd ether
npm run deploy-Mapper:localhost
npm run deploy-Bridge:localhostMainnet:
cd ether
npm run deploy-Mapper:mainnet
npm run deploy-Bridge:mainnetSepolia Testnet:
cd ether
npm run deploy-Mapper:sepolia
npm run deploy-Bridge:sepoliaWhitechain:
cd ether
npm run deploy-Mapper:whitechain
npm run deploy-Bridge:whitechainTron Mainnet:
cd tron
npm run deploy-Mapper:mainnet
npm run deploy-Bridge:mainnetNile Testnet:
cd tron
npm run deploy-Mapper:nile
npm run deploy-Bridge:nilenpm run verify-Mapper:mainnet
npm run verify-Bridge:mainnetcd ether
npm run scripts-Mapper-setup:mainnet
npm run scripts-Mapper-setup:sepolia
npm run scripts-Mapper-setup:whitechain
cd tron
npm run scripts-Mapper-setup:mainnet
npm run scripts-Mapper-setup:nilecd ether
npm run docsDocumentation is generated in the docs/ directory and includes:
- Contract interfaces and implementations
- Function documentation
- Event descriptions
- Error handling
ether/docs/main/modules/bridge/Bridge.md- Bridge contract documentationether/docs/main/modules/mapper/Mapper.md- Mapper contract documentation
cd ether
npm run coverageether/test/modules/bridge/Bridge.ts- Bridge contract testsether/test/modules/mapper/Mapper.ts- Mapper contract tests
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions, please refer to the documentation or create an issue in the repository.