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

fix(json-abi): properly handle Param type field #233

Merged
merged 3 commits into from
Aug 23, 2023
Merged

Conversation

DaniPopes
Copy link
Member

@DaniPopes DaniPopes commented Aug 20, 2023

Motivation

type is either:

  • "tuple" + [] array brackets if components is not empty
  • a canonical Solidity type if components is empty

Check this during deserialization and signature formatting.

Added benchmark for signature formatting:

signature/large-function/alloy                                                                            
                        time:   [217.91 ns 218.47 ns 219.13 ns]
signature/large-function/ethabi                                                                             
                        time:   [2.6704 µs 2.6737 µs 2.6768 µs]

Solution

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@@ -184,6 +180,12 @@ impl Param {
s.push_str(&self.ty)
} else {
crate::utils::signature_raw("", &self.components, s);
// checked during deserialization, but might be invalid from a user
Copy link
Member

Choose a reason for hiding this comment

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

could we check this on type-instantiation so it's impossible for a user to construct an invalid one?

Copy link
Member Author

Choose a reason for hiding this comment

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

How? All struct fields are public

Copy link
Member

Choose a reason for hiding this comment

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

if public fields allow the user to create invalid instances, then we should at least consider making them non-public

@DaniPopes DaniPopes merged commit 406c07b into main Aug 23, 2023
18 checks passed
@DaniPopes DaniPopes deleted the dani/fix-json-types branch August 23, 2023 21:11
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.

2 participants