Skip to content

feat: add webauthn gas estimator #1573

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

howydev
Copy link
Collaborator

@howydev howydev commented Apr 29, 2025

Pull Request Checklist


PR-Codex overview

This PR introduces a new webauthnGasEstimator function in the webauthnGasEstimator.ts file, which calculates gas estimates for transactions while ensuring compatibility with a specific EntryPoint version and checking for the presence of ERC-7212 on the chain.

Detailed summary

  • Added rip7212CheckBytecode constant for ERC-7212 check.
  • Implemented webauthnGasEstimator function as a middleware.
  • Validates the existence of an account and checks EntryPoint version.
  • Computes preVerificationGas and adjusts it based on ERC-7212 presence.
  • Throws errors for missing account or incompatible EntryPoint version.

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

Copy link

vercel bot commented Apr 29, 2025

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

Name Status Preview Comments Updated (UTC)
aa-sdk-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 1, 2025 9:14pm
aa-sdk-ui-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 1, 2025 9:14pm

Copy link

graphite-app bot commented Apr 29, 2025

How to use the Graphite Merge Queue

Add the label graphite-merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

Copy link

github-actions bot commented Apr 29, 2025

🌿 Documentation Preview

Name Status Preview Updated (UTC)
Alchemy Docs ✅ Ready 🔗 Visit Preview May 1, 2025, 9:10 PM

typeof uo.preVerificationGas !== "bigint" &&
typeof uo.preVerificationGas !== "number")
) {
throw new Error(
Copy link
Collaborator

Choose a reason for hiding this comment

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

When would this happen?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not sure but will type narrow this instead


const entryPoint = account.getEntryPoint();
if (entryPoint.version !== "0.7.0") {
throw new Error(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why's this? Couldn't someone use this with any passkey account?

Copy link
Collaborator Author

@howydev howydev Apr 30, 2025

Choose a reason for hiding this comment

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

It could, but the webauthn validation implementation can be different so i recommend we version lock the integrations. For instance:

  1. In v2 webauthn, we probably want to remove all instances of short circuiting, so the values returned below would change
  2. Another possible design is what ithaca is doing - an on-chain check for rip7212 during uo validation, in that mode we wouldn't need the gas estimator


export const webauthnGasEstimator: (
gasEstimator?: ClientMiddlewareFn
) => ClientMiddlewareFn =
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TODO: is it possible to get the size of authenticatorDatas and clientDataJSONs here? if so, we might be able to get a tighter bound on modifications to gas estimation

);
}

const uo = await gasEstimator_(struct, params);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note: we still want to run the underlying gas estimator and modify that value instead of hardcoding PVG because the account/entity could have pre-validation hooks

@github-actions github-actions bot temporarily deployed to docs-preview May 1, 2025 21:08 Inactive
return {
...uo,
preVerificationGas:
BigInt(typeof pvg === "string" ? hexToString(pvg) : pvg) +
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the only possible string type here for pvg is 0x${string} so this works

Copy link
Contributor

@dphilipson dphilipson May 6, 2025

Choose a reason for hiding this comment

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

Are you sure hexToString is what you want? That's for converting UTF-8 bytes into human-readable, e.g.

hexToString("0x48656c6c6f20576f726c6421") === "Hello world!"

Viem docs

If you're trying to convert a hex string representing a number into a bigint, you can just pass it to BigInt directly, e.g.

BigInt("0x10") === 16n

Copy link
Contributor

@dphilipson dphilipson left a comment

Choose a reason for hiding this comment

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

Looks good, had a question about one part.

return {
...uo,
preVerificationGas:
BigInt(typeof pvg === "string" ? hexToString(pvg) : pvg) +
Copy link
Contributor

@dphilipson dphilipson May 6, 2025

Choose a reason for hiding this comment

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

Are you sure hexToString is what you want? That's for converting UTF-8 bytes into human-readable, e.g.

hexToString("0x48656c6c6f20576f726c6421") === "Hello world!"

Viem docs

If you're trying to convert a hex string representing a number into a bigint, you can just pass it to BigInt directly, e.g.

BigInt("0x10") === 16n

// perform eth call read check to see if the chain has 7212
const { data } = await params.client.call({ data: rip7212CheckBytecode });

const chainHas7212: boolean = data ? BigInt(data) === 1n : false;
Copy link
Contributor

@dphilipson dphilipson May 6, 2025

Choose a reason for hiding this comment

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

This is fine, but seeing false in a branch of conditional feels weird to me. I might write this as !!data && BigInt(data) === 1n or data != null && BigInt(data) === 1n. (The !! is an idiom for "cast to boolean")

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.

3 participants