Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data conversion to reduce Contract impact #64

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions projects/evm-compatible-bridge/evm_contract_design.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,18 @@ This contract is "ownable" and the admin will be able to make some operations, f

##### _Token equivalency_

The contract will require some data structures to be stored on the persistent storage mainly to track the mapping of Hathor tokens to EVM tokens and the crossing operations.
The contract will require some data conversions from bytes32 to address to repesent tokens from hathor on eth.

The ERC-777 and ERC-20 tokens are identified by the contract address and the Hathor token by its 32 bytes token uid.
There should be a map going both ways to map a contract address to a token uid and a map from token uid to contract address.
There should be function for data conversion on bridge contract.

```solidity
// This maps a local token address to a hathor token uid
// This can be used to know which token in Hathor is equivalent to our native token.
mapping (address => bytes32) localTokenToHathorUid;

// This maps a Hathor token uid to a local token address.
mapping (bytes32 => address) hathorUidToLocalToken;
// this converts bytes32 to address
function bytesToAddress (bytes32 data) public pure returns (address) {
return address(uint160(uint256(data)));
}
```

The only special case is Hathor native token (HTR) which has a token uid of `00` which is not 32 bytes long.
To use the same method we will map HTR to a 32 bytes sequence of zeroes, i.e. `00000000000000000000000000000000`.

### Federation contract

A good example implementation can be found [here](https://github.com/onepercentio/tokenbridge/blob/master/bridge/contracts/Federation.sol).
Expand Down