Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
Clarify webauthn decoding from pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jzaki committed Sep 22, 2023
1 parent 78fed87 commit 0441f76
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions account-integrations/safe/src/SafeWebAuthnPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ contract SafeWebAuthnPlugin is BaseAccount {
return _publicKey;
}

struct LocalVarStruct {
// Struct declaration to hold multiple local vars.
// Prevents stack from getting too deep for evm.
struct LocalVarWrapper {
bytes1 authenticatorDataFlagMask;
bytes32 clientChallenge;
uint256 clientChallengeDataOffset;
Expand All @@ -81,9 +83,10 @@ contract SafeWebAuthnPlugin is BaseAccount {
bytes calldata clientData;
uint256[2] calldata signature;
uint256[2] calldata pubKey;
LocalVarStruct memory s;
LocalVarWrapper memory wrapper;

{
// scope to contain local variables that can be popped from the stack after use
{
// parse length of all fixed-length params (including length)
uint i = 0;
uint dataLen = 32;
Expand All @@ -92,12 +95,13 @@ contract SafeWebAuthnPlugin is BaseAccount {
i += dataLen; // advance index

// decode fixed length params (values to memory)
dataLen = 4 * 32; //lenFixedParams - 32; // -32 already read length
dataLen = paramLen - 32; // length already read
dataLen -= 2 * 2 * 32; // exclude fixed length arrays
(
s.authenticatorDataFlagMask,
wrapper.authenticatorDataFlagMask,
, // some number
s.clientChallenge,
s.clientChallengeDataOffset
wrapper.clientChallenge,
wrapper.clientChallengeDataOffset
) = abi.decode(
userOp.signature[i:i+dataLen],
(
Expand Down Expand Up @@ -130,8 +134,7 @@ contract SafeWebAuthnPlugin is BaseAccount {
paramLen = abi.decode(userOp.signature[i:i+dataLen], (uint256));
i += dataLen; // advance index
// assign authenticatorData to sig splice
dataLen = paramLen;//((paramLen >> 5) + 1) << 5; // (round up to next slot)

dataLen = paramLen;
authenticatorData = userOp.signature[i:i+dataLen];
i += ((dataLen >> 5) + 1) << 5; // advance index (round up to next slot)

Expand All @@ -140,17 +143,17 @@ contract SafeWebAuthnPlugin is BaseAccount {
paramLen = abi.decode(userOp.signature[i:i+dataLen], (uint256));
i += dataLen; // advance index
// assign clientData to sig splice
dataLen = paramLen;// ((paramLen >> 5) + 1) << 5; // (round up to next slot)
dataLen = paramLen;
clientData = userOp.signature[i:i+dataLen];
i += ((dataLen >> 5) + 1) << 5; // advance index (round up to next slot)
}
// i += ((dataLen >> 5) + 1) << 5; // advance index (round up to next slot)
} // end scope to free vars from stack

bool verified = FCL_WebAuthn.checkSignature(
authenticatorData,
s.authenticatorDataFlagMask,
wrapper.authenticatorDataFlagMask,
clientData,
s.clientChallenge,
s.clientChallengeDataOffset,
wrapper.clientChallenge,
wrapper.clientChallengeDataOffset,
signature,
pubKey
);
Expand Down

0 comments on commit 0441f76

Please sign in to comment.