Skip to content

Commit cedd287

Browse files
committed
eth v1 contract
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.
1 parent ece6c3a commit cedd287

29 files changed

Lines changed: 3815 additions & 1290 deletions

client/asset/eth/contractor.go

Lines changed: 563 additions & 58 deletions
Large diffs are not rendered by default.

client/asset/eth/contractor_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package eth
22

33
import (
44
"bytes"
5+
"crypto/sha256"
56
"fmt"
67
"math/big"
78
"testing"
@@ -128,7 +129,8 @@ func TestRedeemV0(t *testing.T) {
128129
c := contractorV0{contractV0: abiContract, evmify: dexeth.GweiToWei}
129130

130131
secretB := encode.RandomBytes(32)
131-
secretHashB := encode.RandomBytes(32)
132+
secretHash := sha256.Sum256(secretB)
133+
secretHashB := secretHash[:]
132134

133135
redemption := &asset.Redemption{
134136
Secret: secretB,
@@ -160,12 +162,12 @@ func TestRedeemV0(t *testing.T) {
160162
// bad secret hash length
161163
redemption.Spends.SecretHash = encode.RandomBytes(20)
162164
checkResult("bad secret hash length", true)
163-
redemption.Spends.SecretHash = encode.RandomBytes(32)
165+
redemption.Spends.SecretHash = secretHashB
164166

165167
// bad secret length
166168
redemption.Secret = encode.RandomBytes(20)
167169
checkResult("bad secret length", true)
168-
redemption.Secret = encode.RandomBytes(32)
170+
redemption.Secret = secretB
169171

170172
// Redeem error
171173
abiContract.redeemErr = fmt.Errorf("test error")
@@ -177,9 +179,11 @@ func TestRedeemV0(t *testing.T) {
177179
checkResult("dupe error", true)
178180

179181
// two OK
182+
secretB2 := encode.RandomBytes(32)
183+
secretHash2 := sha256.Sum256(secretB2)
180184
redemption2 := &asset.Redemption{
181-
Secret: encode.RandomBytes(32),
182-
Spends: &asset.AuditInfo{SecretHash: encode.RandomBytes(32)},
185+
Secret: secretB2,
186+
Spends: &asset.AuditInfo{SecretHash: secretHash2[:]},
183187
}
184188
redemptions = []*asset.Redemption{redemption, redemption2}
185189
checkResult("two ok", false)

0 commit comments

Comments
 (0)