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

feat: signature from ABI item #255

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SebastienGllmt
Copy link

@SebastienGllmt SebastienGllmt commented Oct 24, 2024

Goal

Solidity allows overloading functions & events - that is to say, you can for example have multiple events with the same name. To avoid this being an issue, Solidity converts ABI entries to a signature which is then used to generate a "selector" (a part of the hash of the signature)

Generating this signature with a static type is important for downstream libraries like viem because the current lack of this feature means viem can't differentiate between events/functions with the same name leading to subtle bugs and bypassing this limitation requires dropping type safety in viem.

Open questions

  1. I added the code to generate the signature from an ABI entry, but I didn't create the inverse (a parse). This is because signatures are lossy so you can't really compute the inverse anyway (but maybe somebody would benefit from even a partial inverse)
  2. I added this to the human-readable folder since it felt like the closest place to add it, but this code doesn't fit particularly well in any of the existing folders I feel. Open to thoughts on this

Test

 ✓ src/human-readable/signatureAbiItem.bench.ts (6) 5781ms

   ✓ Generate Function ABI signature (3) 2856ms
     · abitype   3,859,297.54 ops/sec ±1.31% (1929649 samples) fastest
     · ethers@6     47,912.60 ops/sec ±0.61% (  23957 samples) slowest
     · ethers@5    136,142.23 ops/sec ±0.69% (  68072 samples)

   ✓ Generate Event ABI signature (3) 2923ms
     · abitype   3,849,295.03 ops/sec ±1.51% (1924648 samples) fastest
     · ethers@6     77,291.49 ops/sec ±0.75% (  38646 samples) slowest
     · ethers@5    208,198.71 ops/sec ±0.80% ( 104100 samples)

Test

✓ src/signature/signatureAbiItem.test.ts (10)
   ✓ signatureAbiItem: function
   ✓ signatureAbiItem: function
   ✓ signatureAbiItem: function
   ✓ signatureAbiItem: function
   ✓ signatureAbiItem: function
   ✓ signatureAbiItem: event
   ✓ signatureAbiItem: event
   ✓ signatureAbiItem: event
   ✓ signatureAbiItem: event
   ✓ signatureAbiItem: event

Type test

✓ src/signature/signatureAbiItem.test-d.ts (2)
   ✓ SelectorAbiItem: function
   ✓ SelectorAbiItem: event

PR-Codex overview

This PR focuses on enhancing the abitype package by introducing the signatureAbiItem function for generating ABI signatures, improving type safety, and adding related tests and benchmarks.

Detailed summary

  • Added signatureAbiItem function to format ABI items into signatures.
  • Exported UnknownTypeError, InvalidAbiItemError, and signatureAbiItem.
  • Updated tupleRegex to be exported.
  • Enhanced documentation for signatureAbiItem.
  • Added tests for signatureAbiItem functionality.
  • Implemented benchmarks comparing abitype with ethers library.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

changeset-bot bot commented Oct 24, 2024

🦋 Changeset detected

Latest commit: bd8c51e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
abitype Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Oct 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
abitype ❌ Failed (Inspect) Oct 25, 2024 5:37am

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.

1 participant