Bridge
Bridge smart contracts that allow users to move states between Ethereum and Taraxa chains.
Generated Foundry smart contract specs are available at: https://taraxa-project.github.io/bridge/index.html
Official Testnet Deployment
At the end of June 2024, the bridge was deployed on the official Taraxa testnet and serves as an active avenue to bridge tokens from ETH Holes to TARA and vice versa.
You can find out more about the deployment details in the TESTNET.md file.
Where to find important information
- DEPLOY.md - Deployment addresses
- FLOWS.md - Description of main flows
- INTEGRATION.md - Integration manual
Main contracts
- BridgeBase.sol
- EthBridge.sol
- TaraBridge.sol
- TokenConnectorLogic.sol
- NativeConnector.sol
- ERC20LockingConnector.sol
- ERC20MintingConnector.sol
There are main contracts on both chains that are finalizing states(changes list) and applies state changes from the other chain. Changes are verified against the Bridge Root that is requested from the light clients and is verified against the other chain consensus.
Light clients
Ethereum light client
Ethereum light client is deployed on Taraxa side and it is accepting Ethereum block headers and verifying them against the Ethereum consensus. So after the finalization of Ethereum header we can take state root from it and verify Bridge Root against it.
Taraxa light client
Taraxa light client will verify Taraxa Pillar blocks that are special type of blocks for this purpose. Pillar block will have Bridge Root in it, so we can directly use Bridge Root from it.
Connectors
Connectors are contracts that are deployed on both chains and they are:
- Finalizing state to transfer it to another chain.
- Applies changes from the other chain.
Interface could be found at IBridgeConnector.sol
Examples of connectors:
Scripts
The root Makefile contains a few useful commands that are used for development and testing.
make test
The scripts folder contains a few useful scripts that are used for development, deployment, contract registration and testing.
Contents
- ConnectorUpgradeableBase
- ERC20LockingConnector
- ERC20LockingConnectorLogic
- ERC20MintingConnector
- ERC20MintingConnectorLogic
- IBridgeConnector
- IERC20MintableBurnable
- NativeConnector
- NativeConnectorLogic
- TokenConnectorLogic
- Transfer
- TokenState
- USDTMintingConnector
- USDTMintingConnectorLogic
ConnectorUpgradeableBase
Inherits: OwnableUpgradeable, UUPSUpgradeable
Functions
constructor
Note: oz-upgrades-unsafe-allow: constructor
constructor();
__ConnectorUpgradeableBase_init
function __ConnectorUpgradeableBase_init(address bridge) public onlyInitializing;
__ConnectorUpgradeableBase_init_unchained
function __ConnectorUpgradeableBase_init_unchained(address bridge) internal onlyInitializing;
_authorizeUpgrade
function _authorizeUpgrade(address newImplementation) internal override onlyOwner;
ERC20LockingConnector
Inherits: ConnectorUpgradeableBase, Receiver, ERC20LockingConnectorLogic
Functions
initialize
function initialize(BridgeBase _bridge, IERC20 tokenAddress, address token_on_other_network)
public
payable
initializer;
ERC20LockingConnectorLogic
Inherits: TokenConnectorLogic
Functions
applyState
Applies the given state to the token contract by transfers.
function applyState(bytes calldata _state) public virtual override onlyBridge;
Parameters
Name | Type | Description |
---|---|---|
_state | bytes | The state to be applied. |
lock
The amount of tokens to burn must be approved by the sender
Locks the specified amount of tokens to transfer them to the other network.
function lock(uint256 value) public payable onlySettled;
Parameters
Name | Type | Description |
---|---|---|
value | uint256 | The amount of tokens to lock. |
Events
Locked
Events
event Locked(address indexed account, uint256 value);
ERC20MintingConnector
Inherits: ConnectorUpgradeableBase, Receiver, ERC20MintingConnectorLogic
Functions
initialize
function initialize(BridgeBase _bridge, IERC20MintableBurnable _token, address token_on_other_network)
public
initializer;
ERC20MintingConnectorLogic
Inherits: TokenConnectorLogic
Functions
applyState
Applies the given state to the token contract by transfers.
function applyState(bytes calldata _state) public virtual override onlyBridge;
Parameters
Name | Type | Description |
---|---|---|
_state | bytes | The state to be applied. |
burn
The amount of tokens to burn must be approved by the sender
Burns a specified amount of tokens to transfer them to the other network.
function burn(uint256 value) public payable onlySettled;
Parameters
Name | Type | Description |
---|---|---|
value | uint256 | The amount of tokens to burn |
Events
Burned
Events
event Burned(address indexed account, uint256 value);
IBridgeConnector
Interface for bridgeable contracts.
Functions
finalize
Finalizes the bridge operation and returns a bytes32 value hash.
function finalize(uint256 epoch) external returns (bytes32 finalizedHash);
Parameters
Name | Type | Description |
---|---|---|
epoch | uint256 | The epoch to be finalized |
Returns
Name | Type | Description |
---|---|---|
finalizedHash | bytes32 | of the finalized state |
applyState
Applies the given state to the bridgeable contract.
function applyState(bytes calldata _state) external;
Parameters
Name | Type | Description |
---|---|---|
_state | bytes | The state to apply. |
isStateEmpty
Checks if the state is empty.
function isStateEmpty() external view returns (bool);
Returns
Name | Type | Description |
---|---|---|
<none> | bool | true if the state is empty, false otherwise |
getFinalizedState
Retrieves the finalized state of the bridgeable contract.
function getFinalizedState() external view returns (bytes memory);
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | A bytes serialized finalized state |
getSourceContract
Returns the address of the underlying contract in this network
function getSourceContract() external view returns (address);
getDestinationContract
Returns the address of the bridged contract on the other network
function getDestinationContract() external view returns (address);
getStateLength
Returns the length of the state entries
function getStateLength() external view returns (uint256);
IERC20MintableBurnable
Inherits: IERC20
Functions
mintTo
Mints a specified amount of tokens and assigns them to the specified account.
function mintTo(address receiver, uint256 amount) external;
Parameters
Name | Type | Description |
---|---|---|
receiver | address | The address to which the tokens will be minted. |
amount | uint256 | The amount of tokens to be minted. |
burnFrom
*Destroys a value
amount of tokens from account
, deducting from
the caller's allowance.
See ERC20-_burn and {ERC20-allowance}.
Requirements:
- the caller must have allowance for
accounts
's tokens of at leastvalue
.*
function burnFrom(address account, uint256 value) external;
Parameters
Name | Type | Description |
---|---|---|
account | address | The address from which the tokens will be burnt. |
value | uint256 | The amount of tokens to burn. |
NativeConnector
Inherits: ConnectorUpgradeableBase, Receiver, NativeConnectorLogic
Functions
initialize
function initialize(BridgeBase _bridge, address token_on_other_network) public initializer;
NativeConnectorLogic
Inherits: TokenConnectorLogic
Functions
applyState
Applies the given state to the token contract by transfers.
function applyState(bytes calldata _state) public virtual override onlyBridge;
Parameters
Name | Type | Description |
---|---|---|
_state | bytes | The state to be applied. |
lock
This function is payable, meaning it can receive TARA.
Locks the specified amount of tokens to transfer them to the other network.
function lock(uint256 amount) public payable;
Events
Locked
Events
event Locked(address indexed account, uint256 value);
TokenConnectorLogic
Inherits: IBridgeConnector
State Variables
bridge
BridgeBase public bridge;
token
address public token;
otherNetworkAddress
address public otherNetworkAddress;
state
TokenState public state;
finalizedState
bytes public finalizedState;
Functions
onlySettled
modifier onlySettled();
onlyBridge
modifier onlyBridge();
estimateSettlementFee
function estimateSettlementFee(address locker) public view returns (uint256);
epoch
function epoch() public view returns (uint256);
decodeTransfers
function decodeTransfers(bytes memory data) internal pure returns (Transfer[] memory);
isStateEmpty
function isStateEmpty() external view override returns (bool);
getStateLength
function getStateLength() external view returns (uint256);
finalize
function finalize(uint256 epoch_to_finalize) public virtual override onlyBridge returns (bytes32);
getFinalizedState
Retrieves the finalized state of the bridgeable contract.
function getFinalizedState() public view override returns (bytes memory);
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | A bytes serialized finalized state |
getSourceContract
Returns the address of the underlying contract in this network
function getSourceContract() external view returns (address);
getDestinationContract
Returns the address of the bridged contract on the other network
function getDestinationContract() external view returns (address);
applyState
function applyState(bytes calldata) external virtual;
Events
Finalized
Events
event Finalized(uint256 indexed epoch);
AssetBridged
event AssetBridged(address indexed connector, address indexed account, uint256 value);
Transfer
struct Transfer {
address account;
uint256 amount;
}
TokenState
Inherits: Ownable
State Variables
epoch
uint256 public epoch;
accounts
address[] public accounts;
balances
mapping(address => uint256) public balances;
Functions
constructor
constructor(uint256 _epoch) Ownable(msg.sender);
hasBalance
function hasBalance(address account) public view returns (bool);
empty
function empty() public view returns (bool);
getStateLength
function getStateLength() public view returns (uint256);
setEpoch
function setEpoch(uint256 _epoch) public onlyOwner;
addAmount
function addAmount(address account, uint256 amount) public onlyOwner;
getTransfers
function getTransfers() public view returns (Transfer[] memory);
cleanup
function cleanup() public onlyOwner;
Events
TransferAdded
Events
event TransferAdded(address indexed account, uint256 amount);
USDTMintingConnector
Inherits: ConnectorUpgradeableBase, Receiver, USDTMintingConnectorLogic
Functions
initialize
function initialize(BridgeBase _bridge, IERC20MintableBurnable _token, address token_on_other_network)
public
initializer;
USDTMintingConnectorLogic
Inherits: TokenConnectorLogic
Functions
applyState
Applies the given state to the token contract by transfers.
function applyState(bytes calldata _state) public virtual override onlyBridge;
Parameters
Name | Type | Description |
---|---|---|
_state | bytes | The state to be applied. |
burn
The amount of tokens to burn must be approved by the sender
Burns a specified amount of tokens to transfer them to the other network.
function burn(uint256 value) public payable onlySettled;
Parameters
Name | Type | Description |
---|---|---|
value | uint256 | The amount of tokens to burn |
Events
Burned
Events
event Burned(address indexed account, uint256 value);
Contents
- StateNotMatchingBridgeRoot
- ConnectorAlreadyRegistered
- NotSuccessiveEpochs
- NotEnoughBlocksPassed
- InvalidStateHash
- InvalidBridgeRoot
- ZeroAddress
- ZeroAddressCannotBeRegistered
- NoStateToFinalize
- IncorrectOwner
- HashesNotMatching
- InvalidBlockInterval
- InvalidEpoch
- ThresholdNotMet
- DuplicateSignatures
- SignaturesNotSorted
- InsufficientFunds
- TransferFailed
- InvalidEpoch
- NotBridge
- NoFinalizedState
- ZeroValueCall
StateNotMatchingBridgeRoot
error StateNotMatchingBridgeRoot(bytes32 stateRoot, bytes32 bridgeRoot);
ConnectorAlreadyRegistered
error ConnectorAlreadyRegistered(address connector, address token);
NotSuccessiveEpochs
error NotSuccessiveEpochs(uint256 epoch, uint256 nextEpoch);
NotEnoughBlocksPassed
error NotEnoughBlocksPassed(uint256 lastFinalizedBlock, uint256 currentInterval, uint256 requiredInterval);
InvalidStateHash
error InvalidStateHash(bytes32 stateHash, bytes32 expectedStateHash);
InvalidBridgeRoot
error InvalidBridgeRoot(bytes32 bridgeRoot);
ZeroAddress
error ZeroAddress(string message);
ZeroAddressCannotBeRegistered
error ZeroAddressCannotBeRegistered();
NoStateToFinalize
error NoStateToFinalize();
IncorrectOwner
error IncorrectOwner(address owner, address expected);
HashesNotMatching
error HashesNotMatching(bytes32 expected, bytes32 actual);
InvalidBlockInterval
error InvalidBlockInterval(uint256 expected, uint256 actual);
InvalidEpoch
error InvalidEpoch(uint256 expected, uint256 actual);
ThresholdNotMet
error ThresholdNotMet(uint256 threshold, uint256 weight);
DuplicateSignatures
error DuplicateSignatures(address author);
SignaturesNotSorted
error SignaturesNotSorted();
InsufficientFunds
error InsufficientFunds(uint256 expected, uint256 actual);
TransferFailed
error TransferFailed(address target, uint256 amount);
InvalidEpoch
error InvalidEpoch(uint256 expected, uint256 actual);
NotBridge
error NotBridge(address sender);
NoFinalizedState
error NoFinalizedState();
ZeroValueCall
error ZeroValueCall();
Contents
EthBridge
Inherits: BridgeBase
Functions
initialize
function initialize(
IBridgeLightClient _lightClient,
uint256 _finalizationInterval,
uint256 _feeMultiplierFinalize,
uint256 _feeMultiplierApply,
uint256 _registrationFee,
uint256 _settlementFee
) public initializer;
__initialize_EthBridge_unchained
function __initialize_EthBridge_unchained(
IBridgeLightClient _lightClient,
uint256 _finalizationInterval,
uint256 _feeMultiplierFinalize,
uint256 _feeMultiplierApply,
uint256 _registrationFee,
uint256 _settlementFee
) internal onlyInitializing;
TaraClient
Inherits: IBridgeLightClient, OwnableUpgradeable, UUPSUpgradeable
State Variables
finalized
Contains the last finalized block
PillarBlock.FinalizedBlock public finalized;
finalizedBridgeRoots
Contains the last finalized block for each epoch
mapping(uint256 => bytes32) public finalizedBridgeRoots;
validatorVoteCounts
mapping(address => uint256) public validatorVoteCounts;
totalWeight
uint256 public totalWeight;
pillarBlockInterval
uint256 public pillarBlockInterval;
__gap
gap for upgrade safety <- can be used to add new storage variables(using up to 49 32 byte slots) in new versions of this contract If used, decrease the number of slots in the next contract that inherits this one(ex. uint256[48] __gap;)
uint256[49] __gap;
Functions
constructor
Note: oz-upgrades-unsafe-allow: constructor
constructor();
initialize
function initialize(uint256 _pillarBlockInterval) public initializer;
__TaraClient_init_unchained
function __TaraClient_init_unchained(uint256 _pillarBlockInterval) internal onlyInitializing;
_authorizeUpgrade
function _authorizeUpgrade(address newImplementation) internal override onlyOwner;
getFinalized
function getFinalized() public view returns (PillarBlock.FinalizedBlock memory);
getFinalizedBridgeRoot
Returns the finalized bridge root.
function getFinalizedBridgeRoot(uint256 epoch) external view returns (bytes32);
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | The finalized bridge root as a bytes32 value. |
processValidatorChanges
Processes the changes in validator weights.
function processValidatorChanges(PillarBlock.VoteCountChange[] memory validatorChanges) internal;
Parameters
Name | Type | Description |
---|---|---|
validatorChanges | PillarBlock.VoteCountChange[] | An array of VoteCountChange structs representing the changes in validator vote counts. |
finalizeBlocks
Finalizes blocks by verifying the signatures for the last blocks
function finalizeBlocks(PillarBlock.WithChanges[] memory blocks, CompactSignature[] memory lastBlockSigs) public;
Parameters
Name | Type | Description |
---|---|---|
blocks | PillarBlock.WithChanges[] | list of PillarBlockWithChanges. |
lastBlockSigs | CompactSignature[] | An array of Signature structs representing the signatures of the last block. |
getSignaturesWeight
Calculates the total weight of the signatures
function getSignaturesWeight(bytes32 h, CompactSignature[] memory signatures) public view returns (uint256 weight);
Parameters
Name | Type | Description |
---|---|---|
h | bytes32 | The hash for verification. |
signatures | CompactSignature[] | An array of signatures. |
Returns
Name | Type | Description |
---|---|---|
weight | uint256 | The total weight of the signatures. |
Events
BlockFinalized
Events
event BlockFinalized(PillarBlock.FinalizedBlock indexed finalized);
Contents
- BridgeBase
- BridgeUSDT
- CompactSignature
- Constants
- IBridgeLightClient
- Maths
- PillarBlock
- Receiver
- SharedStructs
- TestERC20
- USDT
BridgeBase
Inherits: Receiver, OwnableUpgradeable, UUPSUpgradeable
State Variables
connectors
Mapping of connectors to the token address
mapping(address => IBridgeConnector) public connectors;
localAddress
Mapping of source and destination addresses to the connector address
mapping(address => address) public localAddress;
bridgeRoots
The bridge roots of finalized epochs
mapping(uint256 => bytes32) public bridgeRoots;
lightClient
The light client used to get the finalized bridge root
IBridgeLightClient public lightClient;
tokenAddresses
The addresses of the registered tokens
address[] public tokenAddresses;
finalizedEpoch
The epoch of the last finalized epoch
uint256 public finalizedEpoch;
appliedEpoch
The epoch of the last applied epoch
uint256 public appliedEpoch;
finalizationInterval
The interval between epoch finalizations
uint256 public finalizationInterval;
lastFinalizedBlock
The block number of the last finalized epoch
uint256 public lastFinalizedBlock;
feeMultiplierFinalize
This multiplier is used to calculate the proper part of the relaying cost for bridging actions(state finalization)
uint256 public feeMultiplierFinalize;
feeMultiplierApply
This multiplier is used to calculate the proper part of the relaying cost for bridging actions(state application)
uint256 public feeMultiplierApply;
registrationFee
Global connector registration fee. Connectors must pay this fee to register
uint256 public registrationFee;
settlementFee
Global transaction settlement fee. Connector must pay settlementFee * numberOfTransactions
to settle the transaction
uint256 public settlementFee;
__gap
gap for upgrade safety <- can be used to add new storage variables(using up to 49 32 byte slots) in new versions of this contract If used, decrease the number of slots in the next contract that inherits this one(ex. uint256[48] __gap;)
uint256[49] __gap;
Functions
constructor
Note: oz-upgrades-unsafe-allow: constructor
constructor();
__BridgeBase_init
function __BridgeBase_init(
IBridgeLightClient _lightClient,
uint256 _finalizationInterval,
uint256 _feeMultiplierFinalize,
uint256 _feeMultiplierApply,
uint256 _registrationFee,
uint256 _settlementFee
) internal onlyInitializing;
__BridgeBase_init_unchained
function __BridgeBase_init_unchained(
IBridgeLightClient _lightClient,
uint256 _finalizationInterval,
uint256 _feeMultiplierFinalize,
uint256 _feeMultiplierApply,
uint256 _registrationFee,
uint256 _settlementFee
) internal onlyInitializing;
_authorizeUpgrade
function _authorizeUpgrade(address newImplementation) internal override onlyOwner;
setFeeMultiplierFinalize
Only the owner can call this function.
Sets the fee multiplier for finalizing epochs.
function setFeeMultiplierFinalize(uint256 _feeMultiplierFinalize) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_feeMultiplierFinalize | uint256 | The fee multiplier for finalizing epochs. |
setFeeMultiplierApply
Only the owner can call this function.
Sets the fee multiplier for applying epochs.
function setFeeMultiplierApply(uint256 _feeMultiplierApply) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_feeMultiplierApply | uint256 | The fee multiplier for applying epochs. |
setSettlementFee
Only the owner can call this function.
Sets the settlement fee.
function setSettlementFee(uint256 _settlementFee) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_settlementFee | uint256 | The settlement fee to be set. |
setFinalizationInterval
Only the owner can call this function.
Sets the finalization interval.
function setFinalizationInterval(uint256 _finalizationInterval) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_finalizationInterval | uint256 | The finalization interval to be set. |
setLightClient
Only the owner can call this function.
Sets the light client.
function setLightClient(IBridgeLightClient _lightClient) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_lightClient | IBridgeLightClient | The address of the light client contract. |
setConnectorOwner
Only the owner can call this function.
Changes the connector owner.
function setConnectorOwner(address connector_address, address newOwner) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
connector_address | address | The connector address. |
newOwner | address | The new owner address. |
removeConnector
Only the owner can call this function.
Removes a connector from the bridge.
function removeConnector(address connector_address) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
connector_address | address | The connector address. |
withdrawFunds
Only the owner can call this function.
Withdraws the funds from the contract.
function withdrawFunds() public onlyOwner;
registeredTokens
function registeredTokens() public view returns (address[] memory);
Returns
Name | Type | Description |
---|---|---|
<none> | address[] | An array of addresses of the registered tokens. |
getBridgeRoot
Gets the bridge root for the given epoch.
function getBridgeRoot(uint256 epoch) public view returns (bytes32);
Parameters
Name | Type | Description |
---|---|---|
epoch | uint256 | The epoch for which the bridge root is to be retrieved. |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | The bridge root as a bytes32 value. |
getBridgeRoot
Returns the latest bridge root.
DO NOT REMOVE! Is used by the node to put it to the pillar block
function getBridgeRoot() public view returns (bytes32);
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | The latest bridge root as a bytes32 value. |
registerConnector
Registers a contract with the EthBridge by providing a connector contract.
function registerConnector(IBridgeConnector connector) public payable;
Parameters
Name | Type | Description |
---|---|---|
connector | IBridgeConnector | The address of the connector contract. |
removeTokenAddress
function removeTokenAddress(address tokenAddress) internal;
delistConnector
function delistConnector(IBridgeConnector connector) internal;
applyState
Applies the given state with proof to the contracts.
function applyState(SharedStructs.StateWithProof calldata state_with_proof) public;
Parameters
Name | Type | Description |
---|---|---|
state_with_proof | SharedStructs.StateWithProof | The state with proof to be applied. |
shouldFinalizeEpoch
Checks whether the current epoch should be finalized.
DO NOT REMOVE! Is used by the node to identify if we need to call a finalization
function shouldFinalizeEpoch() public view returns (bool);
Returns
Name | Type | Description |
---|---|---|
<none> | bool | A boolean value indicating whether the current epoch should be finalized. |
finalizeEpoch
Finalizes the current epoch.
function finalizeEpoch() public;
getStateWithProof
function getStateWithProof() public view returns (SharedStructs.StateWithProof memory ret);
Returns
Name | Type | Description |
---|---|---|
ret | SharedStructs.StateWithProof | finalized states with proof for all tokens |
Events
Finalized
Events
event Finalized(uint256 indexed epoch, bytes32 bridgeRoot);
ConnectorRegistered
event ConnectorRegistered(address indexed connector, address indexed token_source, address indexed token_destination);
ConnectorDelisted
event ConnectorDelisted(address indexed connector, uint256 indexed epoch);
BridgeUSDT
Inherits: ERC20
Functions
constructor
constructor() ERC20("BridgeUSDT", "USDT");
decimals
function decimals() public pure override returns (uint8);
CompactSignature
struct CompactSignature {
bytes32 r;
bytes32 vs;
}
Constants
State Variables
NATIVE_TOKEN_ADDRESS
address public constant NATIVE_TOKEN_ADDRESS = address(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
MINIMUM_CONNECTOR_DEPOSIT
uint256 public constant MINIMUM_CONNECTOR_DEPOSIT = 0.001 ether;
IBridgeLightClient
Functions
getFinalizedBridgeRoot
function getFinalizedBridgeRoot(uint256 epoch) external view returns (bytes32);
Maths
Functions
add
function add(uint256 a, int256 b) internal pure returns (uint256);
PillarBlock
Functions
fromBytes
function fromBytes(bytes memory b) internal pure returns (WithChanges memory);
getHash
function getHash(bytes memory b) internal pure returns (bytes32);
getHash
function getHash(WithChanges memory b) internal pure returns (bytes32);
getHash
function getHash(Vote memory b) internal pure returns (bytes32);
getHash
function getHash(SignedVote memory b) internal pure returns (bytes32);
getVoteHash
function getVoteHash(WithChanges memory b) internal pure returns (bytes32);
getVoteHash
function getVoteHash(uint256 period, bytes32 bh) internal pure returns (bytes32);
Structs
VoteCountChange
Vote count change coming from a validator Encapsulates the address of the validator and the vote count of the validator vote(signature)
struct VoteCountChange {
address validator;
int32 change;
}
FinalizationData
struct FinalizationData {
uint256 period;
bytes32 stateRoot;
bytes32 prevHash;
bytes32 bridgeRoot;
uint256 epoch;
}
WithChanges
struct WithChanges {
FinalizationData block;
VoteCountChange[] validatorChanges;
}
FinalizedBlock
struct FinalizedBlock {
bytes32 blockHash;
FinalizationData block;
uint256 finalizedAt;
}
Vote
struct Vote {
uint256 period;
bytes32 block_hash;
}
SignedVote
struct SignedVote {
Vote vote;
CompactSignature signature;
}
Receiver
Functions
receive
receive() external payable;
SharedStructs
Functions
getBridgeRoot
function getBridgeRoot(uint256 epoch, ContractStateHash[] memory state_hashes) internal pure returns (bytes32);
Structs
StateWithAddress
struct StateWithAddress {
address contractAddress;
bytes state;
}
ContractStateHash
struct ContractStateHash {
address contractAddress;
bytes32 stateHash;
}
BridgeState
struct BridgeState {
uint256 epoch;
StateWithAddress[] states;
}
StateWithProof
struct StateWithProof {
BridgeState state;
ContractStateHash[] state_hashes;
}
TestERC20
Inherits: ERC20, Ownable, IERC20MintableBurnable
Functions
constructor
constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) Ownable(msg.sender);
mintTo
Mints a specified amount of tokens and assigns them to the specified account.
function mintTo(address receiver, uint256 amount) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
receiver | address | The address to which the tokens will be minted. |
amount | uint256 | The amount of tokens to be minted. |
burnFrom
*Destroys a value
amount of tokens from account
, deducting from
the caller's allowance.
See ERC20-_burn and {ERC20-allowance}.
Requirements:
- the caller must have allowance for
accounts
's tokens of at leastvalue
.*
function burnFrom(address account, uint256 value) public virtual onlyOwner;
USDT
Inherits: ERC20, Ownable, IERC20MintableBurnable
Functions
constructor
constructor() ERC20("Tether USD", "USDT") Ownable(msg.sender);
decimals
function decimals() public pure override returns (uint8);
mintTo
Mints a specified amount of tokens and assigns them to the specified account.
function mintTo(address receiver, uint256 amount) public onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
receiver | address | The address to which the tokens will be minted. |
amount | uint256 | The amount of tokens to be minted. |
burnFrom
*Destroys a value
amount of tokens from account
, deducting from
the caller's allowance.
See ERC20-_burn and {ERC20-allowance}.
Requirements:
- the caller must have allowance for
accounts
's tokens of at leastvalue
.*
function burnFrom(address account, uint256 value) public virtual onlyOwner;
Contents
EthClient
Inherits: IBridgeLightClient, OwnableUpgradeable, UUPSUpgradeable
State Variables
client
BeaconLightClient public client;
ethBridgeAddress
address public ethBridgeAddress;
bridgeRootsMappingPosition
bytes32 public bridgeRootsMappingPosition;
lastEpoch
uint256 public lastEpoch;
bridgeRoots
mapping(uint256 => bytes32) public bridgeRoots;
__gap
gap for upgrade safety <- can be used to add new storage variables(using up to 49 32 byte slots) in new versions of this contract If used, decrease the number of slots in the next contract that inherits this one(ex. uint256[48] __gap;)
uint256[49] __gap;
Functions
constructor
Note: oz-upgrades-unsafe-allow: constructor
constructor();
initialize
function initialize(BeaconLightClient _client, address _eth_bridge_address) public initializer;
_authorizeUpgrade
function _authorizeUpgrade(address newImplementation) internal override onlyOwner;
setBeaconLightClient
Sets the BeaconLightClient instance.
function setBeaconLightClient(BeaconLightClient _client) external onlyOwner;
Parameters
Name | Type | Description |
---|---|---|
_client | BeaconLightClient | The address of the new BeaconLightClient contract. |
getFinalizedBridgeRoot
Implements the IBridgeLightClient interface method
function getFinalizedBridgeRoot(uint256 epoch) external view returns (bytes32);
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | The finalized bridge root as a bytes32 value. |
bridgeRootKeyByEpoch
function bridgeRootKeyByEpoch(uint256 epoch) public view returns (bytes32);
processBridgeRoot
Processes the bridge root by verifying account and storage proofs against state root from the light client.
function processBridgeRoot(bytes[] memory account_proof, bytes[] memory storage_proof) external;
Parameters
Name | Type | Description |
---|---|---|
account_proof | bytes[] | The account proofs for the bridge root. |
storage_proof | bytes[] | The storage proofs for the bridge root. |
getMerkleRoot
Returns the Merkle root from the light client.
function getMerkleRoot() external view returns (bytes32);
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | The Merkle root as a bytes32 value. |
Events
BridgeRootProcessed
Events
event BridgeRootProcessed(bytes32 indexed bridgeRoot);
TaraBridge
Inherits: BridgeBase
Functions
initialize
function initialize(
IBridgeLightClient _lightClient,
uint256 _finalizationInterval,
uint256 _feeMultiplierFinalize,
uint256 _feeMultiplierApply,
uint256 _registrationFee,
uint256 _settlementFee
) public initializer;
__initialize_EthBridge_unchained
function __initialize_EthBridge_unchained(
IBridgeLightClient _lightClient,
uint256 _finalizationInterval,
uint256 _feeMultiplierFinalize,
uint256 _feeMultiplierApply,
uint256 _registrationFee,
uint256 _settlementFee
) internal onlyInitializing;