-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b3d05a1
Showing
7 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
SnapshotTest:test((bytes,bytes,uint256,uint256,uint256)) (runs: 256, μ: 407727, ~: 408263) |
This file contains 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,15 @@ | ||
name: test | ||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
workflow_dispatch: | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
- uses: foundry-rs/foundry-toolchain@v1 | ||
- run: for i in {1..16}; do forge snapshot --force | grep runs; done |
This file contains 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,13 @@ | ||
# foundry | ||
cache/ | ||
out/ | ||
!/broadcast | ||
/broadcast/*/31337/ | ||
/broadcast/**/dry-run/ | ||
/broadcast/**/run-latest.json | ||
docs/ | ||
|
||
.env | ||
.vscode/ | ||
.DS_Store | ||
*.log |
This file contains 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,3 @@ | ||
[submodule "lib/webauthn-sol"] | ||
path = lib/webauthn-sol | ||
url = https://github.com/base-org/webauthn-sol |
This file contains 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,8 @@ | ||
[profile.default] | ||
isolate = true | ||
|
||
[fmt] | ||
tab_width = 2 | ||
sort_imports = true | ||
bracket_spacing = true | ||
number_underscore = "thousands" |
Submodule webauthn-sol
added at
619f20
This file contains 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,53 @@ | ||
// SPDX-License-Identifier: AGPL-3.0 | ||
pragma solidity ^0.8.0; | ||
|
||
import { Test } from "forge-std/Test.sol"; | ||
|
||
import { Utils, WebAuthnInfo } from "webauthn-sol/../test/Utils.sol"; | ||
import { WebAuthn } from "webauthn-sol/WebAuthn.sol"; | ||
|
||
contract SnapshotTest is Test { | ||
using Utils for uint256; | ||
using Utils for bytes32; | ||
|
||
uint256 internal constant PRIVATE_KEY = uint256(0x03d99692017473e2d631945a812607b23269d85721e0f370b8d3e7d29a874fd2); | ||
PublicKey public PUBLIC_KEY = abi.decode( | ||
hex"1c05286fe694493eae33312f2d2e0d0abeda8db76238b7a204be1fb87f54ce4228fef61ef4ac300f631657635c28e59bfb2fe71bce1634c81c65642042f6dc4d", | ||
(PublicKey) | ||
); | ||
|
||
function test(UserOperation calldata userOp) external { | ||
bytes32 userOpHash = keccak256(abi.encode(userOp)); | ||
WebAuthnInfo memory webauthn = userOpHash.getWebAuthnStruct(); | ||
(bytes32 r, bytes32 s) = vm.signP256(PRIVATE_KEY, webauthn.messageHash); | ||
assertTrue( | ||
WebAuthn.verify({ | ||
challenge: abi.encode(userOpHash), | ||
requireUV: false, | ||
webAuthnAuth: WebAuthn.WebAuthnAuth({ | ||
authenticatorData: webauthn.authenticatorData, | ||
clientDataJSON: webauthn.clientDataJSON, | ||
typeIndex: 1, | ||
challengeIndex: 23, | ||
r: uint256(r), | ||
s: uint256(s).normalizeS() | ||
}), | ||
x: PUBLIC_KEY.x, | ||
y: PUBLIC_KEY.y | ||
}) | ||
); | ||
} | ||
} | ||
|
||
struct PublicKey { | ||
uint256 x; | ||
uint256 y; | ||
} | ||
|
||
struct UserOperation { | ||
bytes field0; | ||
bytes field1; | ||
uint256 field2; | ||
uint256 field3; | ||
uint256 field4; | ||
} |