-
Notifications
You must be signed in to change notification settings - Fork 82
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
Use assembly in WebAuthnVerifier for Base64 encoding #318
Conversation
eb111a4
to
118428f
Compare
Pull Request Test Coverage Report for Build 8452699560Details
💛 - Coveralls |
modules/4337/contracts/experimental/verifiers/WebAuthnVerifier.sol
Outdated
Show resolved
Hide resolved
modules/4337/contracts/experimental/verifiers/WebAuthnVerifier.sol
Outdated
Show resolved
Hide resolved
530dcb2
to
74ded1f
Compare
The code in question is notable missing unit tests. |
I think we should add unit tests for the functions to ensure that we have 100% coverage (for example, check that it does not validate a correctly signed signature if the authentication flags aren't correctly set). This should be different than general benchmarking. |
Already added here: https://github.com/safe-global/safe-modules/pull/301/files |
@@ -3,7 +3,6 @@ | |||
pragma solidity >=0.8.0; |
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 experimental
code will be removed, so I wouldn't update it here as well.
'{"type":"webauthn.get","challenge":"', | ||
encodedChallenge, | ||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", | ||
'",', |
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.
nit: this can be a single string instead of mutiple strings (not sure how it affects the generated assembly though).
modules/4337/contracts/experimental/verifiers/WebAuthnVerifier.sol
Outdated
Show resolved
Hide resolved
a52864e
to
d48bb04
Compare
d48bb04
to
2fbf4a3
Compare
For some reason, tests fail when run through the coverage command. When run normally, tests pass. I will investigate tomorrow. |
modules/passkey/src/types/solc.d.ts
Outdated
|
||
export function compile(input: string): string | ||
|
||
export function loadRemoteVersion(version: string, callback: (err: Error, solc: any) => void): void |
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.
nit:lints
modules/passkey/tsconfig.json
Outdated
@@ -8,5 +8,6 @@ | |||
"strict": true, | |||
"skipLibCheck": true, | |||
"resolveJsonModule": true | |||
} | |||
}, | |||
"include": ["src/**/*.ts", "hardhat.config.ts"] |
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.
Shouldn't tests be included as well?
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.
Have included it now
modules/passkey/src/types/solc.d.ts
Outdated
@@ -0,0 +1,41 @@ | |||
declare module 'solc' { | |||
export interface CompilerInput { |
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.
Fairly sure these types aren't used anywhere - and I think are inaccurate (in particular CompilerOutput
specifically depends on the outputSelection
of the input). I would remove them if they aren't used.
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.
They're used in the codesize task; without type declaration for solc
, the project won't compile. They might be inaccurate since I generated them using the perplexity AI tool - however, I believe they're still safer than just declaring everything as any, like here. I'll take one more look and fix the inaccuracies
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.
Ahh, now I see what you mean, you're right
ce81d03
to
0e87841
Compare
94cd100
to
95c51a1
Compare
95c51a1
to
1952444
Compare
LGTM |
Co-authored-by: Nicholas Rodrigues Lordello <[email protected]>
This PR implements #289
The algorithm is implemented as a library instead of the suggested in-place adjustment from the original issue. Akshay's original implementation was doing it in-place (which can still be found in the commit history). While it was efficient code size-wise, but gas-wise, it consumed more gas than FCL's implementation, probably due to some inefficient stack manipulations. I tested it with Solady's library then, and it turned out to be much more efficient even though it wasn't doing the encoding in place.
The implementation I'm proposing is based on Solady's efficient algorithm. It seems to me that it's not adjustable to in-place encoding due to the fact the algorithm takes advantage of optimizing stack operations by writing X bytes to the scratch space and then writing them to the string at position Y+(I*N) (I=Iteration, Y=start, N=bytes written in an iteration) as a 32-byte word. Because it writes them as a 32-byte word, it’s not suitable for modifying a string in place because it will overwrite the existing string bytes with empty characters. (I'm happy if I'm wrong though)
Changes in PR:
codesize
taskBase64Url.sol
library with a Base64Url encoding algorithm that is optimized for encodingbytes32
data.Code size change
This PR:
WebAuthnSigner 2693 bytes (limit is 24576)
Default main branch:
WebAuthnSigner 2817 bytes (limit is 24576)
Gas Usage - Needs additional test for benchmarking
Solady:
FCL:
This PR:
This PR (viaIR):