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

accounts/abi: handle ABIs with contract type parameter #30315

Merged
merged 3 commits into from
Aug 20, 2024

Conversation

chen4903
Copy link
Contributor

A PR to fix: #30266
The ABI pulled from Etherscan sometimes does not conform to the specifications, so before formally processing the ABI, we validate whether the input ABI meets the standards.

@MariusVanDerWijden
Copy link
Member

What do you think about this:

diff --git a/accounts/abi/type.go b/accounts/abi/type.go
index d57fa3d4e6..1f0119e36c 100644
--- a/accounts/abi/type.go
+++ b/accounts/abi/type.go
@@ -219,7 +219,15 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
                typ.T = FunctionTy
                typ.Size = 24
        default:
-               return Type{}, fmt.Errorf("unsupported arg type: %s", t)
+               // Filter out these edgecases
+               // {"internalType":"contract INameService","name":"nameService","type":"INameService"},
+               // where solidity replaces an address type with its (undefined) name.
+               if strings.Contains(internalType, "contract") {
+                       typ.Size = 20
+                       typ.T = AddressTy
+               } else {
+                       return Type{}, fmt.Errorf("unsupported arg type: %s", t)
+               }

@chen4903
Copy link
Contributor Author

What do you think about this:

diff --git a/accounts/abi/type.go b/accounts/abi/type.go
index d57fa3d4e6..1f0119e36c 100644
--- a/accounts/abi/type.go
+++ b/accounts/abi/type.go
@@ -219,7 +219,15 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
                typ.T = FunctionTy
                typ.Size = 24
        default:
-               return Type{}, fmt.Errorf("unsupported arg type: %s", t)
+               // Filter out these edgecases
+               // {"internalType":"contract INameService","name":"nameService","type":"INameService"},
+               // where solidity replaces an address type with its (undefined) name.
+               if strings.Contains(internalType, "contract") {
+                       typ.Size = 20
+                       typ.T = AddressTy
+               } else {
+                       return Type{}, fmt.Errorf("unsupported arg type: %s", t)
+               }

Yeah, this way is more concise and efficient.

accounts/abi/type.go Outdated Show resolved Hide resolved
Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@holiman holiman added this to the 1.14.9 milestone Aug 19, 2024
@holiman holiman changed the title Preprocess non-compliant ABIs accounts/abi: handle ABIs with contract type parameter Aug 20, 2024
@holiman holiman merged commit 65aaf52 into ethereum:master Aug 20, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

abi.JSON ERROR:unsupported arg type: INameService
3 participants