Skip to content

Commit

Permalink
fix: check for taproot type when calculating amount (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcar121293 authored Jun 6, 2024
1 parent 0d421d1 commit de1e24f
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 41 deletions.
4 changes: 2 additions & 2 deletions chains/btc/listener/event-handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion chains/btc/listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions chains/btc/listener/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import (
)

const (
PubKeyHash = "pubkeyhash"
ScriptHash = "scripthash"
WitnessV0KeyHash = "witness_v0_keyhash"
WitnessV1Taproot = "witness_v1_taproot"
OP_RETURN = "nulldata"
)

Expand All @@ -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)))
}
}
Expand Down
6 changes: 3 additions & 3 deletions chains/btc/listener/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions e2e/btc/btc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions e2e/evm/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
14 changes: 7 additions & 7 deletions example/cfg/config_evm-evm_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
},
{
"type": "erc1155",
"address": "0xa3523820dc62aab22920D871fa7D8600372aC2EE"
"address": "0x9Fd58882b82EFaD2867f7eaB43539907bc07C360"
},
{
"type": "permissionedGeneric",
"address": "0xa4640d1315Be1f88aC4F81546AA2C785cf247C31"
"address": "0xF956Ba663bd563f585e00D5973E06b443E5C4D65"
},
{
"type": "permissionlessGeneric",
"address": "0xa2451c8553371E754F5e93A440aDcCa1c0DcF395"
"address": "0x156fA85e1df5d69B0F138dcEbAa5a14ca640FaED"
}
],
"gasLimit": 9000000,
Expand All @@ -65,15 +65,15 @@
},
{
"type": "erc1155",
"address": "0xa3523820dc62aab22920D871fa7D8600372aC2EE"
"address": "0x9Fd58882b82EFaD2867f7eaB43539907bc07C360"
},
{
"type": "permissionedGeneric",
"address": "0xa4640d1315Be1f88aC4F81546AA2C785cf247C31"
"address": "0xF956Ba663bd563f585e00D5973E06b443E5C4D65"
},
{
"type": "permissionlessGeneric",
"address": "0xa2451c8553371E754F5e93A440aDcCa1c0DcF395"
"address": "0x156fA85e1df5d69B0F138dcEbAa5a14ca640FaED"
}
],
"gasLimit": 9000000,
Expand Down Expand Up @@ -109,7 +109,7 @@
"resources": [
{
"address": "bcrt1pdf5c3q35ssem2l25n435fa69qr7dzwkc6gsqehuflr3euh905l2sjyr5ek",
"resourceId": "0x0000000000000000000000000000000000000000000000000000000000000900"
"resourceId": "0x0000000000000000000000000000000000000000000000000000000000001000"
}
]
}
Expand Down
14 changes: 7 additions & 7 deletions example/cfg/config_evm-evm_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
},
{
"type": "erc1155",
"address": "0xa3523820dc62aab22920D871fa7D8600372aC2EE"
"address": "0x9Fd58882b82EFaD2867f7eaB43539907bc07C360"
},
{
"type": "permissionedGeneric",
"address": "0xa4640d1315Be1f88aC4F81546AA2C785cf247C31"
"address": "0xF956Ba663bd563f585e00D5973E06b443E5C4D65"
},
{
"type": "permissionlessGeneric",
"address": "0xa2451c8553371E754F5e93A440aDcCa1c0DcF395"
"address": "0x156fA85e1df5d69B0F138dcEbAa5a14ca640FaED"
}
],
"gasLimit": 9000000,
Expand All @@ -65,15 +65,15 @@
},
{
"type": "erc1155",
"address": "0xa3523820dc62aab22920D871fa7D8600372aC2EE"
"address": "0x9Fd58882b82EFaD2867f7eaB43539907bc07C360"
},
{
"type": "permissionedGeneric",
"address": "0xa4640d1315Be1f88aC4F81546AA2C785cf247C31"
"address": "0xF956Ba663bd563f585e00D5973E06b443E5C4D65"
},
{
"type": "permissionlessGeneric",
"address": "0xa2451c8553371E754F5e93A440aDcCa1c0DcF395"
"address": "0x156fA85e1df5d69B0F138dcEbAa5a14ca640FaED"
}
],
"gasLimit": 9000000,
Expand Down Expand Up @@ -112,7 +112,7 @@
"resources": [
{
"address": "bcrt1pdf5c3q35ssem2l25n435fa69qr7dzwkc6gsqehuflr3euh905l2sjyr5ek",
"resourceId": "0x0000000000000000000000000000000000000000000000000000000000000900"
"resourceId": "0x0000000000000000000000000000000000000000000000000000000000001000"
}
]
}
Expand Down
14 changes: 7 additions & 7 deletions example/cfg/config_evm-evm_3.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
},
{
"type": "erc1155",
"address": "0xa3523820dc62aab22920D871fa7D8600372aC2EE"
"address": "0x9Fd58882b82EFaD2867f7eaB43539907bc07C360"
},
{
"type": "permissionedGeneric",
"address": "0xa4640d1315Be1f88aC4F81546AA2C785cf247C31"
"address": "0xF956Ba663bd563f585e00D5973E06b443E5C4D65"
},
{
"type": "permissionlessGeneric",
"address": "0xa2451c8553371E754F5e93A440aDcCa1c0DcF395"
"address": "0x156fA85e1df5d69B0F138dcEbAa5a14ca640FaED"
}
],
"gasLimit": 9000000,
Expand All @@ -65,15 +65,15 @@
},
{
"type": "erc1155",
"address": "0xa3523820dc62aab22920D871fa7D8600372aC2EE"
"address": "0x9Fd58882b82EFaD2867f7eaB43539907bc07C360"
},
{
"type": "permissionedGeneric",
"address": "0xa4640d1315Be1f88aC4F81546AA2C785cf247C31"
"address": "0xF956Ba663bd563f585e00D5973E06b443E5C4D65"
},
{
"type": "permissionlessGeneric",
"address": "0xa2451c8553371E754F5e93A440aDcCa1c0DcF395"
"address": "0x156fA85e1df5d69B0F138dcEbAa5a14ca640FaED"
}
],
"gasLimit": 9000000,
Expand Down Expand Up @@ -111,7 +111,7 @@
"resources": [
{
"address": "bcrt1pdf5c3q35ssem2l25n435fa69qr7dzwkc6gsqehuflr3euh905l2sjyr5ek",
"resourceId": "0x0000000000000000000000000000000000000000000000000000000000000900"
"resourceId": "0x0000000000000000000000000000000000000000000000000000000000001000"
}
]
}
Expand Down
4 changes: 2 additions & 2 deletions example/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit de1e24f

Please sign in to comment.