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

Clarify webauthn decoding from pr comments #102

Merged
merged 2 commits into from
Oct 2, 2023

Conversation

jzaki
Copy link
Contributor

@jzaki jzaki commented Sep 22, 2023

Comments from #85

Copy link
Contributor

@JohnGuilding JohnGuilding left a comment

Choose a reason for hiding this comment

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

Left some questions to clarify a few points :)

@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you have any thoughts on the question at the end of this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In that linked suggestion, it moves around how the variables are used throughout. That is:

  • i is always the index at the start of the data,
  • dataLen is always used as the length of data to read
  • paramLen is the length of the parameter

So assigning dataLen to be paramLen is hopefully helpful towards self-documenting code (and if redundant should be optimised out by the compiler anyway).
Using paramLen directly in the slice is different to how the slices are used everywhere else. So even though it would not error, it is less clear as a whole.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for clarifying, that makes sense to me and agree that seems more clear

Comment on lines +98 to +99
dataLen = paramLen - 32; // length already read
dataLen -= 2 * 2 * 32; // exclude fixed length arrays
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I'm understanding this change, can you explain what's going on here and how this leads to the same value as dataLen = 4 * 32;?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The param length is the length of all fixed bytes including the length parameter (you can add this up from the fixed params or print out to see the value).
The first line subtracts the already-read length, the next line subtract two arrays of length 2 containing 32bytes.

Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed in call, clarified changes and updated one of the comments

Copy link
Contributor

Choose a reason for hiding this comment

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

What did you think about this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was at a squeeze to get the vars to fit without stack overflow. Adding another call introduces additional var copies and stack usage. I didn't try it for that reason, I can try that as a new PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok makes sense, sounds good to me

@jzaki jzaki merged commit 96add0b into main Oct 2, 2023
2 checks passed
@jzaki jzaki deleted the wax-90-webauthn-decode-followup branch October 2, 2023 09:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants