If you are like me, you are fascinated by the idea that there is a pure mined currency running on top of (inside of?) with over 10TH/s of SHA3 Proof of Work hashpower. However, the fact that you also need ETH to pay for gas is annoying. Why not just pay for gas using 0xBTC? It is a digital currency after all.
At the moment, the miners processing Transactions do not accept ERC20 as incentive to include a new tx. That is a story for another time. So what if we just set up middleman servers that converted ERC20 to ETH and then forwarded that ETH + the tx data to the miners?
In order to do this trustlessly, we just need to be able to verify offchain signatures in Solidity. Fortunately, with and , this is very easy to do! Metamask even supports Signed Typed Data for added user friendliness.
The Lava Protocol is a new standard for signing typed data that describes an ERC20 transaction with a fee paid in . This is very similar to a ‘signed check’ in real life and is also called a ‘lava packet’. The difference is, it is cryptographically secure and anyone can turn it into the Network for a reward paid in ERC20 !
The Solidity contract that makes this possible is called the . In this case, it is a 1:1 Proxy for 0xBTC with an extra method called transferTokensWithSignature that accept the following input parameters of a Signed Lava Packet:
address relayAuthority; //address that is allowed to be msg.sender, use 0 for ANY
address from; //the packet origin and signer
address to; //the recipient of
address ; //this contract address
uint256 ; //the amount of to give to the recipient
uint256 relayerRewardTokens; //the amount of to give to msg.sender
uint256 expires; //the eth block number this packet expires at
uint256 nonce; //a random number to ensure that packet hashes are always unique
bytes signature; //a signature that can only be created with the pKey of ‘from’
Using ECRecover, the contract verifies that the token owner (from) really did produce the signature for the hash of all of this data. If so, the contract conducts the transaction! Here is how that looks in practice at :
- Atomic swap 0xBTC to LAVA Proxy Token, 1:1 (you can always swap back)
2. Generate an offchain signature for a new LAVA transaction using software that supports EIP712 like Metamask
3) Provide this Lava Packet (10 input parameters + signature) to any Lava Relay Node (https://github.com/admazzola/lava-relay-node) and it will process the transaction, paying the ETH fee and claiming the ‘Relay Reward () as payment.
As soon as a Lava Relayer gets their hands on that data, they will inspect the Fee to see if it is high enough. If so, they will submit the transaction to the Mainnet like this:
4) Once the transaction goes through, the recipient will have received the ERC20 even though you had absolutely no ETH! This was all done trustlessly and with the same elliptic-curve signature algorithms used for TX themselves, just processed in solidity. If you want, you and the recipient can convert the LAVA Proxy back to 0xBTC with an on-chain method.
Protip: By taking advantage of the ApproveAndCallWithSignature feature, you can actually convert your LAVA back to 0xBTC with no ETH by using a middleman ‘Fire Contract’, a contract like this:
Published at Sat, 16 Mar 2019 23:37:23 +0000