From ccbab8aa43a80fbce613cc511761870420cc7cf0 Mon Sep 17 00:00:00 2001 From: hai pham Date: Tue, 22 Oct 2024 17:59:04 +0700 Subject: [PATCH 1/3] fix: parse zeroxv3 trade --- go.sum | 2 - pkg/parser/zxrfqv3/errors.go | 1 + pkg/parser/zxrfqv3/parser.go | 65 +++++++++++ pkg/parser/zxrfqv3/parser_test.go | 102 ++++++++++++++++-- pkg/parser/zxrfqv3/settler_action.go | 3 + .../zxrfqv3/test/input_execute_data.json | 31 ++++++ 6 files changed, 193 insertions(+), 11 deletions(-) create mode 100644 pkg/parser/zxrfqv3/test/input_execute_data.json diff --git a/go.sum b/go.sum index acfbe8b..5367634 100644 --- a/go.sum +++ b/go.sum @@ -40,8 +40,6 @@ github.com/KyberNetwork/go-binance/v2 v2.0.3 h1:VsBBHXAJTxryBsdO6U9MyK+oHEJ9qZtQ github.com/KyberNetwork/go-binance/v2 v2.0.3/go.mod h1:ihNzjOXDgxZ4cSENV2sQfXnO30wobXQPpqTuKxxUVjw= github.com/KyberNetwork/kyber-trace-go v0.1.1 h1:YgzZb7jSg0Rgj7zFv9zUnSlB13Iksv1eVO5MSWAvjmM= github.com/KyberNetwork/kyber-trace-go v0.1.1/go.mod h1:X6hVacmKMeOEOlFh4TyfEHaEVRerFQ5YLuQ4keRV3hw= -github.com/KyberNetwork/tradinglib v0.4.36 h1:h8+pKMPiqnR/3Q+wGq1JWYxP3qFJ3qXqsPJQETuJcFw= -github.com/KyberNetwork/tradinglib v0.4.36/go.mod h1:3Ciie58Qmd0mFSnUWAg6phbalao6f2GGcAZ6nxw/lcQ= github.com/KyberNetwork/tradinglib v0.5.10 h1:4R9XWkfCDeisuUyxq8px1JMXNGl73+c3tIuqBX9jWl8= github.com/KyberNetwork/tradinglib v0.5.10/go.mod h1:3Ciie58Qmd0mFSnUWAg6phbalao6f2GGcAZ6nxw/lcQ= github.com/Masterminds/squirrel v1.5.4 h1:uUcX/aBc8O7Fg9kaISIUsHXdKuqehiXAMQTYX8afzqM= diff --git a/pkg/parser/zxrfqv3/errors.go b/pkg/parser/zxrfqv3/errors.go index 3dab459..305316d 100644 --- a/pkg/parser/zxrfqv3/errors.go +++ b/pkg/parser/zxrfqv3/errors.go @@ -7,6 +7,7 @@ var ( ErrInvalidRfqTrade = errors.New("invalid zeroxv3 rfq") ErrNotFoundLogWithEmptyTopic = errors.New("not found log with empty topic") ErrDetectRfqButCanNotParse = errors.New("detect zeroxv3 rfq trade but can not parse") + ErrorInputDataIsNotEnough = errors.New("input data is not enough") //abi ErrContractAddressIsZeroAddress = errors.New("contract address is zero address") diff --git a/pkg/parser/zxrfqv3/parser.go b/pkg/parser/zxrfqv3/parser.go index 039ff08..2f17be4 100644 --- a/pkg/parser/zxrfqv3/parser.go +++ b/pkg/parser/zxrfqv3/parser.go @@ -2,9 +2,11 @@ package zxrfqv3 import ( "context" + "encoding/hex" "fmt" "log" "math/big" + "strings" "time" "github.com/KyberNetwork/tradelogs/pkg/decoder" @@ -32,6 +34,7 @@ type Parser struct { } const altEventHash = "0x0000000000000000000000000000000000000000000000000000000000000000" +const paddingByteSize = 32 func MustNewParserWithDeployer(cache *tracecall.Cache, ethClient *ethclient.Client, deployerAddress common.Address, contractAbiSupported ...ContractABI) *Parser { if isZeroAddress(deployerAddress) { @@ -312,6 +315,13 @@ func (p *Parser) getExecuteActionData(contractAddress common.Address, callFrame } contractCall, err := decoder.Decode(abi, callFrame.Input) if err != nil { + actions, ok, errAction := p.DecodeExecuteInput(callFrame.Input) + if errAction != nil { + return nil, errAction + } + if ok { + return actions, nil + } return nil, err } if contractCall.Name == executeFunctionName || contractCall.Name == executeMetaTxnFunctionName { @@ -363,3 +373,58 @@ func (p *Parser) LogFromExchange(log ethereumTypes.Log) bool { func (p *Parser) Address() string { return "" } + +func (p *Parser) DecodeExecuteInput(input string) ([][]byte, bool, error) { + if len(input) < 10 { + return nil, false, ErrorInputDataIsNotEnough + } + if !strings.HasPrefix(input, executeFunctionSelector) && !strings.HasPrefix(input, executeMetaTxnFunctionSelector) { + return nil, false, nil + } + + data, err := hex.DecodeString(input[10:]) + if err != nil { + return nil, false, err + } + // function executeMetaTxn((address,address,uint256) slippage, bytes[] actions, bytes32 zid, address msgSender, bytes sig) + // function execute((address,address,uint256) slippage, bytes[] actions, bytes32 zid) + // skip: slippage (address,address,uint256): 32 + 32 + 32 = 96 bytes + offset := paddingByteSize * 3 + if len(data) < offset { + return nil, false, ErrorInputDataIsNotEnough + } + + offsetActions := new(big.Int).SetBytes(data[offset : offset+paddingByteSize]).Uint64() + // skip actions and zid + offset += paddingByteSize * 2 + + // with executeMetaTxn we need to skip msgSender and sig too + if strings.HasPrefix(input, executeMetaTxnFunctionSelector) { + offset += paddingByteSize * 2 + } + if len(data) < offset { + return nil, false, ErrorInputDataIsNotEnough + } + actionsSize := new(big.Int).SetBytes(data[offsetActions : offsetActions+paddingByteSize]).Uint64() + baseOffset := int(offsetActions + paddingByteSize) + // skip actions size + offset += paddingByteSize + var eachActionOffset []int + + for i := 0; i < int(actionsSize); i++ { + actionOffset := new(big.Int).SetBytes(data[offset : offset+paddingByteSize]).Uint64() + eachActionOffset = append(eachActionOffset, int(actionOffset)) + offset += paddingByteSize + } + var actions [][]byte + for i := 0; i < int(actionsSize); i++ { + startOffset := baseOffset + eachActionOffset[i] + paddingByteSize + actionSize := int(new(big.Int).SetBytes(data[eachActionOffset[i]:startOffset]).Int64()) + endIndex := startOffset + actionSize + if actionSize > len(data) { + endIndex = len(data) + } + actions = append(actions, data[startOffset:endIndex]) + } + return actions, true, nil +} diff --git a/pkg/parser/zxrfqv3/parser_test.go b/pkg/parser/zxrfqv3/parser_test.go index 360c0f0..0681c97 100644 --- a/pkg/parser/zxrfqv3/parser_test.go +++ b/pkg/parser/zxrfqv3/parser_test.go @@ -2,7 +2,9 @@ package zxrfqv3 import ( "context" + "encoding/hex" "encoding/json" + "fmt" "os" "testing" @@ -19,16 +21,16 @@ import ( const rpcURL = "" -func newParserTest(t *testing.T, contractABI ContractABI, needRpc bool) *Parser { +func newParserTest(t *testing.T, needRpc bool, contractABI ...ContractABI) *Parser { var cache *tracecall.Cache if needRpc { ethClient, err := ethclient.Dial(rpcURL) if err != nil { - panic(err) + t.Fatalf("failed to dial to rpc url: %s, err: %s", rpcURL, err) } cache = tracecall.NewCache(rpcnode.NewClient(zap.S(), ethClient)) } - return MustNewParser(cache, contractABI) + return MustNewParser(cache, contractABI...) } func getTestCaseData(t *testing.T, path string, result interface{}) { @@ -46,10 +48,10 @@ func TestGetActionDataFromCallFame(t *testing.T) { getTestCaseData(t, "./test/expected_input_rfq.json", &expectedInput) contractAddress := common.HexToAddress("0x7966aF62034313D87Ede39380bf60f1A84c62BE7") - parser := newParserTest(t, ContractABI{ + parser := newParserTest(t, false, ContractABI{ Address: contractAddress, ContractType: DevContract, - }, false) + }) data, err := parser.getExecuteActionData(contractAddress, callFrame) assert.NoError(t, err, "failed to get execute action data") actionType, rawData, err := decodeCall(data[1]) @@ -78,10 +80,10 @@ func TestGetTransactionAndParseZeroxV3Rfq(t *testing.T) { txHash := common.HexToHash("0xb244877d0cf0badcf2ac82dbb3cbf338b420ab5d1c6e6630fce4a4874121e427") contractAddress := common.HexToAddress("0x7966aF62034313D87Ede39380bf60f1A84c62BE7") - parser := newParserTest(t, ContractABI{ + parser := newParserTest(t, true, ContractABI{ Address: contractAddress, ContractType: DevContract, - }, true) + }) ethClient, err := ethclient.Dial(rpcURL) if err != nil { t.Fatalf("failed to dial to rpc url: %s, err: %s", rpcURL, err) @@ -96,8 +98,6 @@ func TestGetTransactionAndParseZeroxV3Rfq(t *testing.T) { tradeLog, err := parser.Parse(*log, 1) assert.NoError(t, err, "failed to parse trade log") assert.Equal(t, expectedTradelog, tradeLog, "trade log not match") - //x, _ := json.MarshalIndent(tradeLog, "", "\t") - //fmt.Println(string(x)) } } assert.Greater(t, rfqCount, 0, "no rfq trade found") @@ -111,3 +111,87 @@ func TestMustNewParserWithDeployer(t *testing.T) { parser := MustNewParserWithDeployer(nil, ethClient, contractAddress) assert.NotNil(t, parser, "failed to create parser") } + +func TestParseTradeLogsZeroxv3(t *testing.T) { + t.Skip("Need to add the rpc url that enables the trace call JSON-RPC") + type testCase struct { + TxHash common.Hash + ExpectedRfqTrade int + } + + testCases := []testCase{ + { + TxHash: common.HexToHash("0x8775544670f4c40271b3c9ab1b48e0648a1862bedd600c46f017e999b132e6a8"), + ExpectedRfqTrade: 1, + }, + { + TxHash: common.HexToHash("0x99aba817ba6171488417da6990947413064eaff5200bc8d0be9f0c87580f19cc"), + ExpectedRfqTrade: 1, + }, + { + TxHash: common.HexToHash("0xd90590fbf2799cbe63dac8a8a3dd05798b4ee0bd9077654fc1fc85cc09ad5bd1"), + ExpectedRfqTrade: 2, + }, + { + TxHash: common.HexToHash("0x3fff39d6025924755ecfe4787e09cec3f87926791ce31ac79e58ba615463b564"), + ExpectedRfqTrade: 4, + }, + { + TxHash: common.HexToHash("0x56ecb98917f20cfe1864a45e18d2afadbdf43b16b397464fda32bc08bb3018b6"), + ExpectedRfqTrade: 2, + }, + { + TxHash: common.HexToHash("0xb81b2c0467c3c7b8f85a46c25b4b5fdb10256b36d0b2e1426c11f8ed1d710b61"), + ExpectedRfqTrade: 1, + }, + } + + swapContractAddress := common.HexToAddress("0x70bf6634eE8Cb27D04478f184b9b8BB13E5f4710") + gasLessContractAddress := common.HexToAddress("0x12D737470fB3ec6C3DeEC9b518100Bec9D520144") + parser := newParserTest(t, true, ContractABI{ + Address: swapContractAddress, + ContractType: SwapContract, + }, ContractABI{ + Address: gasLessContractAddress, + ContractType: SwapContract, + }) + ethClient, err := ethclient.Dial(rpcURL) + if err != nil { + t.Fatalf("failed to dial to rpc url: %s, err: %s", rpcURL, err) + } + + for _, tc := range testCases { + txReceipt, err := ethClient.TransactionReceipt(context.Background(), tc.TxHash) + require.NoError(t, err, "failed to get tx receipt") + rfqCount := 0 + for _, log := range txReceipt.Logs { + if parser.contractABIs.containAddress(log.Address) && len(log.Topics) == 0 { + rfqCount++ + tradeLog, err := parser.Parse(*log, 1) + assert.NoError(t, err, "failed to parse trade log") + t.Log(tradeLog) + } + } + assert.Equal(t, tc.ExpectedRfqTrade, rfqCount, fmt.Sprintf("Tx hash %s number rfq is not expected", tc.TxHash.Hex())) + } +} + +func TestParserActionsWithCuttingBytes(t *testing.T) { + parser := MustNewParser(nil) + type inputTest struct { + InputData string `json:"input_data"` + Actions []string `json:"actions"` + } + var inputTestCases []inputTest + getTestCaseData(t, "./test/input_execute_data.json", &inputTestCases) + for _, input := range inputTestCases { + inputData := input.InputData + actions, ok, err := parser.DecodeExecuteInput(inputData) + assert.NoError(t, err, "failed to parse action data") + assert.True(t, ok, "failed to parse action data") + require.Equal(t, len(actions), len(input.Actions), "action length not match") + for i, action := range actions { + assert.Equal(t, input.Actions[i], hex.EncodeToString(action), "action not match") + } + } +} diff --git a/pkg/parser/zxrfqv3/settler_action.go b/pkg/parser/zxrfqv3/settler_action.go index 099cba0..5407e39 100644 --- a/pkg/parser/zxrfqv3/settler_action.go +++ b/pkg/parser/zxrfqv3/settler_action.go @@ -22,6 +22,9 @@ const ( executeFunctionName = "execute" executeMetaTxnFunctionName = "executeMetaTxn" actionParamName = "actions" + + executeFunctionSelector = "0x1fff991f" + executeMetaTxnFunctionSelector = "0xfd3ad6d4" ) var mSettlerActionName map[FunctionName]FunctionABI diff --git a/pkg/parser/zxrfqv3/test/input_execute_data.json b/pkg/parser/zxrfqv3/test/input_execute_data.json new file mode 100644 index 0000000..05d06cf --- /dev/null +++ b/pkg/parser/zxrfqv3/test/input_execute_data.json @@ -0,0 +1,31 @@ +[ + { + "input_data": "0x1fff991f00000000000000000000000018cf159e1776ca6bdbe6719dace450121b4603b4000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000000000000000000000000000422ad08e8a6f7eac00000000000000000000000000000000000000000000000000000000000000a0782a7eb7cd1c1f433de4ebb21d49ab000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000a40000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002e00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000006e00000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000090000000000000000000000000000000000000000000000000000000000000001a4d92aadfb00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000001f55c99918ecefcb5eadc11e0a58413e08ff130f38f96d7222b19c0e4d9be7142c02463be0a2b96b0000000000000000000000000000000000000000000000000000000067106e55000000000000000000000000bf19cbf0256f19f39a016a86ff3551ecc6f2aafe0000000000000000000000000000000000000000000000000000000000000120000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d8e7c26370000000000000000000000000000000000000000000000000000395af6275dfe00000000000000000000000000000000000000000000000000000000000000410d047835cec04dac44f56755cccc8f32aaf225ccd7b100edb08c511986e4fab46878c1f6db942268055f16254c5c68866f66b77fb5e131e508a0988d7c2d6b5f1c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e48d68a15600000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f47100000000000000000000000000000000000000000000000000000000000000aa700000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002cee2a03aa6dacf51c18679c516ad5283d8e7c263700000bb8c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c4103b48be00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d8e7c263700000000000000000000000000000000000000000000000000000000000011160000000000000000000000003885fbe4cd8aed7b7e9625923927fa1ce30662a30000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a4d92aadfb00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000b13acacd5eadc11e0a58413e08ff130f38f96d7222b19c0e4d9be7142c02463be0a2b96c0000000000000000000000000000000000000000000000000000000067106e73000000000000000000000000ff8ba4d1fc3762f6154cc942ccf30049a2a0cec60000000000000000000000000000000000000000000000000000000000000120000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d8e7c263700000000000000000000000000000000000000000000000000001cad7b13aeff000000000000000000000000000000000000000000000000000000000000004187eba24314b44783d2ad45f5fdff9927151419a7bda12a1dd44836b55ea9a96645427a4c0b261857baa4215119d815ad314947534874ff0560adccf5e14c70801b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e48d68a15600000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002cdac17f958d2ee523a2206206994597c13d831ec7000001f42260fac5e5542a773aa44fbcfedf7c193bc2c59900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c4103b48be00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f47100000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000002710000000000000000000000000ceff51756c56ceffca006cd410b03ffc46dd3a580000000000000000000000000000000000000000000000000000000000001e01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010438c9c147000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000002710000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000242e1a7d4d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffc1fb425e00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d8e7c263700000000000000000000000000000000000000000000000000007f74cdacd0df0000000000000000000000000000000000006e898131631616b1779bad70bc200000000000000000000000000000000000000000000000000000000067106f4500000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000416d386e77ced75ed7c62688f8d0f54b9aca548d508d3bcb7544f7e4dca9fd805c767c90f3076f638ff1adee6e041aee5a3c4545abf078aefdbb72ac76463db76b1c", + "actions": [ + "c1fb425e00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d8e7c263700000000000000000000000000000000000000000000000000007f74cdacd0df0000000000000000000000000000000000006e898131631616b1779bad70bc200000000000000000000000000000000000000000000000000000000067106f4500000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000416d386e77ced75ed7c62688f8d0f54b9aca548d508d3bcb7544f7e4dca9fd805c767c90f3076f638ff1adee6e041aee5a3c4545abf078aefdbb72ac76463db76b1c", + "d92aadfb00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000001f55c99918ecefcb5eadc11e0a58413e08ff130f38f96d7222b19c0e4d9be7142c02463be0a2b96b0000000000000000000000000000000000000000000000000000000067106e55000000000000000000000000bf19cbf0256f19f39a016a86ff3551ecc6f2aafe0000000000000000000000000000000000000000000000000000000000000120000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d8e7c26370000000000000000000000000000000000000000000000000000395af6275dfe00000000000000000000000000000000000000000000000000000000000000410d047835cec04dac44f56755cccc8f32aaf225ccd7b100edb08c511986e4fab46878c1f6db942268055f16254c5c68866f66b77fb5e131e508a0988d7c2d6b5f1c00000000000000000000000000000000000000000000000000000000000000", + "8d68a15600000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f47100000000000000000000000000000000000000000000000000000000000000aa700000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002cee2a03aa6dacf51c18679c516ad5283d8e7c263700000bb8c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000", + "103b48be00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d8e7c263700000000000000000000000000000000000000000000000000000000000011160000000000000000000000003885fbe4cd8aed7b7e9625923927fa1ce30662a30000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000000000", + "d92aadfb00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000b13acacd5eadc11e0a58413e08ff130f38f96d7222b19c0e4d9be7142c02463be0a2b96c0000000000000000000000000000000000000000000000000000000067106e73000000000000000000000000ff8ba4d1fc3762f6154cc942ccf30049a2a0cec60000000000000000000000000000000000000000000000000000000000000120000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d8e7c263700000000000000000000000000000000000000000000000000001cad7b13aeff000000000000000000000000000000000000000000000000000000000000004187eba24314b44783d2ad45f5fdff9927151419a7bda12a1dd44836b55ea9a96645427a4c0b261857baa4215119d815ad314947534874ff0560adccf5e14c70801b00000000000000000000000000000000000000000000000000000000000000", + "8d68a15600000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002cdac17f958d2ee523a2206206994597c13d831ec7000001f42260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000", + "103b48be00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f47100000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000002710000000000000000000000000ceff51756c56ceffca006cd410b03ffc46dd3a580000000000000000000000000000000000000000000000000000000000001e010000000000000000000000000000000000000000000000000000000000000000", + "38c9c147000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000002710000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000242e1a7d4d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + ] + }, + { + "input_data": "0xfd3ad6d4000000000000000000000000b0331660b88be0516cc75a1005a6eea6fefdc599000000000000000000000000594daad7d77592a2b97b725a7ad59d7e188b5bfa00000000000000000000000000000000000000000000786c2e2da5f81a593d5c00000000000000000000000000000000000000000000000000000000000000e0c7ce7560c1dc89580b6dd5201d49ab0000000000000000000000000000000000000000000000000000000000b0331660b88be0516cc75a1005a6eea6fefdc599000000000000000000000000000000000000000000000000000000000000058000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000000a40dfeb41900000000000000000000000012d737470fb3ec6c3deec9b518100bec9d520144000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000000225237e60000000000000000000000000000000000006e898131631616b1779bad70bc140000000000000000000000000000000000000000000000000000000067177daf00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012438c9c147000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000008a000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000044a9059cbb00000000000000000000000038f5e5b4da37531a6e85161e337e0238bb27aa900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a4d92aadfb00000000000000000000000012d737470fb3ec6c3deec9b518100bec9d520144000000000000000000000000594daad7d77592a2b97b725a7ad59d7e188b5bfa000000000000000000000000000000000000000000007a2b9d4e7e068f0ffa00e0c7c3d565d843982dcb2dfe380d076c74066eaf820f74c5942e739e5ba33a9b0000000000000000000000000000000000000000000000000000000067177cdd000000000000000000000000ff8ba4d1fc3762f6154cc942ccf30049a2a0cec60000000000000000000000000000000000000000000000000000000000000120000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000000223c40b800000000000000000000000000000000000000000000000000000000000000413377fd41dd05fe5f41224fdb83acf0ea5492b8d8ddb3f8ac28876dc20887a96046e2c42ed90f89b21d9f8885ec0115d35fa285eddb9ef392ab0659092b05debf1b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000416a7b4d03f5e9225176fc05da2061237cd829fbbf827be505010df2a124cafbe342d0b4390b6cd76edd42e057b7f1c0d4225d7f00e018b0335cbed3ab7ad407291c00000000000000000000000000000000000000000000000000000000000000", + "actions": [ + "0dfeb41900000000000000000000000012d737470fb3ec6c3deec9b518100bec9d520144000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000000225237e60000000000000000000000000000000000006e898131631616b1779bad70bc140000000000000000000000000000000000000000000000000000000067177daf", + "38c9c147000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000008a000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000044a9059cbb00000000000000000000000038f5e5b4da37531a6e85161e337e0238bb27aa90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "d92aadfb00000000000000000000000012d737470fb3ec6c3deec9b518100bec9d520144000000000000000000000000594daad7d77592a2b97b725a7ad59d7e188b5bfa000000000000000000000000000000000000000000007a2b9d4e7e068f0ffa00e0c7c3d565d843982dcb2dfe380d076c74066eaf820f74c5942e739e5ba33a9b0000000000000000000000000000000000000000000000000000000067177cdd000000000000000000000000ff8ba4d1fc3762f6154cc942ccf30049a2a0cec60000000000000000000000000000000000000000000000000000000000000120000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000000223c40b800000000000000000000000000000000000000000000000000000000000000413377fd41dd05fe5f41224fdb83acf0ea5492b8d8ddb3f8ac28876dc20887a96046e2c42ed90f89b21d9f8885ec0115d35fa285eddb9ef392ab0659092b05debf1b00000000000000000000000000000000000000000000000000000000000000" + ] + }, + { + "input_data": "0xfd3ad6d400000000000000000000000031579fa8ca29087317e7d2f907cedf6ff42b8b26000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000000000000000000000000000115b52997a573d9500000000000000000000000000000000000000000000000000000000000000e0d7b34d5d98dcedb1bb3a6f9b1d49ab000000000000000000000000000000000000000000000000000000000031579fa8ca29087317e7d2f907cedf6ff42b8b2600000000000000000000000000000000000000000000000000000000000005200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000032000000000000000000000000000000000000000000000000000000000000001449ebf8e8d00000000000000000000000012d737470fb3ec6c3deec9b518100bec9d52014400000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000eeee2a2e650697d2a8e8bc990c2f3d04203be06f0000000000000000000000000000000000000000000084595161401484a000000000000000000000000000000000000000006e898131631616b1779bad70bc110000000000000000000000000000000000000000000000000000000067177d400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002ceeee2a2e650697d2a8e8bc990c2f3d04203be06f00002710c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010438c9c147000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000002710000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000242e1a7d4d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c438c9c147000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000038f5e5b4da37531a6e85161e337e0238bb27aa90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000413b11e3a188a202578ca5c5cabed3b9084dec54e3b00dca5e1e829c9ae043739418ee67fb2d7820084d9f6f14c9006ff502f5ab3382045dde24ffd9c4b6aaa9941b00000000000000000000000000000000000000000000000000000000000000", + "actions": [ + "9ebf8e8d00000000000000000000000012d737470fb3ec6c3deec9b518100bec9d52014400000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000eeee2a2e650697d2a8e8bc990c2f3d04203be06f0000000000000000000000000000000000000000000084595161401484a000000000000000000000000000000000000000006e898131631616b1779bad70bc110000000000000000000000000000000000000000000000000000000067177d400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002ceeee2a2e650697d2a8e8bc990c2f3d04203be06f00002710c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000", + "38c9c147000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000002710000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000242e1a7d4d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "38c9c147000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000038f5e5b4da37531a6e85161e337e0238bb27aa90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000" + ] + } +] \ No newline at end of file From e9db2d3aa17d889ae622d72bf3d0b293e7ae9be4 Mon Sep 17 00:00:00 2001 From: hai pham Date: Wed, 23 Oct 2024 12:00:16 +0700 Subject: [PATCH 2/3] docs(zeroxv3): add docs for decode input execute function --- pkg/parser/zxrfqv3/docs.go | 162 +++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 pkg/parser/zxrfqv3/docs.go diff --git a/pkg/parser/zxrfqv3/docs.go b/pkg/parser/zxrfqv3/docs.go new file mode 100644 index 0000000..2b3ac86 --- /dev/null +++ b/pkg/parser/zxrfqv3/docs.go @@ -0,0 +1,162 @@ +package zxrfqv3 + +// To detect tradelog of zeroxv3. We will look into the event log output, if the event log has address is the gasless or +// swap contract address and has no topic (as log0), we will consider it as a trade log. +// log0 only emit when call though function execute or executeMetaTxn, so in the implementation, we will check +// function selector (first 4 bytes) of input data is equal to execute or executeMetaTxn function selector. + +// function execute((address,address,uint256) slippage, bytes[] actions, bytes32 zid): selector = 0x1fff991f +// function executeMetaTxn((address,address,uint256) slippage, bytes[] actions, bytes32 zid): selector = 0xfd3ad6d4 +// However, there is an exception when decoding the input of these functions. The actions parameter is of type bytes[], +// which means it has dynamic data size. This can lead to a situation where the first byte in actions may +// indicate an overflow in the data size. In other words, the indicated data size could be larger than the actual +// input data, causing ABI decoding to fail and return an error. +// To handle this case, we need to detect the offset of each bytes element in the actions array. +// If the size of an action exceeds the size of the input data, we will cap it to the maximum available size of the input. + +// Detail implement: DecodeExecuteInput(input string) ([][]byte, bool, error) +// 1) check the input size contain the function selector (execute, executeMetaTxn) +// 2) the format of input will be: selector + slippage + actions metadata + zid + byte data of actions +// 3) with fixed size data like slippage and byte32 each parameter will have fixed size is 32 bytes we call it is paddingByteSize +// we will move the offset out of slippage +// 4) the next paddingByteSize bytes will be the size of actions we will call it actionsSize, +// the baseOffset is next paddingByteSize bytes after actionsSize +// 5) for loop the actionsSize to detect the offset of each action +// 6) for each action, we need to calculate 2 thing: +// + startOffset: baseOffset + it's offset + 32 bytes (paddingByteSize) +// + actionSize: max(len(input), int(startOffset + 32)) +// action = input[startOffset:actionSize] + +// Example: with this https://etherscan.io/tx/0xc7f14f7ef30bea8bc001faff8282a7dc554b0ade37134bfbf5ff2398b1680227 +// input data +// 0x1fff991f +// 00000000000000000000000018cf159e1776ca6bdbe6719dace450121b4603b4 +// 000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee +// 000000000000000000000000000000000000000000000000422ad08e8a6f7eac +// 00000000000000000000000000000000000000000000000000000000000000a0 +// 782a7eb7cd1c1f433de4ebb21d49ab0000000000000000000000000000000000 +// 0000000000000000000000000000000000000000000000000000000000000008 +// 0000000000000000000000000000000000000000000000000000000000000a40 +// 0000000000000000000000000000000000000000000000000000000000000100 +// 00000000000000000000000000000000000000000000000000000000000002e0 +// 0000000000000000000000000000000000000000000000000000000000000400 +// 0000000000000000000000000000000000000000000000000000000000000500 +// 00000000000000000000000000000000000000000000000000000000000006e0 +// 0000000000000000000000000000000000000000000000000000000000000800 +// 0000000000000000000000000000000000000000000000000000000000000900 +// 00000000000000000000000000000000000000000000000000000000000001a4 +// d92aadfb00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb1 +// 3e5f4710000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead908 +// 3c756cc20000000000000000000000000000000000000000000000001f55c999 +// 18ecefcb5eadc11e0a58413e08ff130f38f96d7222b19c0e4d9be7142c02463b +// e0a2b96b00000000000000000000000000000000000000000000000000000000 +// 67106e55000000000000000000000000bf19cbf0256f19f39a016a86ff3551ec +// c6f2aafe00000000000000000000000000000000000000000000000000000000 +// 00000120000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d +// 8e7c26370000000000000000000000000000000000000000000000000000395a +// f6275dfe00000000000000000000000000000000000000000000000000000000 +// 000000410d047835cec04dac44f56755cccc8f32aaf225ccd7b100edb08c5119 +// 86e4fab46878c1f6db942268055f16254c5c68866f66b77fb5e131e508a0988d +// 7c2d6b5f1c000000000000000000000000000000000000000000000000000000 +// 0000000000000000000000000000000000000000000000000000000000000000 +// 00000000000000000000000000000000000000000000000000000000000000e4 +// 8d68a15600000000000000000000000070bf6634ee8cb27d04478f184b9b8bb1 +// 3e5f471000000000000000000000000000000000000000000000000000000000 +// 00000aa700000000000000000000000000000000000000000000000000000000 +// 0000008000000000000000000000000000000000000000000000000000000000 +// 0000000000000000000000000000000000000000000000000000000000000000 +// 0000002cee2a03aa6dacf51c18679c516ad5283d8e7c263700000bb8c02aaa39 +// b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000 +// 0000000000000000000000000000000000000000000000000000000000000000 +// 00000000000000000000000000000000000000000000000000000000000000c4 +// 103b48be00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb1 +// 3e5f4710000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d +// 8e7c263700000000000000000000000000000000000000000000000000000000 +// 000011160000000000000000000000003885fbe4cd8aed7b7e9625923927fa1c +// e30662a300000000000000000000000000000000000000000000000000000000 +// 00001e0000000000000000000000000000000000000000000000000000000000 +// 0000000000000000000000000000000000000000000000000000000000000000 +// 00000000000000000000000000000000000000000000000000000000000001a4 +// d92aadfb00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb1 +// 3e5f4710000000000000000000000000dac17f958d2ee523a2206206994597c1 +// 3d831ec700000000000000000000000000000000000000000000000000000000 +// b13acacd5eadc11e0a58413e08ff130f38f96d7222b19c0e4d9be7142c02463b +// e0a2b96c00000000000000000000000000000000000000000000000000000000 +// 67106e73000000000000000000000000ff8ba4d1fc3762f6154cc942ccf30049 +// a2a0cec600000000000000000000000000000000000000000000000000000000 +// 00000120000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d +// 8e7c263700000000000000000000000000000000000000000000000000001cad +// 7b13aeff00000000000000000000000000000000000000000000000000000000 +// 0000004187eba24314b44783d2ad45f5fdff9927151419a7bda12a1dd44836b5 +// 5ea9a96645427a4c0b261857baa4215119d815ad314947534874ff0560adccf5 +// e14c70801b000000000000000000000000000000000000000000000000000000 +// 0000000000000000000000000000000000000000000000000000000000000000 +// 00000000000000000000000000000000000000000000000000000000000000e4 +// 8d68a15600000000000000000000000070bf6634ee8cb27d04478f184b9b8bb1 +// 3e5f471000000000000000000000000000000000000000000000000000000000 +// 0000271000000000000000000000000000000000000000000000000000000000 +// 0000008000000000000000000000000000000000000000000000000000000000 +// 0000000000000000000000000000000000000000000000000000000000000000 +// 0000002cdac17f958d2ee523a2206206994597c13d831ec7000001f42260fac5 +// e5542a773aa44fbcfedf7c193bc2c59900000000000000000000000000000000 +// 0000000000000000000000000000000000000000000000000000000000000000 +// 00000000000000000000000000000000000000000000000000000000000000c4 +// 103b48be00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb1 +// 3e5f47100000000000000000000000002260fac5e5542a773aa44fbcfedf7c19 +// 3bc2c59900000000000000000000000000000000000000000000000000000000 +// 00002710000000000000000000000000ceff51756c56ceffca006cd410b03ffc +// 46dd3a5800000000000000000000000000000000000000000000000000000000 +// 00001e0100000000000000000000000000000000000000000000000000000000 +// 0000000000000000000000000000000000000000000000000000000000000000 +// 0000000000000000000000000000000000000000000000000000000000000104 +// 38c9c147000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead908 +// 3c756cc200000000000000000000000000000000000000000000000000000000 +// 00002710000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead908 +// 3c756cc200000000000000000000000000000000000000000000000000000000 +// 0000000400000000000000000000000000000000000000000000000000000000 +// 000000a000000000000000000000000000000000000000000000000000000000 +// 000000242e1a7d4d000000000000000000000000000000000000000000000000 +// 0000000000000000000000000000000000000000000000000000000000000000 +// 0000000000000000000000000000000000000000000000000000000000000000 +// 000000000000000000000000000000000000000000000000000000000000ffff +// c1fb425e00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb1 +// 3e5f4710000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d +// 8e7c263700000000000000000000000000000000000000000000000000007f74 +// cdacd0df0000000000000000000000000000000000006e898131631616b1779b +// ad70bc2000000000000000000000000000000000000000000000000000000000 +// 67106f4500000000000000000000000000000000000000000000000000000000 +// 000000c000000000000000000000000000000000000000000000000000000000 +// 000000416d386e77ced75ed7c62688f8d0f54b9aca548d508d3bcb7544f7e4dc +// a9fd805c767c90f3076f638ff1adee6e041aee5a3c4545abf078aefdbb72ac76 +// 463db76b1c + +// input +//selector: 0x1fff991f +//00000000000000000000000018cf159e1776ca6bdbe6719dace450121b4603b4 // 0x0000: receipient padding to 32 bytes +//000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee // 0x0020: by token, padding to 32 bytes +//000000000000000000000000000000000000000000000000422ad08e8a6f7eac // 0x0040: minAmoutOut padding to 32 bytes +//00000000000000000000000000000000000000000000000000000000000000a0 // 0x0060: offset to actions, 0xa0 = 160 = 5 * 32 +//782a7eb7cd1c1f433de4ebb21d49ab0000000000000000000000000000000000 // 0x0080: zid bytes32 +// +//0000000000000000000000000000000000000000000000000000000000000008 // 0x00a0: start of actions array here(0xa0), slice has 8 elements, following is actions array data, start at 0xa0 + 0x20 = 0xc0 (we call base_offset) +//0000000000000000000000000000000000000000000000000000000000000a40 // 0x00c0: offset to first element(should add with base_offset to get item data => 0xa40 + 0xc0) +//0000000000000000000000000000000000000000000000000000000000000100 // 0x00e0: offset to 2nd -> (offset to 2nd element = = 0x100 + 0xc0 = 0x1c0) +//00000000000000000000000000000000000000000000000000000000000002e0 // 0x0100 offset to 3rd +//0000000000000000000000000000000000000000000000000000000000000400 // 0x0120: offset to 4th +//0000000000000000000000000000000000000000000000000000000000000500 // 0x0140: offset to 5th +//00000000000000000000000000000000000000000000000000000000000006e0 // 0x0160: offset to 6th +//0000000000000000000000000000000000000000000000000000000000000800 // 0x0180: offset to 7th +//0000000000000000000000000000000000000000000000000000000000000900 // 0x01a0: offset to 8th +// +//00000000000000000000000000000000000000000000000000000000000001a4 // 0x01c0: this is start of 2nd element (the second action), which is a bytes slice with length = 0x1a4, following is its data +//d92aadfb00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000001f55c99918ecefcb5eadc11e0a58413e08ff130f38f96d7222b19c0e4d9be7142c02463be0a2b96b0000000000000000000000000000000000000000000000000000000067106e55000000000000000000000000bf19cbf0256f19f39a016a86ff3551ecc6f2aafe0000000000000000000000000000000000000000000000000000000000000120000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d8e7c26370000000000000000000000000000000000000000000000000000395af6275dfe00000000000000000000000000000000000000000000000000000000000000410d047835cec04dac44f56755cccc8f32aaf225ccd7b100edb08c511986e4fab46878c1f6db942268055f16254c5c68866f66b77fb5e131e508a0988d7c2d6b5f1c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e48d68a15600000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f47100000000000000000000000000000000000000000000000000000000000000aa700000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002cee2a03aa6dacf51c18679c516ad5283d8e7c263700000bb8c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c4103b48be00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d8e7c263700000000000000000000000000000000000000000000000000000000000011160000000000000000000000003885fbe4cd8aed7b7e9625923927fa1ce30662a30000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a4d92aadfb00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000b13acacd5eadc11e0a58413e08ff130f38f96d7222b19c0e4d9be7142c02463be0a2b96c0000000000000000000000000000000000000000000000000000000067106e73000000000000000000000000ff8ba4d1fc3762f6154cc942ccf30049a2a0cec60000000000000000000000000000000000000000000000000000000000000120000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d8e7c263700000000000000000000000000000000000000000000000000001cad7b13aeff000000000000000000000000000000000000000000000000000000000000004187eba24314b44783d2ad45f5fdff9927151419a7bda12a1dd44836b55ea9a96645427a4c0b261857baa4215119d815ad314947534874ff0560adccf5e14c70801b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e48d68a15600000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002cdac17f958d2ee523a2206206994597c13d831ec7000001f42260fac5e5542a773aa44fbcfedf7c193bc2c59900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c4103b48be00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f47100000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000002710000000000000000000000000ceff51756c56ceffca006cd410b03ffc46dd3a580000000000000000000000000000000000000000000000000000000000001e01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010438c9c147000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000002710000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000242e1a7d4d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffc1fb425e00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d8e7c263700000000000000000000000000000000000000000000000000007f74cdacd0df0000000000000000000000000000000000006e898131631616b1779bad70bc200000000000000000000000000000000000000000000000000000000067106f4500000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000416d386e77ced75ed7c62688f8d0f54b9aca548d508d3bcb7544f7e4dca9fd805c767c90f3076f638ff1adee6e041aee5a3c4545abf078aefdbb72ac76463db76b1c + +// actions after decode (8 action): +// c1fb425e00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d8e7c263700000000000000000000000000000000000000000000000000007f74cdacd0df0000000000000000000000000000000000006e898131631616b1779bad70bc200000000000000000000000000000000000000000000000000000000067106f4500000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000416d386e77ced75ed7c62688f8d0f54b9aca548d508d3bcb7544f7e4dca9fd805c767c90f3076f638ff1adee6e041aee5a3c4545abf078aefdbb72ac76463db76b1c +// d92aadfb00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000001f55c99918ecefcb5eadc11e0a58413e08ff130f38f96d7222b19c0e4d9be7142c02463be0a2b96b0000000000000000000000000000000000000000000000000000000067106e55000000000000000000000000bf19cbf0256f19f39a016a86ff3551ecc6f2aafe0000000000000000000000000000000000000000000000000000000000000120000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d8e7c26370000000000000000000000000000000000000000000000000000395af6275dfe00000000000000000000000000000000000000000000000000000000000000410d047835cec04dac44f56755cccc8f32aaf225ccd7b100edb08c511986e4fab46878c1f6db942268055f16254c5c68866f66b77fb5e131e508a0988d7c2d6b5f1c00000000000000000000000000000000000000000000000000000000000000 +// 8d68a15600000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f47100000000000000000000000000000000000000000000000000000000000000aa700000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002cee2a03aa6dacf51c18679c516ad5283d8e7c263700000bb8c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000 +// 103b48be00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d8e7c263700000000000000000000000000000000000000000000000000000000000011160000000000000000000000003885fbe4cd8aed7b7e9625923927fa1ce30662a30000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000000000 +// d92aadfb00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec700000000000000000000000000000000000000000000000000000000b13acacd5eadc11e0a58413e08ff130f38f96d7222b19c0e4d9be7142c02463be0a2b96c0000000000000000000000000000000000000000000000000000000067106e73000000000000000000000000ff8ba4d1fc3762f6154cc942ccf30049a2a0cec60000000000000000000000000000000000000000000000000000000000000120000000000000000000000000ee2a03aa6dacf51c18679c516ad5283d8e7c263700000000000000000000000000000000000000000000000000001cad7b13aeff000000000000000000000000000000000000000000000000000000000000004187eba24314b44783d2ad45f5fdff9927151419a7bda12a1dd44836b55ea9a96645427a4c0b261857baa4215119d815ad314947534874ff0560adccf5e14c70801b00000000000000000000000000000000000000000000000000000000000000 +// 8d68a15600000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f4710000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002cdac17f958d2ee523a2206206994597c13d831ec7000001f42260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000 +// 103b48be00000000000000000000000070bf6634ee8cb27d04478f184b9b8bb13e5f47100000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000002710000000000000000000000000ceff51756c56ceffca006cd410b03ffc46dd3a580000000000000000000000000000000000000000000000000000000000001e010000000000000000000000000000000000000000000000000000000000000000 +// 38c9c147000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000002710000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000242e1a7d4d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" From 9735fdf06fbf4ffc1f4dfb32eb5c3d73cbfba61f Mon Sep 17 00:00:00 2001 From: hai pham Date: Wed, 23 Oct 2024 13:19:10 +0700 Subject: [PATCH 3/3] chore: init slice size --- pkg/parser/zxrfqv3/parser.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/parser/zxrfqv3/parser.go b/pkg/parser/zxrfqv3/parser.go index 2f17be4..377bd91 100644 --- a/pkg/parser/zxrfqv3/parser.go +++ b/pkg/parser/zxrfqv3/parser.go @@ -409,14 +409,15 @@ func (p *Parser) DecodeExecuteInput(input string) ([][]byte, bool, error) { baseOffset := int(offsetActions + paddingByteSize) // skip actions size offset += paddingByteSize - var eachActionOffset []int + eachActionOffset := make([]int, actionsSize) for i := 0; i < int(actionsSize); i++ { actionOffset := new(big.Int).SetBytes(data[offset : offset+paddingByteSize]).Uint64() - eachActionOffset = append(eachActionOffset, int(actionOffset)) + eachActionOffset[i] = int(actionOffset) offset += paddingByteSize } - var actions [][]byte + + actions := make([][]byte, actionsSize) for i := 0; i < int(actionsSize); i++ { startOffset := baseOffset + eachActionOffset[i] + paddingByteSize actionSize := int(new(big.Int).SetBytes(data[eachActionOffset[i]:startOffset]).Int64()) @@ -424,7 +425,7 @@ func (p *Parser) DecodeExecuteInput(input string) ([][]byte, bool, error) { if actionSize > len(data) { endIndex = len(data) } - actions = append(actions, data[startOffset:endIndex]) + actions[i] = data[startOffset:endIndex] } return actions, true, nil }