From de1e24f24f3ddea74df7fee6e53aa5f0800ed716 Mon Sep 17 00:00:00 2001 From: tcar121293 Date: Thu, 6 Jun 2024 08:48:42 +0200 Subject: [PATCH] fix: check for taproot type when calculating amount (#294) --- chains/btc/listener/event-handlers_test.go | 4 ++-- chains/btc/listener/listener.go | 2 +- chains/btc/listener/util.go | 6 ++---- chains/btc/listener/util_test.go | 6 +++--- e2e/btc/btc_test.go | 4 ++-- e2e/evm/util.go | 12 ++++++------ example/cfg/config_evm-evm_1.json | 14 +++++++------- example/cfg/config_evm-evm_2.json | 14 +++++++------- example/cfg/config_evm-evm_3.json | 14 +++++++------- example/docker-compose.yml | 4 ++-- 10 files changed, 39 insertions(+), 41 deletions(-) diff --git a/chains/btc/listener/event-handlers_test.go b/chains/btc/listener/event-handlers_test.go index 7c4a7637..d34bc5f5 100644 --- a/chains/btc/listener/event-handlers_test.go +++ b/chains/btc/listener/event-handlers_test.go @@ -128,7 +128,7 @@ func (s *DepositHandlerTestSuite) Test_HandleDepositFails_ExecutionContinue() { }, { ScriptPubKey: btcjson.ScriptPubKeyResult{ - Type: "witness_v0_keyhash", + Type: "witness_v1_taproot", Address: "tb1qln69zuhdunc9stwfh6t7adexxrcr04ppy6thgm", }, Value: float64(0.00019), @@ -152,7 +152,7 @@ func (s *DepositHandlerTestSuite) Test_HandleDepositFails_ExecutionContinue() { }, { ScriptPubKey: btcjson.ScriptPubKeyResult{ - Type: "witness_v0_keyhash", + Type: "witness_v1_taproot", Address: "invalidBridgeAddressuhdunc9stwfh6t7adexxrcr04ppy6thgm", }, Value: float64(0.00019), diff --git a/chains/btc/listener/listener.go b/chains/btc/listener/listener.go index 68cac1d6..74439cc7 100644 --- a/chains/btc/listener/listener.go +++ b/chains/btc/listener/listener.go @@ -90,7 +90,7 @@ loop: continue } - log.Debug().Msgf("Fetching btc events for block %d", block.Height) + log.Debug().Msgf("Fetching btc events for block %d", startBlock) for _, handler := range l.eventHandlers { err := handler.HandleEvents(startBlock) diff --git a/chains/btc/listener/util.go b/chains/btc/listener/util.go index f49c30d1..e800d165 100644 --- a/chains/btc/listener/util.go +++ b/chains/btc/listener/util.go @@ -9,9 +9,7 @@ import ( ) const ( - PubKeyHash = "pubkeyhash" - ScriptHash = "scripthash" - WitnessV0KeyHash = "witness_v0_keyhash" + WitnessV1Taproot = "witness_v1_taproot" OP_RETURN = "nulldata" ) @@ -35,7 +33,7 @@ func DecodeDepositEvent(evt btcjson.TxRawResult, resource btc.Resource) (Deposit if resource.Address.String() == vout.ScriptPubKey.Address { isBridgeDeposit = true resourceID = resource.ResourceID - if vout.ScriptPubKey.Type == PubKeyHash || vout.ScriptPubKey.Type == ScriptHash || vout.ScriptPubKey.Type == WitnessV0KeyHash { + if vout.ScriptPubKey.Type == WitnessV1Taproot { amount.Add(amount, big.NewInt(int64(vout.Value*1e8))) } } diff --git a/chains/btc/listener/util_test.go b/chains/btc/listener/util_test.go index f297a81e..d974e1e8 100644 --- a/chains/btc/listener/util_test.go +++ b/chains/btc/listener/util_test.go @@ -48,7 +48,7 @@ func (s *DecodeEventsSuite) Test_DecodeDepositEvent_ErrorDecodingOPRETURNData() }, { ScriptPubKey: btcjson.ScriptPubKeyResult{ - Type: "witness_v0_keyhash", + Type: "witness_v1_taproot", Address: "tb1qln69zuhdunc9stwfh6t7adexxrcr04ppy6thgm", }, Value: float64(0.00019), @@ -79,7 +79,7 @@ func (s *DecodeEventsSuite) Test_DecodeDepositEvent() { }, { ScriptPubKey: btcjson.ScriptPubKeyResult{ - Type: "witness_v0_keyhash", + Type: "witness_v1_taproot", Address: "tb1qln69zuhdunc9stwfh6t7adexxrcr04ppy6thgm", }, Value: float64(0.00019), @@ -113,7 +113,7 @@ func (s *DecodeEventsSuite) Test_DecodeDepositEvent_NotBridgeDepositTx() { }, { ScriptPubKey: btcjson.ScriptPubKeyResult{ - Type: "witness_v0_keyhash", + Type: "witness_v1_taproot", Address: "NotBridgeAddress", }, Value: float64(0.00019), diff --git a/e2e/btc/btc_test.go b/e2e/btc/btc_test.go index 7a72fa90..c7452bb9 100644 --- a/e2e/btc/btc_test.go +++ b/e2e/btc/btc_test.go @@ -44,8 +44,8 @@ type TestClient interface { func Test_EVMBtc(t *testing.T) { evmConfig := evm.DEFAULT_CONFIG - evmConfig.Erc20LockReleaseAddr = common.HexToAddress("0x8f5b7716a0A5f94Ea10590F9070442f285a31116") - evmConfig.Erc20LockReleaseResourceID = evm.SliceTo32Bytes(common.LeftPadBytes([]byte{9}, 31)) + evmConfig.Erc20LockReleaseAddr = common.HexToAddress("0xd3Eb00fCE476aEFdC76A02F3531b7A0C6D5238B3") + evmConfig.Erc20LockReleaseResourceID = evm.SliceTo32Bytes(common.LeftPadBytes([]byte{0x10}, 31)) ethClient, err := evmClient.NewEVMClient(evm.ETHEndpoint1, evm.AdminAccount) if err != nil { diff --git a/e2e/evm/util.go b/e2e/evm/util.go index a77b2d57..4dc76225 100644 --- a/e2e/evm/util.go +++ b/e2e/evm/util.go @@ -92,19 +92,19 @@ var DEFAULT_CONFIG = BridgeConfig{ Erc20LockReleaseHandlerAddr: common.HexToAddress("0x02091EefF969b33A5CE8A729DaE325879bf76f90"), Erc20LockReleaseResourceID: SliceTo32Bytes(common.LeftPadBytes([]byte{3}, 31)), - Erc721Addr: common.HexToAddress("0xABEF96bFC837D1Bc3dA7CCAE29Ca7Fde633aFc56"), + Erc721Addr: common.HexToAddress("0xa4640d1315Be1f88aC4F81546AA2C785cf247C31"), Erc721HandlerAddr: common.HexToAddress("0xC2D334e2f27A9dB2Ed8C4561De86C1A00EBf6760"), Erc721ResourceID: SliceTo32Bytes(common.LeftPadBytes([]byte{2}, 31)), - GenericHandlerAddr: common.HexToAddress("0xb61bd8740F60e0Bfc1b5C3fA2Bb9810e4AEf8938"), + GenericHandlerAddr: common.HexToAddress("0xF956Ba663bd563f585e00D5973E06b443E5C4D65"), GenericResourceID: SliceTo32Bytes(common.LeftPadBytes([]byte{1}, 31)), - AssetStoreAddr: common.HexToAddress("0xaF831F8eCFC012e269BeD49531ebC794bDEc2fC0"), + AssetStoreAddr: common.HexToAddress("0xa2451c8553371E754F5e93A440aDcCa1c0DcF395"), - PermissionlessGenericHandlerAddr: common.HexToAddress("0x61d101704F9cC889d8a5496aE5f4ade01e687E47"), + PermissionlessGenericHandlerAddr: common.HexToAddress("0x156fA85e1df5d69B0F138dcEbAa5a14ca640FaED"), PermissionlessGenericResourceID: SliceTo32Bytes(common.LeftPadBytes([]byte{5}, 31)), - Erc1155Addr: common.HexToAddress("0x94e9070f0354b69e7fb583134a820949a390d341"), - Erc1155HandlerAddr: common.HexToAddress("0xa3523820dc62aab22920D871fa7D8600372aC2EE"), + Erc1155Addr: common.HexToAddress("0xFfd243c2C27e303e6d96aA4F7b3840Bf7209F0d7"), + Erc1155HandlerAddr: common.HexToAddress("0x9Fd58882b82EFaD2867f7eaB43539907bc07C360"), Erc1155ResourceID: SliceTo32Bytes(common.LeftPadBytes([]byte{4}, 31)), BasicFeeHandlerAddr: common.HexToAddress("0x1CcB4231f2ff299E1E049De76F0a1D2B415C563A"), diff --git a/example/cfg/config_evm-evm_1.json b/example/cfg/config_evm-evm_1.json index 6a9992b6..08bbab26 100644 --- a/example/cfg/config_evm-evm_1.json +++ b/example/cfg/config_evm-evm_1.json @@ -32,15 +32,15 @@ }, { "type": "erc1155", - "address": "0xa3523820dc62aab22920D871fa7D8600372aC2EE" + "address": "0x9Fd58882b82EFaD2867f7eaB43539907bc07C360" }, { "type": "permissionedGeneric", - "address": "0xa4640d1315Be1f88aC4F81546AA2C785cf247C31" + "address": "0xF956Ba663bd563f585e00D5973E06b443E5C4D65" }, { "type": "permissionlessGeneric", - "address": "0xa2451c8553371E754F5e93A440aDcCa1c0DcF395" + "address": "0x156fA85e1df5d69B0F138dcEbAa5a14ca640FaED" } ], "gasLimit": 9000000, @@ -65,15 +65,15 @@ }, { "type": "erc1155", - "address": "0xa3523820dc62aab22920D871fa7D8600372aC2EE" + "address": "0x9Fd58882b82EFaD2867f7eaB43539907bc07C360" }, { "type": "permissionedGeneric", - "address": "0xa4640d1315Be1f88aC4F81546AA2C785cf247C31" + "address": "0xF956Ba663bd563f585e00D5973E06b443E5C4D65" }, { "type": "permissionlessGeneric", - "address": "0xa2451c8553371E754F5e93A440aDcCa1c0DcF395" + "address": "0x156fA85e1df5d69B0F138dcEbAa5a14ca640FaED" } ], "gasLimit": 9000000, @@ -109,7 +109,7 @@ "resources": [ { "address": "bcrt1pdf5c3q35ssem2l25n435fa69qr7dzwkc6gsqehuflr3euh905l2sjyr5ek", - "resourceId": "0x0000000000000000000000000000000000000000000000000000000000000900" + "resourceId": "0x0000000000000000000000000000000000000000000000000000000000001000" } ] } diff --git a/example/cfg/config_evm-evm_2.json b/example/cfg/config_evm-evm_2.json index 0b60e9cc..c8ee322d 100644 --- a/example/cfg/config_evm-evm_2.json +++ b/example/cfg/config_evm-evm_2.json @@ -32,15 +32,15 @@ }, { "type": "erc1155", - "address": "0xa3523820dc62aab22920D871fa7D8600372aC2EE" + "address": "0x9Fd58882b82EFaD2867f7eaB43539907bc07C360" }, { "type": "permissionedGeneric", - "address": "0xa4640d1315Be1f88aC4F81546AA2C785cf247C31" + "address": "0xF956Ba663bd563f585e00D5973E06b443E5C4D65" }, { "type": "permissionlessGeneric", - "address": "0xa2451c8553371E754F5e93A440aDcCa1c0DcF395" + "address": "0x156fA85e1df5d69B0F138dcEbAa5a14ca640FaED" } ], "gasLimit": 9000000, @@ -65,15 +65,15 @@ }, { "type": "erc1155", - "address": "0xa3523820dc62aab22920D871fa7D8600372aC2EE" + "address": "0x9Fd58882b82EFaD2867f7eaB43539907bc07C360" }, { "type": "permissionedGeneric", - "address": "0xa4640d1315Be1f88aC4F81546AA2C785cf247C31" + "address": "0xF956Ba663bd563f585e00D5973E06b443E5C4D65" }, { "type": "permissionlessGeneric", - "address": "0xa2451c8553371E754F5e93A440aDcCa1c0DcF395" + "address": "0x156fA85e1df5d69B0F138dcEbAa5a14ca640FaED" } ], "gasLimit": 9000000, @@ -112,7 +112,7 @@ "resources": [ { "address": "bcrt1pdf5c3q35ssem2l25n435fa69qr7dzwkc6gsqehuflr3euh905l2sjyr5ek", - "resourceId": "0x0000000000000000000000000000000000000000000000000000000000000900" + "resourceId": "0x0000000000000000000000000000000000000000000000000000000000001000" } ] } diff --git a/example/cfg/config_evm-evm_3.json b/example/cfg/config_evm-evm_3.json index d1553e96..ad2e7e25 100644 --- a/example/cfg/config_evm-evm_3.json +++ b/example/cfg/config_evm-evm_3.json @@ -32,15 +32,15 @@ }, { "type": "erc1155", - "address": "0xa3523820dc62aab22920D871fa7D8600372aC2EE" + "address": "0x9Fd58882b82EFaD2867f7eaB43539907bc07C360" }, { "type": "permissionedGeneric", - "address": "0xa4640d1315Be1f88aC4F81546AA2C785cf247C31" + "address": "0xF956Ba663bd563f585e00D5973E06b443E5C4D65" }, { "type": "permissionlessGeneric", - "address": "0xa2451c8553371E754F5e93A440aDcCa1c0DcF395" + "address": "0x156fA85e1df5d69B0F138dcEbAa5a14ca640FaED" } ], "gasLimit": 9000000, @@ -65,15 +65,15 @@ }, { "type": "erc1155", - "address": "0xa3523820dc62aab22920D871fa7D8600372aC2EE" + "address": "0x9Fd58882b82EFaD2867f7eaB43539907bc07C360" }, { "type": "permissionedGeneric", - "address": "0xa4640d1315Be1f88aC4F81546AA2C785cf247C31" + "address": "0xF956Ba663bd563f585e00D5973E06b443E5C4D65" }, { "type": "permissionlessGeneric", - "address": "0xa2451c8553371E754F5e93A440aDcCa1c0DcF395" + "address": "0x156fA85e1df5d69B0F138dcEbAa5a14ca640FaED" } ], "gasLimit": 9000000, @@ -111,7 +111,7 @@ "resources": [ { "address": "bcrt1pdf5c3q35ssem2l25n435fa69qr7dzwkc6gsqehuflr3euh905l2sjyr5ek", - "resourceId": "0x0000000000000000000000000000000000000000000000000000000000000900" + "resourceId": "0x0000000000000000000000000000000000000000000000000000000000001000" } ] } diff --git a/example/docker-compose.yml b/example/docker-compose.yml index 862c16a2..632962cb 100644 --- a/example/docker-compose.yml +++ b/example/docker-compose.yml @@ -29,7 +29,7 @@ services: entrypoint: /cfg/entrypoint/entrypoint.sh evm1-1: - image: ghcr.io/sygmaprotocol/sygma-solidity:evm1-v2.5.3 + image: ghcr.io/sygmaprotocol/sygma-solidity:evm1-v2.7.0 container_name: evm1-1 command: ganache-cli --chainId 1337 -d --db data/ --blockTime 2 > /dev/null logging: @@ -38,7 +38,7 @@ services: - "8545:8545" evm2-1: - image: ghcr.io/sygmaprotocol/sygma-solidity:evm2-v2.5.3 + image: ghcr.io/sygmaprotocol/sygma-solidity:evm2-v2.7.0 command: ganache-cli --chainId 1338 -d --db data/ --blockTime 2 > /dev/null container_name: evm2-1 logging: