HUID Token

The HUID token is an ERC20-compliant token with additional features for bulk transfers and approvals. It is designed to be upgradeable using a proxy pattern and supports cross-chain transfers through

Core Features

  • ERC20 Standard: The token implements the standard ERC20 interface, including functions like transfer, approve, balanceOf, etc.

  • Bulk Operations:

    • transferBulk: Allows for sending tokens to multiple addresses in a single transaction, reducing gas costs.

    • increaseApprovalBulk: Enables increasing the allowance for multiple spenders at once.

  • Detailed Error Handling: The contract uses custom errors to provide more specific information about failed transactions.

Proxy (Upgradeable) Functionality (Testnet Only)

Disclaimer: The proxy contract described here is intended for testnet and testing purposes only. It is being used to facilitate testing and development until the HUID token contract is finalized. The production version of the HUID token will not use a proxy contract.

The HUIDToken is deployed behind a HUIDTokenProxy contract on the testnet. This allows the token's logic to be upgraded without requiring a token migration during the development and testing phases.

  • HUIDTokenProxy: A simple proxy contract that delegates all calls to the implementation contract (the HUIDToken).

  • upgradeTo: The owner of the proxy can call this function to point the proxy to a new HUIDToken implementation contract.

Bridge for Cross-Chain Transfers

A Bridge contract facilitates the movement of HUID tokens between different blockchains.

  • lock: Users can lock their tokens in the bridge on the source chain. This emits an event that a relayer can use to mint tokens on the destination chain.

  • unlock: The relayer (as the owner of the bridge) can unlock tokens on the source chain when tokens are burned on the destination chain.

  • Nonce: A nonce is used to prevent replay attacks, ensuring that each lock/unlock operation can only be processed once.

Smart Contract Code Analysis

HUIDToken.sol

  • Solidity Version: The contract is written for Solidity version 0.8.24.

  • Error Handling: It uses custom errors for more gas-efficient and descriptive error reporting.

  • Bulk Operations: The transferBulk and increaseApprovalBulk functions iterate through arrays to perform multiple operations. While this is a useful feature, it's important to be mindful of the gas limits on the blockchain. The contract includes a BULK_MAX_COUNT constant to limit the number of operations in a single bulk transaction.

  • Safety: The contract includes checks for zero addresses and insufficient balances to prevent common vulnerabilities.

HUIDTokenProxy.sol

  • Delegatecall: The proxy uses a fallback function with delegatecall to forward all calls to the implementation contract. This is a standard and efficient way to implement a proxy.

  • Ownable: The upgradeTo function is protected by an onlyOwner modifier, ensuring that only the owner of the proxy can change the implementation address.

Bridge.sol

  • Ownable: The unlock function is restricted to the owner of the contract, which should be the off-chain relayer.

  • Nonce: The usedNonces mapping is a critical security feature to prevent replay attacks.

  • Token Transfer: The bridge interacts with the HUIDToken contract to transfer tokens using transferFrom for locking and transfer for unlocking.

Last updated