-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Verify Multiple P-256 Verifiers Are Supported (#307)
Partially addresses #285 This PR adds new tests that verify multiple P-256 verifiers are supported by our code. The `webauthn` shim code now moved to the `passkey` package and is imported by the `4337` package, as this made more sense to me. @mmv08 moved E2E tests for Passkey+4337 to the `passkey` project, so once they both merge, the dependency can be removed. Note that for now, we use a `TestWebAuthnSignerFactor` contract just for implementing the tests, but it should be switched to using the canonical signing factory from #306 once merged. The additional verifier that is being used is the one from [Daimo-eth](https://github.com/daimo-eth/p256-verifier). The artifact was vendored into the project, as it is a Foundry project, and this is the easiest way to include the dependency without building it (giving us identical bytecode to what is deployed on-chain). Adding a test for using the precompile will be done in a separate PR. --- Note that this PR contains some unrelated changes to the deployment and E2E setup. This was a result of rebasing onto changes introduced in #306 to get things working as well as some nits leftover from the aforementioned PR.
- Loading branch information
Showing
21 changed files
with
325 additions
and
116 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module.exports = { | ||
root: true, | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
|
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
This file was deleted.
Oops, something went wrong.
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 @@ | ||
coverage/ | ||
dist/ | ||
typechain-types/ |
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
86 changes: 86 additions & 0 deletions
86
modules/passkey/contracts/test/TestWebAuthnSignerFactory.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,86 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
/* solhint-disable one-contract-per-file */ | ||
pragma solidity ^0.8.0; | ||
|
||
import {IP256Verifier, P256VerifierLib} from "../verifiers/IP256Verifier.sol"; | ||
|
||
contract TestWebAuthnSignerFactory { | ||
function createSigner(address verifier, uint256 x, uint256 y) external returns (TestWebAuthnSigner signer) { | ||
signer = new TestWebAuthnSigner{salt: 0}(verifier, x, y); | ||
} | ||
} | ||
|
||
contract TestWebAuthnSigner { | ||
using P256VerifierLib for IP256Verifier; | ||
|
||
struct SignatureData { | ||
bytes authenticatorData; | ||
bytes clientDataFields; | ||
uint256 r; | ||
uint256 s; | ||
} | ||
|
||
string private constant _BASE64URL = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; | ||
|
||
address private immutable _VERIFIER; | ||
uint256 private immutable _X; | ||
uint256 private immutable _Y; | ||
|
||
constructor(address verifier, uint256 x, uint256 y) { | ||
_VERIFIER = verifier; | ||
_X = x; | ||
_Y = y; | ||
} | ||
|
||
function isValidSignature(bytes32 hash, bytes calldata signature) external view returns (bytes4 magicValue) { | ||
SignatureData calldata sig; | ||
// solhint-disable-next-line no-inline-assembly | ||
assembly ("memory-safe") { | ||
sig := signature.offset | ||
} | ||
|
||
if ( | ||
IP256Verifier(_VERIFIER).verifySignatureAllowMalleability( | ||
_signingMessage(hash, sig.authenticatorData, sig.clientDataFields), | ||
sig.r, | ||
sig.s, | ||
_X, | ||
_Y | ||
) | ||
) { | ||
magicValue = this.isValidSignature.selector; | ||
} | ||
} | ||
|
||
function _signingMessage( | ||
bytes32 challenge, | ||
bytes calldata authenticatorData, | ||
bytes calldata clientDataFields | ||
) internal pure returns (bytes32 message) { | ||
/* solhint-disable quotes */ | ||
bytes memory clientDataJson = abi.encodePacked( | ||
'{"type":"webauthn.get","challenge":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",', | ||
clientDataFields, | ||
"}" | ||
); | ||
/* solhint-enable quotes */ | ||
|
||
string memory alphabet = _BASE64URL; | ||
// solhint-disable-next-line no-inline-assembly | ||
assembly ("memory-safe") { | ||
let lut := add(alphabet, 1) | ||
let ptr := add(clientDataJson, 68) | ||
|
||
for { | ||
let i := 0 | ||
} lt(i, 42) { | ||
i := add(i, 1) | ||
} { | ||
mstore8(add(ptr, i), mload(add(lut, and(0x3f, shr(sub(250, mul(6, i)), challenge))))) | ||
} | ||
mstore8(add(ptr, 42), mload(add(lut, and(0x3f, shl(2, challenge))))) | ||
} | ||
|
||
message = sha256(abi.encodePacked(authenticatorData, sha256(clientDataJson))); | ||
} | ||
} |
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
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
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,25 +1,19 @@ | ||
import { DeployFunction } from 'hardhat-deploy/types' | ||
import { LAUNCHPAD_DEPLOYMENT_ENTRY_POINT_ADDRESS } from '../constants' | ||
|
||
const deploy: DeployFunction = async ({ deployments, getNamedAccounts, network }) => { | ||
if (!network.tags.dev && !network.tags.test) { | ||
return | ||
} | ||
|
||
const deploy: DeployFunction = async ({ deployments, getNamedAccounts }) => { | ||
const { deployer } = await getNamedAccounts() | ||
const { deploy } = deployments | ||
|
||
const entryPoint = (await deployments.getOrNull('EntryPoint').then((d) => d?.address)) || LAUNCHPAD_DEPLOYMENT_ENTRY_POINT_ADDRESS | ||
if (!entryPoint) { | ||
throw new Error('Entry point contract should be deployed or set in LAUNCHPAD_DEPLOYMENT_ENTRY_POINT_ADDRESS') | ||
} | ||
const entryPoint = await deployments.get('EntryPoint') | ||
|
||
await deploy('Safe256BitECSignerLaunchpad', { | ||
from: deployer, | ||
args: [entryPoint], | ||
args: [entryPoint.address], | ||
log: true, | ||
deterministicDeployment: true, | ||
}) | ||
} | ||
|
||
deploy.dependencies = ['entrypoint'] | ||
|
||
export default deploy |
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
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
Oops, something went wrong.