Skip to content

Commit

Permalink
eth contract v1
Browse files Browse the repository at this point in the history
Implements the version 1 contracts for ethereum and tokens. Based
on feedback in #1426, everything is now encoded in the
"contract data". This "contract data", is the msgjson.Init.Contract
-> msgjson.Audit.Contract -> MatchMetaData.Proof.CounterContract,
AuditInfo.Contract -> Redemption.Spends.Contract.

A few new terms are introduced to differentiate various encodings and
data sets. The aforementioned contract data did encode a version
and a secret hash. It now encodes a version and a "locator", which is
a []byte whose length and content depend on the version. For
version 0, the locator is still just the secretHash[:]. For v1,
the locator encodes all of the immutable data that defines the
swap. This immutable data is now collected in something called
a "vector" (dexeth.SwapVector). For version 0, some vector data
is stored on-chain indexed by the secret hash. For version 1, all
vector data is encoded in the locator.

I've also made an effort to standardize the use of status/step,
and eliminated the use of ambiguous "ver" variables throughout.
A "status" is now the collection of mutable contract data: the step,
the init block height, and the secret. The status and vector
collectively fully characterize the swap.

client/asset/eth:
New contractV1 and tokenContractorV1 interfaces. To avoid duplication,
the ERC20 parts of the tokenContractors are separated into a new type
erc20Contractor that is embedded by both versions. Getters for
status and vector are added in place of the old method "swap".

assetWallet and embedding types are updated to work with the new
version-dependent locators and the status and vector model.

dex/networks/{eth,erc20}:
New contracts added. New methods for dealing with locators. Simnet
entries added for eth and dextt.eth in the ContractAddresses and Tokens
maps. txDataHandler interace is replaced with versioned package-level
functions.

server/asset/eth:
Server is fully switched to version 1. No option to use version 0.
Translation to new version was straightforward, with one notable
difference that we can no longer get a block height from the
contract once the swap is redeemed.
  • Loading branch information
buck54321 committed Jan 10, 2023
1 parent d673de8 commit 50ac869
Show file tree
Hide file tree
Showing 31 changed files with 3,735 additions and 1,238 deletions.
633 changes: 573 additions & 60 deletions client/asset/eth/contractor.go

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions client/asset/eth/contractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package eth

import (
"bytes"
"crypto/sha256"
"fmt"
"math/big"
"testing"
Expand Down Expand Up @@ -134,7 +135,8 @@ func TestRedeemV0(t *testing.T) {
c := contractorV0{contractV0: abiContract, evmify: dexeth.GweiToWei}

secretB := encode.RandomBytes(32)
secretHashB := encode.RandomBytes(32)
secretHash := sha256.Sum256(secretB)
secretHashB := secretHash[:]

redemption := &asset.Redemption{
Secret: secretB,
Expand Down Expand Up @@ -166,12 +168,12 @@ func TestRedeemV0(t *testing.T) {
// bad secret hash length
redemption.Spends.SecretHash = encode.RandomBytes(20)
checkResult("bad secret hash length", true)
redemption.Spends.SecretHash = encode.RandomBytes(32)
redemption.Spends.SecretHash = secretHashB

// bad secret length
redemption.Secret = encode.RandomBytes(20)
checkResult("bad secret length", true)
redemption.Secret = encode.RandomBytes(32)
redemption.Secret = secretB

// Redeem error
abiContract.redeemErr = fmt.Errorf("test error")
Expand All @@ -183,9 +185,11 @@ func TestRedeemV0(t *testing.T) {
checkResult("dupe error", true)

// two OK
secretB2 := encode.RandomBytes(32)
secretHash2 := sha256.Sum256(secretB2)
redemption2 := &asset.Redemption{
Secret: encode.RandomBytes(32),
Spends: &asset.AuditInfo{SecretHash: encode.RandomBytes(32)},
Secret: secretB2,
Spends: &asset.AuditInfo{SecretHash: secretHash2[:]},
}
redemptions = []*asset.Redemption{redemption, redemption2}
checkResult("two ok", false)
Expand Down
633 changes: 430 additions & 203 deletions client/asset/eth/eth.go

Large diffs are not rendered by default.

Loading

0 comments on commit 50ac869

Please sign in to comment.