Skip to content

Commit

Permalink
🎉 mise en place
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzdanilo committed May 17, 2024
0 parents commit 761c7f6
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gas-snapshot
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)
15 changes: 15 additions & 0 deletions .github/workflows/test.yaml
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
13 changes: 13 additions & 0 deletions .gitignore
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
3 changes: 3 additions & 0 deletions .gitmodules
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
8 changes: 8 additions & 0 deletions foundry.toml
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"
1 change: 1 addition & 0 deletions lib/webauthn-sol
Submodule webauthn-sol added at 619f20
53 changes: 53 additions & 0 deletions test/Snapshot.t.sol
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;
}

0 comments on commit 761c7f6

Please sign in to comment.