Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add signature to callframe decode. #116

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eth/tracers/blocknative/decoder/calldata.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ func decodeCallData(sender common.Address, contract *Contract, input []byte) (*C

return &CallData{
MethodID: method,
Signature: method.Signature(),
Args: args,
Transfers: transfers,
}, nil
Expand Down
23 changes: 14 additions & 9 deletions eth/tracers/blocknative/decoder/calldata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ func getTestCases() []decodeCallDataTest {
&Contract{interfaces: []Interface{interfaceTypeERC20}},
},
&CallData{
MethodID: methodIDTransferFrom,
Args: []string{"0x5470c5a6Fce7447aFd2C9BE3A0F25e362C093661", "0x479ee0363a7Ac2ef34cba7ee82D2C2E0652D4669", "6341"},
MethodID: methodIDTransferFrom,
Signature: methodSignatures[methodIDTransferFrom.String()],
Args: []string{"0x5470c5a6Fce7447aFd2C9BE3A0F25e362C093661", "0x479ee0363a7Ac2ef34cba7ee82D2C2E0652D4669", "6341"},
Transfers: []*Transfer{{
From: common.HexToAddress("0x5470c5a6Fce7447aFd2C9BE3A0F25e362C093661"),
To: common.HexToAddress("0x479ee0363a7Ac2ef34cba7ee82D2C2E0652D4669"),
Expand All @@ -66,8 +67,9 @@ func getTestCases() []decodeCallDataTest {
&Contract{interfaces: []Interface{interfaceTypeERC721}},
},
&CallData{
MethodID: methodIDTransferFrom,
Args: []string{"0x5470c5a6Fce7447aFd2C9BE3A0F25e362C093661", "0x479ee0363a7Ac2ef34cba7ee82D2C2E0652D4669", "6341"},
MethodID: methodIDTransferFrom,
Signature: methodSignatures[methodIDTransferFrom.String()],
Args: []string{"0x5470c5a6Fce7447aFd2C9BE3A0F25e362C093661", "0x479ee0363a7Ac2ef34cba7ee82D2C2E0652D4669", "6341"},
Transfers: []*Transfer{{
From: common.HexToAddress("0x5470c5a6Fce7447aFd2C9BE3A0F25e362C093661"),
To: common.HexToAddress("0x479ee0363a7Ac2ef34cba7ee82D2C2E0652D4669"),
Expand All @@ -84,8 +86,9 @@ func getTestCases() []decodeCallDataTest {
&Contract{interfaces: []Interface{interfaceTypeERC20, interfaceTypeERC721}},
},
&CallData{
MethodID: methodIDTransferFrom,
Args: []string{"0x5470c5a6Fce7447aFd2C9BE3A0F25e362C093661", "0x479ee0363a7Ac2ef34cba7ee82D2C2E0652D4669", "6341"},
MethodID: methodIDTransferFrom,
Signature: methodSignatures[methodIDTransferFrom.String()],
Args: []string{"0x5470c5a6Fce7447aFd2C9BE3A0F25e362C093661", "0x479ee0363a7Ac2ef34cba7ee82D2C2E0652D4669", "6341"},
Transfers: []*Transfer{{
From: common.HexToAddress("0x5470c5a6fce7447afd2c9be3a0f25e362c093661"),
To: common.HexToAddress("0x479ee0363a7Ac2ef34cba7ee82D2C2E0652D4669"),
Expand All @@ -102,8 +105,9 @@ func getTestCases() []decodeCallDataTest {
&Contract{interfaces: []Interface{interfaceTypeERC20, interfaceTypeERC721}},
},
&CallData{
MethodID: methodIDSafeTransferFrom3,
Args: []string{"0xcb89354a1c6e7ABd1972a68466Db238e48a3B0C8", "0x20964f741d2dfFD2cCec658CA086e21aF1D7dF8E", "29", "1"},
MethodID: methodIDSafeTransferFrom3,
Signature: methodSignatures[methodIDSafeTransferFrom3.String()],
Args: []string{"0xcb89354a1c6e7ABd1972a68466Db238e48a3B0C8", "0x20964f741d2dfFD2cCec658CA086e21aF1D7dF8E", "29", "1"},
Transfers: []*Transfer{{
From: common.HexToAddress("0xcb89354a1c6e7ABd1972a68466Db238e48a3B0C8"),
To: common.HexToAddress("0x20964f741d2dffd2ccec658ca086e21af1d7df8e"),
Expand All @@ -120,7 +124,8 @@ func getTestCases() []decodeCallDataTest {
&Contract{interfaces: []Interface{interfaceTypeERC20, interfaceTypeERC721}},
},
&CallData{
MethodID: methodIDSafeBatchTransferFrom,
MethodID: methodIDSafeBatchTransferFrom,
Signature: methodSignatures[methodIDSafeBatchTransferFrom.String()],
Transfers: []*Transfer{{
From: common.HexToAddress("0x381E840F4eBe33d0153e9A312105554594A98C42"),
To: common.HexToAddress("0xA2b876dbb382d40cECeE2ACC670f55AD95c4767e"),
Expand Down
75 changes: 53 additions & 22 deletions eth/tracers/blocknative/decoder/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,68 @@ var (
ErrMethodIDTooLong = fmt.Errorf("methodID is too long")

// ERC20
methodIDTransfer = methodIDToBytes(0xa9059cbb) // transfer(address,uint256)
methodIDTransferFrom = methodIDToBytes(0x23b872dd) // transferFrom(address,address,uint256)
methodIDTotalSupply = methodIDToBytes(0x18160ddd) // totalSupply()
methodIDBalanceOf = methodIDToBytes(0x70a08231) // balanceOf(address)
methodIDApprove = methodIDToBytes(0x095ea7b3) // approve(address,uint256)
methodIDAllowance = methodIDToBytes(0xdd62ed3e) // allowance(address,address)
methodIDTransfer = methodIDToBytes(0xa9059cbb)
methodIDTransferFrom = methodIDToBytes(0x23b872dd)
methodIDTotalSupply = methodIDToBytes(0x18160ddd)
methodIDBalanceOf = methodIDToBytes(0x70a08231)
methodIDApprove = methodIDToBytes(0x095ea7b3)
methodIDAllowance = methodIDToBytes(0xdd62ed3e)

// ERC721
methodIDSafeTransferFrom = methodIDToBytes(0x42842e0e) // safeTransferFrom(address,address,uint256)
methodIDSafeTransferFrom2 = methodIDToBytes(0xb88d4fde) // safeTransferFrom(address,address,uint256,bytes)
methodIDOwnerOf = methodIDToBytes(0x6352211e) // ownerOf(uint256)
methodIDSetApprovalForAll = methodIDToBytes(0xa22cb465) // setApprovalForAll(address,bool)
methodIDGetApproved = methodIDToBytes(0x081812fc) // getApproved(uint256)
methodIDIsApprovedForAll = methodIDToBytes(0xe985e9c5) // isApprovedForAll(address,address)
methodIDSafeTransferFrom = methodIDToBytes(0x42842e0e)
methodIDSafeTransferFrom2 = methodIDToBytes(0xb88d4fde)
methodIDOwnerOf = methodIDToBytes(0x6352211e)
methodIDSetApprovalForAll = methodIDToBytes(0xa22cb465)
methodIDGetApproved = methodIDToBytes(0x081812fc)
methodIDIsApprovedForAll = methodIDToBytes(0xe985e9c5)

// ERC1155
methodIDBalanceOf2 = methodIDToBytes(0x00fdd58e) // balanceOf(address,uint256)
methodIDBalanceOfBatch = methodIDToBytes(0x4e1273f4) // balanceOfBatch(address[],uint256[])
methodIDSafeTransferFrom3 = methodIDToBytes(0xf242432a) // safeTransferFrom(address,address,uint256,uint256,bytes)
methodIDSafeBatchTransferFrom = methodIDToBytes(0x2eb2c2d6) // safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)
methodIDBalanceOf2 = methodIDToBytes(0x00fdd58e)
methodIDBalanceOfBatch = methodIDToBytes(0x4e1273f4)
methodIDSafeTransferFrom3 = methodIDToBytes(0xf242432a)
methodIDSafeBatchTransferFrom = methodIDToBytes(0x2eb2c2d6)

// Metadata
methodIDName = methodIDToBytes(0x06fdde03) // name()
methodIDSymbol = methodIDToBytes(0x95d89b41) // symbol()
methodIDDecimals = methodIDToBytes(0x313ce567) // decimals()
methodIDTokenURI = methodIDToBytes(0xc87b56dd) // tokenURI(uint256)
methodIDURI = methodIDToBytes(0x0e89341c) // uri(uint256)
methodIDName = methodIDToBytes(0x06fdde03)
methodIDSymbol = methodIDToBytes(0x95d89b41)
methodIDDecimals = methodIDToBytes(0x313ce567)
methodIDTokenURI = methodIDToBytes(0xc87b56dd)
methodIDURI = methodIDToBytes(0x0e89341c)

// Interfaces by list of methodIDs
interfaceMethodsERC20 = []MethodID{methodIDName, methodIDSymbol, methodIDDecimals, methodIDTransfer, methodIDTransferFrom, methodIDTotalSupply, methodIDBalanceOf, methodIDApprove, methodIDAllowance}
interfaceMethodsERC721 = []MethodID{methodIDBalanceOf, methodIDOwnerOf, methodIDSafeTransferFrom, methodIDSafeTransferFrom2, methodIDTransferFrom, methodIDApprove, methodIDSetApprovalForAll, methodIDGetApproved, methodIDIsApprovedForAll}
interfaceMethodsERC1155 = []MethodID{methodIDSafeTransferFrom3, methodIDSafeBatchTransferFrom, methodIDBalanceOf2, methodIDBalanceOfBatch, methodIDSetApprovalForAll, methodIDIsApprovedForAll}
)

// methodSignatures is a map of methodID strings to their signatures.
var methodSignatures = map[string]string{
methodIDTransfer.String(): "transfer(address,uint256)",
methodIDTransferFrom.String(): "transferFrom(address,address,uint256)",
methodIDTotalSupply.String(): "totalSupply()",
methodIDBalanceOf.String(): "balanceOf(address)",
methodIDApprove.String(): "approve(address,uint256)",
methodIDAllowance.String(): "allowance(address,address)",

methodIDSafeTransferFrom.String(): "safeTransferFrom(address,address,uint256)",
methodIDSafeTransferFrom2.String(): "safeTransferFrom(address,address,uint256,bytes)",
methodIDOwnerOf.String(): "ownerOf(uint256)",
methodIDSetApprovalForAll.String(): "setApprovalForAll(address,bool)",
methodIDGetApproved.String(): "getApproved(uint256)",
methodIDIsApprovedForAll.String(): "isApprovedForAll(address,address)",

methodIDBalanceOf2.String(): "balanceOf(address,uint256)",
methodIDBalanceOfBatch.String(): "balanceOfBatch(address[],uint256[])",
methodIDSafeTransferFrom3.String(): "safeTransferFrom(address,address,uint256,uint256,bytes)",
methodIDSafeBatchTransferFrom.String(): "safeBatchTransferFrom(address,address,uint256[],uint256[],bytes)",

methodIDName.String(): "name()",
methodIDSymbol.String(): "symbol()",
methodIDDecimals.String(): "decimals()",
methodIDTokenURI.String(): "tokenURI(uint256)",
methodIDURI.String(): "uri(uint256)",
}

type MethodID []byte

func (m MethodID) Is(other MethodID) bool {
Expand All @@ -61,6 +89,10 @@ func (m MethodID) String() string {
return "0x" + hex.EncodeToString(m)
}

func (m MethodID) Signature() string {
return methodSignatures[m.String()]
}

func (m MethodID) MarshalJSON() ([]byte, error) {
return json.Marshal(m.String())
}
Expand Down Expand Up @@ -88,7 +120,6 @@ func (m *MethodID) UnmarshalJSON(b []byte) error {
// Decode hex into m.
methodIDBytes := make([]byte, 4)
if _, err := hex.Decode(methodIDBytes, b); err != nil {
panic(err)
return err
}

Expand Down
3 changes: 2 additions & 1 deletion eth/tracers/blocknative/decoder/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ type Contract struct {
}

type CallData struct {
MethodID MethodID `json:"methodID"`
MethodID MethodID `json:"method"`
Signature string `json:"signature,omitempty"`
Args []string `json:"args,omitempty"`
Transfers []*Transfer `json:"-"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"output": "0x446374989d279847d0dbc6708a9c76a419fe9831d42c78bc89473f559a00d91500000000000000000000000061d76c05cd2aa9ed5135e21e52fff188b02089d4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000092f1dbea03ce08225e31e95cc926ddbe0198e6f2000000000000000000000000529c4cb814029b8bb32acb516ea3a4b07fdae350846fd373887ade3ab7703750294876afa61cf56303f5f014a4d80d04f508a1f100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"decoded": {
"type": "erc20",
"methodID": "0x8c172fa2",
"method": "0x8c172fa2",
"args": [
"0xd9a4ffe21d19763887176173d08241e8393c1dfd208f29193dfecdf854b664ac"
]
Expand All @@ -179,7 +179,7 @@
"input": "0x24d4e90a0000000000000000000000000000000000000000000000020000000000000000",
"output": "0x000000000000000000000000000000000000000000000000b17217f7d1cf79ab",
"decoded": {
"methodID": "0x24d4e90a",
"method": "0x24d4e90a",
"args": [
"0x0000000000000000000000000000000000000000000000020000000000000000"
]
Expand All @@ -195,7 +195,7 @@
"input": "0x872fb2b5000000000000000000000000000000000000000000000000c330b3f7006420b8",
"output": "0x00000000000000000000000000000000000000000000000224bf7df2c80f0878",
"decoded": {
"methodID": "0x872fb2b5",
"method": "0x872fb2b5",
"args": [
"0x000000000000000000000000000000000000000000000000c330b3f7006420b8"
]
Expand All @@ -211,7 +211,7 @@
"input": "0x872fb2b50000000000000000000000000000000000000000000000000000000000000000",
"output": "0x00000000000000000000000000000000000000000000000100000016aee6e8ef",
"decoded": {
"methodID": "0x872fb2b5",
"method": "0x872fb2b5",
"args": [
"0x0000000000000000000000000000000000000000000000000000000000000000"
]
Expand All @@ -227,7 +227,7 @@
"input": "0x24d4e90a00000000000000000000000000000000000000000000000324bf7e0976f5f167",
"output": "0x0000000000000000000000000000000000000000000000012535c5e5f87ee0d2",
"decoded": {
"methodID": "0x24d4e90a",
"method": "0x24d4e90a",
"args": [
"0x00000000000000000000000000000000000000000000000324bf7e0976f5f167"
]
Expand All @@ -243,7 +243,7 @@
"input": "0x872fb2b5000000000000000000000000000000000000000000000000c330b3f7006420b8",
"output": "0x00000000000000000000000000000000000000000000000224bf7df2c80f0878",
"decoded": {
"methodID": "0x872fb2b5",
"method": "0x872fb2b5",
"args": [
"0x000000000000000000000000000000000000000000000000c330b3f7006420b8"
]
Expand All @@ -259,7 +259,7 @@
"input": "0x872fb2b500000000000000000000000000000000000000000000000237d37fe5d297a500",
"output": "0x0000000000000000000000000000000000000000000000093088c407fcbbce38",
"decoded": {
"methodID": "0x872fb2b5",
"method": "0x872fb2b5",
"args": [
"0x00000000000000000000000000000000000000000000000237d37fe5d297a500"
]
Expand All @@ -275,15 +275,15 @@
"input": "0x24d4e90a00000000000000000000000000000000000000000000000b554841fac4cad6b0",
"output": "0x0000000000000000000000000000000000000000000000026d7fc130d6a74cbe",
"decoded": {
"methodID": "0x24d4e90a",
"method": "0x24d4e90a",
"args": [
"0x00000000000000000000000000000000000000000000000b554841fac4cad6b0"
]
}
}
],
"decoded": {
"methodID": "0x0439978d",
"method": "0x0439978d",
"args": [
"0xe9efd3ab89acad6a3edf9828c3b00ed1c4a74e974d05d32d3b2fb15aa16fc377",
"0x0000000000000000000000000000000000000000000000004563918244f40000",
Expand All @@ -307,7 +307,7 @@
"output": "0x0000000000000000000000000000000000000000000000000071ea279ec31402",
"decoded": {
"type": "erc20",
"methodID": "0xc51cf179",
"method": "0xc51cf179",
"args": [
"0x000000000000000000000000000000000000000000000000de0b6b3a76400000"
]
Expand Down Expand Up @@ -344,7 +344,8 @@
"output": "0x0000000000000000000000000000000000000000000000000000000000000001",
"decoded": {
"type": "erc20",
"methodID": "0x23b872dd",
"method": "0x23b872dd",
"signature": "transferFrom(address,address,uint256)",
"args": [
"0x3dE712784baf97260455aE25fb74f574EC9c1add",
"0x6CA7f214AB2ddbB9A8E1A1e2C8550e3164E9dbA5",
Expand All @@ -363,7 +364,8 @@
"output": "0x0000000000000000000000000000000000000000000000000000000000000001",
"decoded": {
"type": "erc20",
"methodID": "0x095ea7b3",
"method": "0x095ea7b3",
"signature": "approve(address,uint256)",
"args": [
"0x0000000000000000000000005aae5c59d642e5fd45b427df6ed478b49d55fefd",
"0x00000000000000000000000000000000000000000000000080d29fa5cccfadac"
Expand Down Expand Up @@ -391,7 +393,8 @@
"output": "0x0000000000000000000000000000000000000000000000000000000000000001",
"decoded": {
"type": "erc20",
"methodID": "0x23b872dd",
"method": "0x23b872dd",
"signature": "transferFrom(address,address,uint256)",
"args": [
"0x6CA7f214AB2ddbB9A8E1A1e2C8550e3164E9dbA5",
"0x5aaE5c59D642E5fD45b427Df6eD478b49d55FEfD",
Expand All @@ -410,7 +413,8 @@
"output": "0x0000000000000000000000000000000000000000000000000000000000000001",
"decoded": {
"type": "erc20",
"methodID": "0xa9059cbb",
"method": "0xa9059cbb",
"signature": "transfer(address,uint256)",
"args": [
"0x950CA4a06c78934a148B7a3Ff3Ea8fC366f77A06",
"18565314632837192"
Expand All @@ -428,7 +432,7 @@
"output": "0x0000000000000000000000000000000000000000000000000000000000000001",
"decoded": {
"type": "erc20",
"methodID": "0x475a9fa9",
"method": "0x475a9fa9",
"args": [
"0x0000000000000000000000006ca7f214ab2ddbb9a8e1a1e2c8550e3164e9dba5",
"0x0000000000000000000000000000000000000000000000008090aa97a4fa4564"
Expand All @@ -446,7 +450,7 @@
"output": "0x0000000000000000000000000000000000000000000000000000000000000001",
"decoded": {
"type": "erc20",
"methodID": "0x475a9fa9",
"method": "0x475a9fa9",
"args": [
"0x0000000000000000000000006ca7f214ab2ddbb9a8e1a1e2c8550e3164e9dba5",
"0x0000000000000000000000000000000000000000000000008090aa97a4fa4564"
Expand All @@ -456,7 +460,7 @@
],
"decoded": {
"type": "erc20",
"methodID": "0x07d5b826",
"method": "0x07d5b826",
"args": [
"0xd9a4ffe21d19763887176173d08241e8393c1dfd208f29193dfecdf854b664ac",
"0x00000000000000000000000000000000000000000000000080d29fa5cccfadac"
Expand All @@ -474,7 +478,7 @@
"output": "0x000000000000000000000000f4cbd7e037b80c2e67b80512d482685f15b1fb28",
"decoded": {
"type": "erc20",
"methodID": "0x1f0c1e0c",
"method": "0x1f0c1e0c",
"args": [
"0xd9a4ffe21d19763887176173d08241e8393c1dfd208f29193dfecdf854b664ac",
"0x0000000000000000000000000000000000000000000000000000000000000001"
Expand Down Expand Up @@ -521,7 +525,7 @@
"input": "0x88d5fecb00000000000000000000000000000000000000000000000000000000000000010000000000000000000000003de712784baf97260455ae25fb74f574ec9c1add000000000000000000000000000000000000000000000000de0b6b3a76400000",
"output": "0x0000000000000000000000000000000000000000000000000000000000000001",
"decoded": {
"methodID": "0x88d5fecb",
"method": "0x88d5fecb",
"args": [
"0x0000000000000000000000000000000000000000000000000000000000000001",
"0x0000000000000000000000003de712784baf97260455ae25fb74f574ec9c1add",
Expand All @@ -532,7 +536,8 @@
],
"decoded": {
"type": "erc20",
"methodID": "0xa9059cbb",
"method": "0xa9059cbb",
"signature": "transfer(address,uint256)",
"args": [
"0x3dE712784baf97260455aE25fb74f574EC9c1add",
"16000000000000000000"
Expand All @@ -541,7 +546,7 @@
}
],
"decoded": {
"methodID": "0xbbd4f854",
"method": "0xbbd4f854",
"args": [
"0xe9efd3ab89acad6a3edf9828c3b00ed1c4a74e974d05d32d3b2fb15aa16fc377",
"0x0000000000000000000000000000000000000000000000000000000000000001",
Expand Down
Loading