From a9d979d4d508df20d70e3c9ac878dc0ab12d960d Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Wed, 22 Jan 2025 17:07:45 +0100 Subject: [PATCH 1/4] feat(adjudicator): Add checks for the cross-contract case in which only one participant withdraws on stellar fix(funder, setup): Fix name of needFunding and remove unused code Signed-off-by: Sophia Koehler --- channel/adjudicator.go | 28 +++++++++++++++++++++++++-- channel/funder.go | 8 ++++---- channel/test/setup.go | 4 ---- testdata/perun_soroban_contract.wasm | Bin 53817 -> 54145 bytes 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/channel/adjudicator.go b/channel/adjudicator.go index b84c311..f9b961f 100644 --- a/channel/adjudicator.go +++ b/channel/adjudicator.go @@ -19,9 +19,11 @@ import ( "errors" "fmt" "github.com/stellar/go/xdr" + "math/big" pchannel "perun.network/go-perun/channel" "perun.network/go-perun/log" pwallet "perun.network/go-perun/wallet" + "perun.network/perun-stellar-backend/channel/types" "perun.network/perun-stellar-backend/client" "perun.network/perun-stellar-backend/wallet" "time" @@ -89,6 +91,11 @@ func (a *Adjudicator) Withdraw(ctx context.Context, req pchannel.AdjudicatorReq, } if req.Tx.State.IsFinal { log.Println("Channel is final, closing now") + withdrawSelf := needWithdraw([]pchannel.Bal{req.Tx.State.Balances[0][req.Idx], req.Tx.State.Balances[1][req.Idx]}, req.Tx.State.Assets) + if req.Idx == 0 && (a.oneWithdrawer || !withdrawSelf) { + log.Println("A only closes when A also has to withdraw") + return nil + } err := a.Close(ctx, req.Tx.State, req.Tx.Sigs) if err != nil { chanControl, errChanState = a.CB.GetChannelInfo(ctx, a.perunAddr, req.Tx.State.ID) @@ -119,12 +126,19 @@ func (a *Adjudicator) Withdraw(ctx context.Context, req pchannel.AdjudicatorReq, } func (a *Adjudicator) handleWithdrawal(ctx context.Context, req pchannel.AdjudicatorReq) error { - if a.oneWithdrawer { + withdrawOther := needWithdraw([]pchannel.Bal{req.Tx.State.Balances[0][1-req.Idx], req.Tx.State.Balances[1][1-req.Idx]}, req.Tx.State.Assets) + if a.oneWithdrawer && withdrawOther { + log.Println("Withdrawing other", req.Idx) if err := a.withdrawOther(ctx, req); err != nil { return err } } - return a.withdraw(ctx, req) + withdrawSelf := needWithdraw([]pchannel.Bal{req.Tx.State.Balances[0][req.Idx], req.Tx.State.Balances[1][req.Idx]}, req.Tx.State.Assets) + if withdrawSelf { + log.Println("Withdrawing self", req.Idx) + return a.withdraw(ctx, req) + } + return nil } func (a *Adjudicator) withdraw(ctx context.Context, req pchannel.AdjudicatorReq) error { @@ -173,3 +187,13 @@ func (a Adjudicator) Progress(ctx context.Context, req pchannel.ProgressReq) err // only relevant for AppChannels return nil } + +func needWithdraw(balances []pchannel.Bal, assets []pchannel.Asset) bool { + for i, bal := range balances { + _, ok := assets[i].(*types.StellarAsset) + if bal.Cmp(big.NewInt(0)) != 0 && ok { // if balance is 0 or asset is not stellar asset, participant does not need to withdraw + return true + } + } + return false +} diff --git a/channel/funder.go b/channel/funder.go index 508ea73..bb72195 100644 --- a/channel/funder.go +++ b/channel/funder.go @@ -106,7 +106,7 @@ func (f *Funder) fundParty(ctx context.Context, req pchannel.FundingReq) error { } if req.Idx == pchannel.Index(0) && !chanState.Control.FundedA { - shouldFund := need_funding(req.State.Balances[0], req.State.Assets) + shouldFund := needFunding(req.State.Balances[0], req.State.Assets) if !shouldFund { log.Println("Party A does not need to fund") return nil @@ -148,9 +148,9 @@ func (f *Funder) fundParty(ctx context.Context, req pchannel.FundingReq) error { log.Println("Balance A: ", bal0, bal1, " after funding amount: ", req.State.Balances, req.State.Assets) continue } - if req.Idx == pchannel.Index(1) && !chanState.Control.FundedB && (chanState.Control.FundedA || !need_funding(req.State.Balances[0], req.State.Assets)) { // If party A has funded or does not need to fund, party B funds + if req.Idx == pchannel.Index(1) && !chanState.Control.FundedB && (chanState.Control.FundedA || !needFunding(req.State.Balances[0], req.State.Assets)) { // If party A has funded or does not need to fund, party B funds log.Println("Funding party B") - shouldFund := need_funding(req.State.Balances[1], req.State.Assets) + shouldFund := needFunding(req.State.Balances[1], req.State.Assets) if !shouldFund { log.Println("Party B does not need to fund", req.State.Balances[1], req.State.Assets) return nil @@ -269,7 +269,7 @@ func assetSliceToSet(assets []xdr.ScVal) map[string]struct{} { return assetSet } -func need_funding(balances []pchannel.Bal, assets []pchannel.Asset) bool { +func needFunding(balances []pchannel.Bal, assets []pchannel.Asset) bool { for i, bal := range balances { _, ok := assets[i].(*types.StellarAsset) if bal.Cmp(big.NewInt(0)) != 0 && ok { // if balance is 0 or asset is not stellar asset, participant does not need to fund diff --git a/channel/test/setup.go b/channel/test/setup.go index 34fff6b..757c018 100644 --- a/channel/test/setup.go +++ b/channel/test/setup.go @@ -114,8 +114,6 @@ func NewTestSetup(t *testing.T, options ...bool) *Setup { } _, kpsToFund, _ := MakeRandPerunAccsWallets(5) - // kpsToFund[2], _ = keypair.ParseFull("SD4XPDWFDY25V7NRMF47QE4WT6WOFWUJIZGFRMMCRHGVINJ3RMMDG6WS") - // kpsToFund[3], _ = keypair.ParseFull("SDHDGJMVERIXSN5LQ5KDLW3F2QIVM2D6CLP3BDHSKWBAYX53YDEY3FND") require.NoError(t, CreateFundStellarAccounts(kpsToFund, initLumensBalance)) depTokenOneKp := kpsToFund[2] @@ -142,8 +140,6 @@ func NewTestSetup(t *testing.T, options ...bool) *Setup { require.NoError(t, InitTokenContract(depTokenOneKp, tokenAddressOne, HorizonURL)) require.NoError(t, InitTokenContract(depTokenTwoKp, tokenAddressTwo, HorizonURL)) - // acc0 := wallet.NewAccount("5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a", *kpsToFund[0].FromAddress(), [20]byte([]byte{86, 253, 40, 156, 238, 113, 74, 94, 71, 28, 65, 132, 54, 239, 166, 62, 120, 13, 122, 135})) - // acc1 := wallet.NewAccount("7c852118294e51e653712a81e05800f419141751be58f605c371e15141b007a6", *kpsToFund[0].FromAddress(), [20]byte([]byte{101, 54, 66, 91, 233, 90, 102, 97, 246, 198, 246, 141, 112, 155, 107, 225, 82, 120, 93, 246})) acc0, err := wallet.NewRandomAccountWithAddress(mathrand.New(mathrand.NewSource(0)), kpsToFund[0].FromAddress()) acc1, err := wallet.NewRandomAccountWithAddress(mathrand.New(mathrand.NewSource(0)), kpsToFund[1].FromAddress()) w0 := wallet.NewEphemeralWallet() diff --git a/testdata/perun_soroban_contract.wasm b/testdata/perun_soroban_contract.wasm index 81eca3f39d8f073e137e10aff97ac5fb7a1d47cf..ab945fbc9a61c98d706485514cda6f206763ae5e 100755 GIT binary patch delta 4663 zcmcgvdsJ0b8sFbJT)1$#a4uYV3;Te)MKqJEsObTpD^teQ)l)?v^@d;wYD!#?r&=n0 zpjbXr6U!Xz=x8|^rX{ACrWG!o87gNMGvhS&m~yRbm~Y?9r7JUk&tiS&cYk|-``h1Z zpR;*;pImi7Zd(BIX?PC{ARhwpJTyOD1zyjT73H&PFys{$FDqcRV0xywB(Gqei`Icp z{^Dgz%SsDaJs4LkE?tyglDmSf1#|9#;*!#NV)5dlg=`&|78aDw%UhINR8&yN)&tCA z7x1Js=#k@a1RkCDF8m%g!45bB@5405Hh38h!JBXxehY2zB5Z`s&;-qJ09xT7ybiCz zUf2iw;Wg0VC|rb(;Vk$adq;XtA1seESl+3stYpj-$T;J`CFPV}Zp<|Vo^}n>pu|DB zuHQDlDnX~dQ3(OKuD@pKkl>hJY^^rHCj36U0*+xx#CK_jUTLpns<%Iwr19KfX4=_p z&H=6Mpg>7uDv)@Qg4ThJkt!TTJ+dTfm)MO39`hG!DV9l9s?lJtvtKU(}0J?g($^4;e^Fs~GY=KqqQL<3p|s zgArWTdYGM_iFU1>Dc7-l=%=JGW7u4J9v+rJD?b}n;os?0md1-e>>6&hv>Rrc$ph`0 zWY?HBSn0$Y!^8C*4~!-A`i)!qmoXjo>5pefR4shUHiDj;ZD~Qh+Y1{b z?OM0k`ikumr!PEt{&A$n&wQMQgS+T2BpU`dL~Wi1*6vhe2(2?C?514tCQ9{ zW3Rz=ed9wp5|OU)X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Q^|gmGMwG}f9Qq7dEbf=GBo%=hF4JU$93f@kCcuMw8D~FxR@lHHIDs1vLsTAH zd$i#FBwTwO4u>zKLG$SinV1XrO&dLtLBabA*?wI~@v1CqaC5^`Z{&v?Pb&#>J@iJ9 z%`j{;-e5~sn32IQd9_+-6lx1@B!ec$w=~Ooi2}>ME<X&2|U&Y};wwsiu%#%J0K`ATc3cId5Ap zjk)v&Pu{o`1<$^X8E8*$d<^ZVO{37x-Si?IkAr5 zv)|ep7ea6Gd43pmSY$^IET?fr`v??4o7&S*KJ9PMz;DQzb_?H;9p#B{_ygz07W+e| z8i(-~w{&>vB!AXXKtJWw&Rk4%q|43oIw#Q2cuQvnUF5@^58^wdD-RQm>zZZ!Oc_E= zj_X;I4&x-ZcI86tNY~8xV3)sKPpZJd`YF4*bCKZ6=&WvK^r`N%bd6_iUy7Rf_3iUw zPb+h%Qob#cN9;(5e`i2CC@HV;%pFS{~JRxVjMrnXLqaZW=-2q8YugvbF7=I}Qm<&E;5Iq?{{=0oOo2oVnq@&!Zq_26R$^=|+_Uh(WYlo=Zw^+!lmnqJ{)hpG$uqu>a* zGsvxBz#xAayxONA|0y;=#lD|^d#E~gYqTNefvW~7t*yM^a4Frz?;oC;UKV5EmzgCYMx|m9LVgAXfuAdFGM)@P2TK z;Qqy{kIalsi#7a*qyU%?sfT}g??r`tGdxQqqerX zHaAmLLax$m=-8lq=(tjEWo3Dpd~8m6-SW!%!ouZMD>>ahkbWI@ys(oBQs*Yfk5n@L zi=7i2l-v%9TG4eo^Ju&y>q{)<8<0?rfTBTePzp$bvO)R$y<_=V_0aNxHi0@pFMtk% Rj)P8vE`dI^UpaOu<=^d4%qjo? From 9e4eb44b9889b15c25831a3bb02262a4c03118f1 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Tue, 28 Jan 2025 11:04:07 +0100 Subject: [PATCH 2/4] chore: Update licenses Signed-off-by: Sophia Koehler --- channel/adjudicator.go | 2 +- channel/funder.go | 2 +- channel/test/setup.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/channel/adjudicator.go b/channel/adjudicator.go index f9b961f..8c39375 100644 --- a/channel/adjudicator.go +++ b/channel/adjudicator.go @@ -1,4 +1,4 @@ -// Copyright 2024 PolyCrypt GmbH +// Copyright 2025 PolyCrypt GmbH // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/funder.go b/channel/funder.go index bb72195..54b9991 100644 --- a/channel/funder.go +++ b/channel/funder.go @@ -1,4 +1,4 @@ -// Copyright 2023 PolyCrypt GmbH +// Copyright 2025 PolyCrypt GmbH // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/channel/test/setup.go b/channel/test/setup.go index 757c018..8487576 100644 --- a/channel/test/setup.go +++ b/channel/test/setup.go @@ -1,4 +1,4 @@ -// Copyright 2024 PolyCrypt GmbH +// Copyright 2025 PolyCrypt GmbH // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. From 8e0d4dbfa2c45f4da543804edc406337ec99f923 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Tue, 28 Jan 2025 11:21:25 +0100 Subject: [PATCH 3/4] chore: Update go-perun dependency Signed-off-by: Sophia Koehler --- channel/ethbackend.go | 2 +- channel/types/asset.go | 4 ++-- channel/types/ethasset.go | 24 ++++++++++++------------ go.mod | 2 +- go.sum | 4 ++-- wire/balances.go | 2 +- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/channel/ethbackend.go b/channel/ethbackend.go index a7e2ebd..35e7893 100644 --- a/channel/ethbackend.go +++ b/channel/ethbackend.go @@ -99,7 +99,7 @@ func assetToEthAsset(asset channel.Asset) ChannelAsset { log.Panicf("expected asset of type MultiLedgerAsset, but got wrong asset type: %T", asset) } id := new(big.Int) - _, ok = id.SetString(string(multiAsset.AssetID().LedgerID().MapKey()), 10) // base 10 for decimal numbers + _, ok = id.SetString(string(multiAsset.LedgerBackendID().LedgerID().MapKey()), 10) // base 10 for decimal numbers if !ok { log.Panicf("Error: Failed to parse string into big.Int") } diff --git a/channel/types/asset.go b/channel/types/asset.go index cf89627..92a9e2d 100644 --- a/channel/types/asset.go +++ b/channel/types/asset.go @@ -153,8 +153,8 @@ func (a Asset) Address() []byte { } -// AssetID returns the asset ID of the Stellar asset. -func (s StellarAsset) AssetID() multi.AssetID { +// LedgerBackendID returns the asset ID of the Stellar asset. +func (s StellarAsset) LedgerBackendID() multi.LedgerBackendID { return s.id } diff --git a/channel/types/ethasset.go b/channel/types/ethasset.go index 53dc2dd..361ae79 100644 --- a/channel/types/ethasset.go +++ b/channel/types/ethasset.go @@ -123,11 +123,11 @@ func (id ChainID) MapKey() multi.LedgerIDMapKey { type ( // Asset is an Ethereum asset. EthAsset struct { - assetID AssetID + assetID LedgerBackendID AssetHolder wallet.Address } - - AssetID struct { + // LedherBackendID holds the ChainID and BackendID of an Asset. + LedgerBackendID struct { backendID uint32 ledgerID ChainID } @@ -137,23 +137,23 @@ type ( ) func MakeEthAsset(id *big.Int, holder wallet.Address) EthAsset { - return EthAsset{assetID: AssetID{backendID: 1, ledgerID: MakeChainID(id)}, AssetHolder: holder} + return EthAsset{assetID: LedgerBackendID{backendID: 1, ledgerID: MakeChainID(id)}, AssetHolder: holder} } -func (id AssetID) BackendID() uint32 { +func (id LedgerBackendID) BackendID() uint32 { return id.backendID } -func (id AssetID) LedgerID() multi.LedgerID { +func (id LedgerBackendID) LedgerID() multi.LedgerID { return &id.ledgerID } -// MakeAssetID makes a AssetID for the given id. -func MakeAssetID(id *big.Int) multi.AssetID { +// MakeAssetID makes a LedgerBackendID for the given id. +func MakeLedgerBackendID(id *big.Int) multi.LedgerBackendID { if id.Sign() < 0 { panic("must not be smaller than zero") } - return AssetID{backendID: 1, ledgerID: MakeChainID(id)} + return LedgerBackendID{backendID: 1, ledgerID: MakeChainID(id)} } // MapKey returns the asset's map key representation. @@ -184,11 +184,11 @@ func (a *EthAsset) UnmarshalBinary(data []byte) error { // LedgerID returns the ledger ID the asset lives on. func (a EthAsset) LedgerID() multi.LedgerID { - return a.AssetID().LedgerID() + return a.LedgerBackendID().LedgerID() } -// AssetID returns the ledger ID the asset lives on. -func (a EthAsset) AssetID() multi.AssetID { +// LedgerBackendID returns the ledger ID the asset lives on. +func (a EthAsset) LedgerBackendID() multi.LedgerBackendID { return a.assetID } diff --git a/go.mod b/go.mod index f721c8c..8f14c5a 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/ethereum/go-ethereum v1.10.12 github.com/stellar/go-xdr v0.0.0-20231122183749-b53fb00bcac2 github.com/stretchr/testify v1.9.0 - perun.network/go-perun v0.12.1-0.20250114072911-f46b0c55fe65 + perun.network/go-perun v0.12.1-0.20250128081648-21d0af4e234b polycry.pt/poly-go v0.0.0-20220301085937-fb9d71b45a37 ) diff --git a/go.sum b/go.sum index 02a02d3..2bae5e1 100644 --- a/go.sum +++ b/go.sum @@ -658,8 +658,8 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las= -perun.network/go-perun v0.12.1-0.20250114072911-f46b0c55fe65 h1:kJ3AS374fe23a/9puoaOwCr9Bx2L/WJ5p2npDql3m4A= -perun.network/go-perun v0.12.1-0.20250114072911-f46b0c55fe65/go.mod h1:uH8iwi75alXDizxxDzH0A+6uqXPbagCpKfl8ECMv/cA= +perun.network/go-perun v0.12.1-0.20250128081648-21d0af4e234b h1:6FeodthJZB10aWGk/DgtV2VicacyUnLaUoT8OUcwSms= +perun.network/go-perun v0.12.1-0.20250128081648-21d0af4e234b/go.mod h1:uH8iwi75alXDizxxDzH0A+6uqXPbagCpKfl8ECMv/cA= polycry.pt/poly-go v0.0.0-20220301085937-fb9d71b45a37 h1:iA5GzEa/hHfVlQpimEjPV09NATwHXxSjWNB0VVodtew= polycry.pt/poly-go v0.0.0-20220301085937-fb9d71b45a37/go.mod h1:XUBrNtqgEhN3EEOP/5gh7IBd3xVHKidCjXDZfl9+kMU= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= diff --git a/wire/balances.go b/wire/balances.go index e1f3e21..abef491 100644 --- a/wire/balances.go +++ b/wire/balances.go @@ -256,7 +256,7 @@ func extractAndConvertLedgerID(asset channel.Asset) (uint64, error) { if !ok { return 0, errors.New("invalid Asset format") } - id := multiAsset.AssetID().LedgerID() + id := multiAsset.LedgerBackendID().LedgerID() if id == nil { return 0, errors.New("invalid LedgerID") } From bd5a98ac626180f8a6d7f9433b5fa372bb995f54 Mon Sep 17 00:00:00 2001 From: Sophia Koehler Date: Wed, 29 Jan 2025 15:03:29 +0100 Subject: [PATCH 4/4] fix: fixes B not withdrawing in only-stellar-swaps Signed-off-by: Sophia Koehler --- channel/adjudicator.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/channel/adjudicator.go b/channel/adjudicator.go index 8c39375..7b25a27 100644 --- a/channel/adjudicator.go +++ b/channel/adjudicator.go @@ -92,8 +92,9 @@ func (a *Adjudicator) Withdraw(ctx context.Context, req pchannel.AdjudicatorReq, if req.Tx.State.IsFinal { log.Println("Channel is final, closing now") withdrawSelf := needWithdraw([]pchannel.Bal{req.Tx.State.Balances[0][req.Idx], req.Tx.State.Balances[1][req.Idx]}, req.Tx.State.Assets) - if req.Idx == 0 && (a.oneWithdrawer || !withdrawSelf) { - log.Println("A only closes when A also has to withdraw") + withdrawOther := needWithdraw([]pchannel.Bal{req.Tx.State.Balances[0][1-req.Idx], req.Tx.State.Balances[1][1-req.Idx]}, req.Tx.State.Assets) + if req.Idx == 0 && a.oneWithdrawer && (!withdrawSelf || !withdrawOther) { // If one participant does not need to withdraw, the swap is cross-chain which means A does not need to close + log.Println("A only closes when A & B have to withdraw") return nil } err := a.Close(ctx, req.Tx.State, req.Tx.Sigs)