-
Notifications
You must be signed in to change notification settings - Fork 16
fix: Safe WebAuthn owner matching, init-signature sorting, and estimation-path input handling #216
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fe290bc
fix: sort WebAuthn init signatures by the shared-signer address that …
sherifahmed990 962311d
fix: checksum WebAuthn verifier addresses and match owners case-insen…
sherifahmed990 e38ac94
fix: Safe estimation-path input handling — WebAuthn dummy pairs and m…
sherifahmed990 2979d98
docs: explain getSignerLowerCaseAddress derives owner addresses, not …
sherifahmed990 635ab78
fix: complete WebAuthn dummy-pair handling on both estimation call sites
sherifahmed990 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| // Regression tests: baseEstimateUserOperationGas must accept user-supplied | ||
| // dummySignerSignaturePairs containing raw WebauthnPublicKey signers — | ||
| // deriving isInit from the operation's own init fields — and must forward | ||
| // the WebAuthn verifier-config overrides so deployed accounts with custom | ||
| // verifier setups encode the correct owner address. Offline. | ||
|
|
||
| const ak = require('../../dist/index.cjs'); | ||
|
|
||
| const WEBAUTHN_KEY = { | ||
| x: 0x7a2fa39b3c61b3cbab8e44abeac8c9c7a4c1f76d42ae6f47b3b2a96d5c4f1a2bn, | ||
| y: 0x2e8c5f6d4b7a9c1e3f5a8d7b6c4e2f1a9d8c7b6a5e4f3d2c1b0a9f8e7d6c5b4an, | ||
| }; | ||
| const WEBAUTHN_SIG = '0x' + 'ab'.repeat(320); | ||
| const ACCOUNT = '0x' + '42'.repeat(20); | ||
| const CUSTOM_SIGNER_FACTORY = '0x' + '77'.repeat(20); | ||
|
|
||
| const GAS_RESULT = { | ||
| callGasLimit: '0x10000', | ||
| verificationGasLimit: '0x10000', | ||
| preVerificationGas: '0x10000', | ||
| }; | ||
|
|
||
| function estimateWithDummyPairs({ factory, overrides = {} }) { | ||
| const captured = []; | ||
| const bundler = new ak.Bundler({ | ||
| request: async ({ method, params }) => { | ||
| captured.push({ method, params }); | ||
| return GAS_RESULT; | ||
| }, | ||
| }); | ||
| const account = new ak.SafeAccountV0_3_0(ACCOUNT); | ||
| const userOperation = { | ||
| sender: ACCOUNT, | ||
| nonce: 0n, | ||
| factory, | ||
| factoryData: null, | ||
| callData: '0x', | ||
| callGasLimit: 0n, | ||
| verificationGasLimit: 0n, | ||
| preVerificationGas: 0n, | ||
| maxFeePerGas: 0n, | ||
| maxPriorityFeePerGas: 0n, | ||
| paymaster: null, | ||
| paymasterVerificationGasLimit: null, | ||
| paymasterPostOpGasLimit: null, | ||
| paymasterData: null, | ||
| signature: '0x', | ||
| }; | ||
| const estimation = account.baseEstimateUserOperationGas(userOperation, bundler, { | ||
| dummySignerSignaturePairs: [{ signer: WEBAUTHN_KEY, signature: WEBAUTHN_SIG }], | ||
| ...overrides, | ||
| }); | ||
| return { estimation, captured }; | ||
| } | ||
|
|
||
| // signature layout: 0x + validAfter (6 bytes) + validUntil (6 bytes) + static | ||
| // segments (65 bytes per signer: r = padded owner address, s = offset, v). | ||
| // The encoded owner address sits in bytes 12..32 of the first segment's r. | ||
| function encodedOwner(signature) { | ||
| return signature.slice(2 + 24).slice(24, 64); | ||
| } | ||
|
|
||
| describe('WebAuthn dummySignerSignaturePairs in baseEstimateUserOperationGas', () => { | ||
| test('init op: derives isInit from the factory field and encodes the shared signer', async () => { | ||
| const { estimation, captured } = estimateWithDummyPairs({ | ||
| factory: '0x' + '11'.repeat(20), | ||
| }); | ||
| await expect(estimation).resolves.toBeDefined(); | ||
| const sentOp = captured[0].params[0]; | ||
| expect(encodedOwner(sentOp.signature)).toBe( | ||
| ak.SafeAccountV0_3_0.DEFAULT_WEB_AUTHN_SHARED_SIGNER.slice(2).toLowerCase(), | ||
| ); | ||
| }); | ||
|
|
||
| test('deployed op: encodes the per-owner verifier-proxy address', async () => { | ||
| const { estimation, captured } = estimateWithDummyPairs({ factory: null }); | ||
| await expect(estimation).resolves.toBeDefined(); | ||
| const sentOp = captured[0].params[0]; | ||
| const verifierProxy = ak.SafeAccountV0_3_0.createWebAuthnSignerVerifierAddress( | ||
| WEBAUTHN_KEY.x, | ||
| WEBAUTHN_KEY.y, | ||
| ); | ||
| expect(encodedOwner(sentOp.signature)).toBe(verifierProxy.slice(2).toLowerCase()); | ||
| }); | ||
|
|
||
| test('deployed op: forwards custom verifier-config overrides to the encoder', async () => { | ||
| const { estimation, captured } = estimateWithDummyPairs({ | ||
| factory: null, | ||
| overrides: { webAuthnSignerFactory: CUSTOM_SIGNER_FACTORY }, | ||
| }); | ||
| await expect(estimation).resolves.toBeDefined(); | ||
| const sentOp = captured[0].params[0]; | ||
| const customVerifierProxy = ak.SafeAccountV0_3_0.createWebAuthnSignerVerifierAddress( | ||
| WEBAUTHN_KEY.x, | ||
| WEBAUTHN_KEY.y, | ||
| { webAuthnSignerFactory: CUSTOM_SIGNER_FACTORY }, | ||
| ); | ||
| const defaultVerifierProxy = ak.SafeAccountV0_3_0.createWebAuthnSignerVerifierAddress( | ||
| WEBAUTHN_KEY.x, | ||
| WEBAUTHN_KEY.y, | ||
| ); | ||
| expect(customVerifierProxy).not.toBe(defaultVerifierProxy); | ||
| expect(encodedOwner(sentOp.signature)).toBe(customVerifierProxy.slice(2).toLowerCase()); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Regression test: during account init the encoded owner for a WebAuthn | ||
| // signer is the shared signer, so sorting must use the shared-signer | ||
| // address too — not the per-owner verifier-proxy address. Offline. | ||
|
|
||
| const ak = require('../../dist/index.cjs'); | ||
|
|
||
| const WEBAUTHN_KEY = { | ||
| x: 0x7a2fa39b3c61b3cbab8e44abeac8c9c7a4c1f76d42ae6f47b3b2a96d5c4f1a2bn, | ||
| y: 0x2e8c5f6d4b7a9c1e3f5a8d7b6c4e2f1a9d8c7b6a5e4f3d2c1b0a9f8e7d6c5b4an, | ||
| }; | ||
|
|
||
| const SHARED_SIGNER = ak.SafeAccountV0_3_0.DEFAULT_WEB_AUTHN_SHARED_SIGNER; | ||
| // one below the shared signer, so: verifierProxy < EOA < sharedSigner | ||
| const EOA = '0x' + (BigInt(SHARED_SIGNER) - 1n).toString(16).padStart(40, '0'); | ||
|
|
||
| const WEBAUTHN_SIG = '0x' + 'ab'.repeat(320); | ||
| const EOA_SIG = '0x' + '22'.repeat(32) + '33'.repeat(32) + '1c'; | ||
|
|
||
| describe('WebAuthn init signature sorting', () => { | ||
| const verifierProxy = ak.SafeAccountV0_3_0.createWebAuthnSignerVerifierAddress( | ||
| WEBAUTHN_KEY.x, | ||
| WEBAUTHN_KEY.y, | ||
| ); | ||
|
|
||
| test('fixture precondition: verifierProxy < EOA < sharedSigner', () => { | ||
| expect(verifierProxy.toLowerCase() < EOA.toLowerCase()).toBe(true); | ||
| expect(EOA.toLowerCase() < SHARED_SIGNER.toLowerCase()).toBe(true); | ||
| }); | ||
|
|
||
| test('isInit: true sorts by the shared-signer address that gets encoded', () => { | ||
| const sig = ak.SafeAccountV0_3_0.buildSignaturesFromSingerSignaturePairs( | ||
| [ | ||
| { signer: WEBAUTHN_KEY, signature: WEBAUTHN_SIG }, | ||
| { signer: EOA, signature: EOA_SIG }, | ||
| ], | ||
| { isInit: true }, | ||
| ); | ||
| const seg1 = sig.slice(2, 132); | ||
| const seg2 = sig.slice(132, 262); | ||
| // EOA (lower address) must come first: its segment ends with v=0x1c | ||
| expect(seg1.endsWith('1c')).toBe(true); | ||
| // contract-signature segment second: owner = shared signer, v=0 | ||
| expect(seg2.slice(24, 64)).toBe(SHARED_SIGNER.slice(2).toLowerCase()); | ||
| expect(seg2.slice(128, 130)).toBe('00'); | ||
| }); | ||
|
|
||
| test('isInit: false still sorts by the verifier-proxy address', () => { | ||
| const sig = ak.SafeAccountV0_3_0.buildSignaturesFromSingerSignaturePairs( | ||
| [ | ||
| { signer: EOA, signature: EOA_SIG }, | ||
| { signer: WEBAUTHN_KEY, signature: WEBAUTHN_SIG }, | ||
| ], | ||
| { isInit: false }, | ||
| ); | ||
| const seg1 = sig.slice(2, 132); | ||
| // verifier proxy (lower address) comes first as the contract signature | ||
| expect(seg1.slice(24, 64)).toBe(verifierProxy.slice(2).toLowerCase()); | ||
| expect(seg1.slice(128, 130)).toBe('00'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For isInit: false, it also needs the verifier, factory, singleton, and proxy creation code values. Without them, it derives the owner using defaults rather than the caller’s custom configuration
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.
done