-
Notifications
You must be signed in to change notification settings - Fork 167
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
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
How to use the Graphite Merge QueueAdd 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. |
🌿 Documentation Preview
|
typeof uo.preVerificationGas !== "bigint" && | ||
typeof uo.preVerificationGas !== "number") | ||
) { | ||
throw new Error( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When would this happen?
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
- In v2 webauthn, we probably want to remove all instances of short circuiting, so the values returned below would change
- 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 = |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
return { | ||
...uo, | ||
preVerificationGas: | ||
BigInt(typeof pvg === "string" ? hexToString(pvg) : pvg) + |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!"
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
There was a problem hiding this 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) + |
There was a problem hiding this comment.
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!"
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; |
There was a problem hiding this comment.
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")
Pull Request Checklist
yarn test
)site
folder, and guidelines for updating/adding docs can be found in the contribution guide)feat!: breaking change
)yarn lint:check
) and fix any issues? (yarn lint:write
)PR-Codex overview
This PR introduces a new
webauthnGasEstimator
function in thewebauthnGasEstimator.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
rip7212CheckBytecode
constant for ERC-7212 check.webauthnGasEstimator
function as a middleware.preVerificationGas
and adjusts it based on ERC-7212 presence.