HUID Token Bridge

The Bridge.sol contract is designed to facilitate the transfer of HUID tokens between different blockchains. This is achieved by locking tokens on the source chain and then minting an equivalent amount on the destination chain. An off-chain relayer is responsible for monitoring events on the source chain and executing the corresponding actions on the destination chain.

How it Works

The bridge operates on a lock-and-unlock mechanism:

  1. Locking: A user on the source chain calls the lock function, specifying the recipient address on the destination chain, the amount of tokens to transfer, and a unique nonce. The tokens are then transferred from the user to the bridge contract.

  2. Event Emission: The lock function emits a TokensLocked event, which is monitored by the off-chain relayer.

  3. Minting on Destination Chain: The relayer, upon detecting the TokensLocked event, mints an equivalent number of tokens on the destination chain and sends them to the recipient address.

  4. Unlocking: When a user wants to transfer tokens back to the source chain, they burn the tokens on the destination chain. The relayer detects this and calls the unlock function on the source chain's bridge contract. This releases the locked tokens to the user.

Key Functions

  • lock(address _to, uint256 _amount, uint256 _nonce): This function is called by the user to initiate a cross-chain transfer. It transfers the specified amount of HUID tokens from the user to the bridge contract.

  • unlock(address _to, uint256 _amount, uint256 _nonce): This function is called by the relayer (the owner of the contract) to release tokens to a user on the source chain.

Security Features

  • Ownable: The unlock function is restricted to the owner of the contract, which is the off-chain relayer. This prevents unauthorized withdrawal of tokens from the bridge.

  • Nonce: The usedNonces mapping is a critical security feature that prevents replay attacks. Each nonce can only be used once for both locking and unlocking, ensuring that a transaction cannot be processed multiple times.

Last updated