Bsc Bridge#
Basic Contract Information#
Contract Name: Bsc Bridge
Dependencies:
@openzeppelin/contracts-upgradeable
@openzeppelin/contracts
Custom interface IBscBridge
Inheritance:
Initializable
PausableUpgradeable
OwnableUpgradeable
UUPSUpgradeable
Core Functions#
1. Role Permission Management#
Relayers: A whitelist of authorized relayer addresses managed through mapping(address => bool)
Only contract Owner can manage relayer list through addRelayer()/removeRelayer()
Relayers have permission to call mintLLA() for cross-chain minting
Owner: Has highest privileges: upgrade contract, pause/unpause, set token address, manage funds, etc.
2. Cross-chain Minting Process#
mintLLA() Function Logic:
function mintLLA(address user, uint256 amount, bytes32 txHash)
Input Validation:
User address validity (user != address(0))
Minting amount positive (amount > 0)
Transaction hash uniqueness (!processedHashes[txHash])
State Update:
Mark transaction hash as processed (processedHashes[txHash] = true)
Core Operation:
Call LLA token contract’s mint() method to mint tokens for user
3. Emergency Handling Mechanism#
Fund Withdrawal:
function emergencyWithdraw(address tokenAddress, address to, uint256 amount)
Allows Owner to withdraw any ERC20 tokens
Contract Pause:
function pause()/unpause()
Security Mechanisms#
1. Protection Measures#
Mechanism |
Implementation |
---|---|
Replay Attack Protection |
processedHashes mapping records processed transaction hashes |
Permission Isolation |
Role separation through onlyOwner and onlyRelayer |
Input Validation |
Critical parameter non-zero checks (address, amount) |
Upgradability Control |
UUPS proxy pattern + _authorizeUpgrade only allows Owner operation |
Architecture Flow Chart#
