Important: NAP is a research prototype. It represents ongoing work conducted within the TAST research project. Use with care.
This project contains a proof of concept implementation of a true cross-blockchain token. That is, holders of the token can decide on which blockchains they want to hold their tokens with the ability to freely transfer tokens from one chain to another.
The token differs from atomic swaps in the sense that tokens are not exchanged between two different users on different blockchains, but rather the same token can be transferred to another blockchain with no other user involved.
The workflow of transferring a token from one chain to another consists of the following steps.
- Burn tokens on the source blockchain.
- Create a proof of the transaction burning the tokens.
- Claim the tokens on the destination blockchain using the proof.
- If the proof is valid, the tokens (re-)created on the destination blockchain.
- If the proof is invalid, the claim is denied.
To create proofs of transactions, we can leverage the concept of Simplified Payment Verification (SPV). SPV is explained by the Bitcoin Whitepaper as follows:
It is possible to verify payments without running a full network node. A user only needs to keep a copy of the block headers of the longest proof-of-work chain, which he can get by querying network nodes until he's convinced he has the longest chain, and obtain the Merkle branch linking the transaction to the block it's timestamped in. He can't check the transaction for himself, but by linking it to a place in the chain, he can see that a network node has accepted it, and blocks added after it further confirm the network has accepted it.
Evidently, the smart contract on the destination blockchain implementing the token needs a way to reliably validate an SPV of a burn transaction that has taken place on the source blockchain.
For this, NAP makes use of Testimonium––a blockchain relay which continuously relays block headers from the source blockchain to the destination blockchain. Testimonium makes sure that SPVs cannot be submitted for illegal block headers of the source blockchain––all while remaining fully decentralized.
So far, NAP consists of a smart contract implemented in Solidity, as such it is available for Ethereum-based blockchains.
- Clone the repository:
git clone [email protected]:pantos-io/nap-token.git
- Change into the project directory:
cd nap-token/
- Install all dependencies:
npm install
- Deploy contracts:
truffle migrate --reset
Run the tests with truffle test --network test
.
For transferring tokens between two blockchains, the contract offers the following two methods.
function transferToChain(
address recipient,
address destinationContract,
uint value
) public;
This method burns tokens of the sender and emits an event that can be used to claim the tokens on the destination blockchain.
The sender has to provide the address of the recipient (recipient
) and the address of the NAP contract (destinationContract
) on the destination blockchain,
as well as the amount the user wishes to transfer (value
).
function transferFromChain(
bytes memory rlpHeader,
bytes memory rlpTx,
bytes memory rlpReceipt,
bytes memory rlpMerkleProofTx,
bytes memory rlpMerkleProofReceipt,
bytes memory path
) public payable;
This method can be used to claim tokens on the destination blockchain. As mentioned before, the sender has to provide a valid SPV to the destination blockchain.
The SPV consists of the RLP-encoded block header of the source blockchain presumably containing the burn transaction (rlpHeader
),
the RLP-encoded burn transaction itself (rlpTx
) together with its (RLP-encoded) transaction receipt (rlpReceipt
),
as well as Merkle proofs contesting the inclusion of the burn transaction and receipt
within the provided block header (rlpMerkleProofTx
, rlpMerkleProofReceipt
, and path
).
Internally, the provided information is parsed to check whether the transaction is actually a successful burn transaction. Then the SPV proof is passed to the Testimonium relay to verify that the transaction (and receipt) are actually part of the source blockchain.
Besides the ability to transfer tokens between different blockchains, NAP further implements the popular ERC20 standard.
NAP is a research prototype. We welcome anyone to contribute. File a bug report or submit feature requests through the issue tracker. If you want to contribute feel free to submit a pull request.
The development of this prototype was funded by Pantos within the TAST research project. Further, the contract uses the RLPReader library from Hamdi Allam and the ERC20 token implementation from OpenZeppelin.
This project is licensed under the MIT License.