1 of 24

Dogecoin-Ethereum

Bridge

Ismael Bejarano (@CoinFabrik) - Catalina Juarros (@CoinFabrik) - Oscar Guindzberg

2 of 24

Goals

Exchange Dogecoin and an ERC-20 token back and forth in a decentralised manner.

3 of 24

Challenges

  • Keep the same circulating supply of Dogecoin.
    • Don’t burn or mint for security reasons.
  • Perform the exchange in a decentralised way.
    • Exchanges are centralised.
    • Atomic swap requires at least two people.

4 of 24

Existing solutions

  • BTCRelay.
    • Only supports one-way transaction verifications.
  • RSK Bridge.
    • Supports two-way operations.
    • Controlled by a federation.

5 of 24

More challenges

  • Dogecoin uses Scrypt as its proof-of-work function.
    • EVM-based verification costs about 100M gas.
  • Storing all the blocks is expensive.
    • 200USD per day, even if the bridge receives no transactions.
  • Dogecoin has scripts, but it offers limited support for programming.
    • Adding an opcode would require a fork.

6 of 24

Solution!

7 of 24

TrueBit

Off-chain Scrypt hash verification using a challenge-response protocol.

8 of 24

TrueBit

  • Scrypt hash is calculated off-chain.
  • Iterative challenge:
    • Divide the problem into N steps.
    • Binary search to find the first incorrect step.
    • Execute incorrect step in the contract.
  • Economic incentives to prevent attacks.
    • Each step must cover the potential response’s cost.

9 of 24

Superblocks

Store the Merkle root of a tree consisting of several blocks.

10 of 24

Superblocks

  • Blocks that aren’t relevant for the bridge don’t need to be stored.
  • Adds complexity and possible attacks.
  • The goal is to disincentivise attacks.

11 of 24

Collateral

Mechanism similar to MakerDAO’s stable coin DAI for converting DogeTokens to Dogecoin.

12 of 24

Collateral

  • Dogecoin:
    • Doesn’t support complex scripts.
    • New opcode needs a hard fork.
  • Collateral:
    • Dogecoin is backed by operators.
    • Operators must deposit ether in order to cover the total amount of Dogecoin in the bridge.
    • Affected by Ether to Dogecoin price fluctuations.

13 of 24

Tools

  • Truffle
  • Ganache
  • Travis CI
  • Web3j

14 of 24

Truffle

  • Smart contract compilation and deployment.
  • Integration tests for Solidity smart contracts and Java agent.
  • Unit tests during development.
    • We currently have over 100 unit tests.

15 of 24

Ganache

  • Development Ethereum node.
  • Automatic mining.
  • Infinite balance.

16 of 24

Travis CI

Web3j

  • Test case execution in a clean environment.
  • Execute tests on a branch before merging.
  • Java version of web3.
  • Used by ‘agents’ for interacting with the Ethereum blockchain.

17 of 24

Some issues

18 of 24

Some issues

  • Truffle
    • Sometimes it doesn’t recompile contracts:
      • Automate compilation and deployment with bash scripts.
      • Remove build directory.
      • Force recompilation: truffle compile --all.
    • Latest compiler version:
      • Edit dependencies manually.

19 of 24

Some issues

  • Ganache
    • Slow for complex contracts.
    • Easy to create transaction collisions.
      • Transactions aren’t signed.
    • A bugged version made Travis CI fail.
      • Hardcode a working version.

20 of 24

Some issues

  • No stack trace for debugging.
    • Use error codes instead of revert.
    • Use log0(), log1(), etc. to inspect variable state
    • New revert with reason opcode is not yet supported
      • There is still no defined protocol for interpreting reason

21 of 24

Some issues

  • Possible ‘out of gas’ causes:
    • 32KB per transaction limit.
      • Makes it impossible to deploy very large contracts.
    • Almost any error causes ‘out of gas’ on Ganache.
      • Turn on verbose mode.
      • Test on geth development mode (PoA).

22 of 24

Some issues

  • ‘Out of gas’ solutions
    • Separate contracts according to their functionality.
      • Adds complexity and dependencies between contracts.
    • Use libraries.
      • extern functions use delegatecall.
      • internal functions are compiled inline.
      • No access to storage.
    • Use Solidity assembly.
      • Hard to debug.
    • Turn on compiler optimisation.

23 of 24

That’s all!

24 of 24

References