-
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 7203d4e
Showing
7 changed files
with
100 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_snapshot((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes)) (runs: 256, μ: 409655, ~: 410110) |
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 test_snapshot; 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,59 @@ | ||
// 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_snapshot(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 { | ||
address sender; | ||
uint256 nonce; | ||
bytes initCode; | ||
bytes callData; | ||
uint256 callGasLimit; | ||
uint256 verificationGasLimit; | ||
uint256 preVerificationGas; | ||
uint256 maxFeePerGas; | ||
uint256 maxPriorityFeePerGas; | ||
bytes paymasterAndData; | ||
bytes signature; | ||
} |