Skip to content

Commit efeceb0

Browse files
authored
fix: match signature with on-chain one (#26)
* feat: use nonce from api request * Update codeowners * Improve logs * Fix missing bracket * Lint * fix: match signature with on-chain one * Rename variable
1 parent ad5538a commit efeceb0

File tree

5 files changed

+43
-18
lines changed

5 files changed

+43
-18
lines changed

app/app.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,25 @@ func Run() error {
138138
supportedChains := make(map[uint64]struct{})
139139
confirmationsPerChain := make(map[uint64]map[uint64]uint64)
140140
domains := make(map[uint64]relayer.RelayedChain)
141+
142+
acrossPools := make(map[uint64]common.Address)
143+
for _, chainConfig := range configuration.ChainConfigs {
144+
switch chainConfig["type"] {
145+
case "evm":
146+
{
147+
config, err := evm.NewEVMConfig(chainConfig)
148+
panicOnError(err)
149+
150+
if config.AcrossPool != "" {
151+
poolAddress := common.HexToAddress(config.AcrossPool)
152+
acrossPools[*config.GeneralChainConfig.Id] = poolAddress
153+
}
154+
}
155+
default:
156+
panic(fmt.Errorf("type '%s' not recognized", chainConfig["type"]))
157+
}
158+
}
159+
141160
for _, chainConfig := range configuration.ChainConfigs {
142161
switch chainConfig["type"] {
143162
case "evm":
@@ -154,11 +173,10 @@ func Run() error {
154173

155174
mh := message.NewMessageHandler()
156175
if config.AcrossPool != "" {
157-
poolAddress := common.HexToAddress(config.AcrossPool)
158176
acrossMh := evmMessage.NewAcrossMessageHandler(
159177
*config.GeneralChainConfig.Id,
160178
client,
161-
poolAddress,
179+
acrossPools,
162180
coordinator,
163181
host,
164182
communication,

chains/evm/calls/events/events.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,6 @@ func (a *AcrossV3RelayData) Calldata(repaymentChainID *big.Int, repaymentAddress
8383
if err != nil {
8484
return []byte{}, err
8585
}
86+
8687
return input, nil
8788
}

chains/evm/message/across.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package message
33
import (
44
"context"
55
"fmt"
6+
"maps"
67
"math/big"
8+
"slices"
79
"time"
810

911
"github.com/ethereum/go-ethereum"
1012
"github.com/ethereum/go-ethereum/common"
11-
"github.com/ethereum/go-ethereum/common/hexutil"
1213
"github.com/ethereum/go-ethereum/common/math"
1314
"github.com/ethereum/go-ethereum/core/types"
1415
"github.com/ethereum/go-ethereum/crypto"
@@ -79,7 +80,7 @@ type AcrossMessageHandler struct {
7980
confirmations map[uint64]uint64
8081
blocktime time.Duration
8182
tokenPricer TokenPricer
82-
pool common.Address
83+
pools map[uint64]common.Address
8384

8485
coordinator Coordinator
8586
host host.Host
@@ -92,7 +93,7 @@ type AcrossMessageHandler struct {
9293
func NewAcrossMessageHandler(
9394
chainID uint64,
9495
client EventFilterer,
95-
pool common.Address,
96+
pools map[uint64]common.Address,
9697
coordinator Coordinator,
9798
host host.Host,
9899
comm comm.Communication,
@@ -106,7 +107,7 @@ func NewAcrossMessageHandler(
106107
return &AcrossMessageHandler{
107108
chainID: chainID,
108109
client: client,
109-
pool: pool,
110+
pools: pools,
110111
coordinator: coordinator,
111112
host: host,
112113
comm: comm,
@@ -241,18 +242,21 @@ func (h *AcrossMessageHandler) minimalConfirmations(d *events.AcrossDeposit) (ui
241242
return 0, err
242243
}
243244

244-
orderValue, _ := new(big.Float).Quo(
245+
orderValueInt := new(big.Int)
246+
orderValueInt, _ = new(big.Float).Quo(
245247
new(big.Float).Mul(big.NewFloat(price), new(big.Float).SetInt(d.InputAmount)),
246248
new(big.Float).SetInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(c.Decimals)), nil)),
247-
).Float64()
249+
).Int(orderValueInt)
248250

249-
for bucket, confirmation := range h.confirmations {
250-
if uint64(orderValue) < bucket {
251-
return confirmation, nil
251+
buckets := slices.Collect(maps.Keys(h.confirmations))
252+
slices.Sort(buckets)
253+
for _, bucket := range buckets {
254+
if orderValueInt.Cmp(new(big.Int).SetUint64(bucket)) < 0 {
255+
return h.confirmations[bucket], nil
252256
}
253257
}
254258

255-
return 0, fmt.Errorf("order value %f exceeds confirmation buckets", orderValue)
259+
return 0, fmt.Errorf("order value %f exceeds confirmation buckets", orderValueInt)
256260
}
257261

258262
func (h *AcrossMessageHandler) waitForConfirmations(
@@ -319,7 +323,7 @@ func (h *AcrossMessageHandler) deposit(depositId *big.Int) (common.Hash, *events
319323
ToBlock: latestBlock,
320324
FromBlock: new(big.Int).Sub(latestBlock, big.NewInt(BLOCK_RANGE)),
321325
Addresses: []common.Address{
322-
h.pool,
326+
h.pools[h.chainID],
323327
},
324328
Topics: [][]common.Hash{
325329
{
@@ -374,7 +378,7 @@ func (h *AcrossMessageHandler) unlockHash(
374378
) ([]byte, error) {
375379
calldata, err := deposit.ToV3RelayData(
376380
new(big.Int).SetUint64(sourceChainId),
377-
).Calldata(deposit.DestinationChainId, data.LiquidityPool)
381+
).Calldata(deposit.DestinationChainId, data.Caller)
378382
if err != nil {
379383
return []byte{}, err
380384
}
@@ -383,8 +387,8 @@ func (h *AcrossMessageHandler) unlockHash(
383387
"caller": data.Caller.Hex(),
384388
"borrowToken": common.BytesToAddress(deposit.OutputToken[12:]).Hex(),
385389
"amount": deposit.OutputAmount,
386-
"target": common.BytesToAddress(deposit.Recipient[12:]).Hex(),
387-
"targetCallData": hexutil.Encode(calldata),
390+
"target": h.pools[deposit.DestinationChainId.Uint64()].Hex(),
391+
"targetCallData": calldata,
388392
"nonce": data.Nonce,
389393
"deadline": new(big.Int).SetUint64(uint64(deposit.FillDeadline)),
390394
}

chains/evm/message/across_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ func (s *AcrossMessageHandlerTestSuite) SetupTest() {
6161

6262
s.mockPricer = mock_message.NewMockTokenPricer(ctrl)
6363

64-
pool := common.HexToAddress("0x5c7BCd6E7De5423a257D81B442095A1a6ced35C5")
64+
pools := make(map[uint64]common.Address)
65+
pools[2] = common.HexToAddress("0x5c7BCd6E7De5423a257D81B442095A1a6ced35C5")
6566

6667
s.sigChn = make(chan interface{}, 1)
6768

@@ -79,7 +80,7 @@ func (s *AcrossMessageHandlerTestSuite) SetupTest() {
7980
s.handler = message.NewAcrossMessageHandler(
8081
1,
8182
s.mockEventFilterer,
82-
pool,
83+
pools,
8384
s.mockCoordinator,
8485
s.mockHost,
8586
s.mockCommunication,

tss/ecdsa/signing/signing.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ func (s *Signing) processEndMessage(ctx context.Context, endChn chan tssCommon.S
207207
es = append(es[:], ethCommon.LeftPadBytes(sig.R, 32)...)
208208
es = append(es[:], ethCommon.LeftPadBytes(sig.S, 32)...)
209209
es = append(es[:], sig.SignatureRecovery...)
210+
es[len(es)-1] += 27 // Transform V from 0/1 to 27/28
210211

211212
s.resultChn <- EcdsaSignature{
212213
Signature: es,

0 commit comments

Comments
 (0)