Skip to content

Commit

Permalink
[#312] Remove replace SafeWebAuthnSigner.sol with SafeWebAuthnSignerP…
Browse files Browse the repository at this point in the history
…roxy.sol, same for factory
  • Loading branch information
akshay-ap committed Apr 11, 2024
1 parent 03dc99d commit 3c4fd03
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 231 deletions.
37 changes: 0 additions & 37 deletions modules/passkey/contracts/SafeWebAuthnSigner.sol

This file was deleted.

63 changes: 0 additions & 63 deletions modules/passkey/contracts/SafeWebAuthnSignerFactory.sol

This file was deleted.

2 changes: 1 addition & 1 deletion modules/passkey/contracts/SafeWebAuthnSignerProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {IP256Verifier} from "./interfaces/IP256Verifier.sol";

/**
* @title SafeWebAuthnSignerProxy
* @dev A proxy contract that points to SafeWebAuthnSigner.
* @dev A proxy contract that points to SafeWebAuthnSigner singleton.
*/
contract SafeWebAuthnSignerProxy {
uint256 internal immutable X;
Expand Down
25 changes: 20 additions & 5 deletions modules/passkey/contracts/SafeWebAuthnSignerProxyFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
pragma solidity >=0.8.0;

import {ICustomECDSASignerFactory} from "./interfaces/ICustomECDSASignerFactory.sol";
import {IP256Verifier} from "./interfaces/IP256Verifier.sol";
import {ERC1271} from "./libraries/ERC1271.sol";
import {WebAuthn} from "./libraries/WebAuthn.sol";
import {SafeWebAuthnSignerProxy} from "./SafeWebAuthnSignerProxy.sol";
import {SafeWebAuthnSignerSingleton} from "./SafeWebAuthnSignerSingleton.sol";
/**
* @title SafeWebAuthnSignerProxyFactory
* @dev A factory contract for creating and managing WebAuthn proxy signers.
Expand Down Expand Up @@ -49,8 +47,25 @@ contract SafeWebAuthnSignerProxyFactory is ICustomECDSASignerFactory {
uint256 y,
address verifier
) external view override returns (bytes4 magicValue) {
if (WebAuthn.verifySignature(message, signature, WebAuthn.USER_VERIFICATION, x, y, IP256Verifier(verifier))) {
magicValue = ERC1271.MAGIC_VALUE;
address _singleton = SINGLETON;
bytes memory data = abi.encodePacked(
abi.encodeWithSignature("isValidSignature(bytes32,bytes)", message, signature),
x,
y,
verifier
);

// solhint-disable-next-line no-inline-assembly
assembly {
let dataSize := mload(data)
let dataLocation := add(data, 0x20)

let success := staticcall(gas(), _singleton, dataLocation, dataSize, 0, 0)
returndatacopy(magicValue, 0, returndatasize())
if iszero(success) {
// TODO
}
return(0, returndatasize())
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/passkey/contracts/SafeWebAuthnSignerSingleton.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract SafeWebAuthnSignerSingleton is SignatureValidatorProxy {
uint256 x,
uint256 y,
address verifier
) public view virtual override returns (bool success) {
) internal view virtual override returns (bool success) {
success = WebAuthn.verifySignature(message, signature, WebAuthn.USER_VERIFICATION, x, y, IP256Verifier(verifier));
}
}
2 changes: 1 addition & 1 deletion modules/passkey/contracts/base/SignatureValidatorProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ abstract contract SignatureValidatorProxy {
uint256 x,
uint256 y,
address verifier
) public view virtual returns (bool success);
) internal view virtual returns (bool success);
}
16 changes: 1 addition & 15 deletions modules/passkey/src/deploy/webauthn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,9 @@ const deploy: DeployFunction = async ({ deployments, getNamedAccounts }) => {
const { deployer } = await getNamedAccounts()
const { deploy } = deployments

await deploy('SafeWebAuthnSignerFactory', {
from: deployer,
args: [],
log: true,
deterministicDeployment: true,
})

const singletonDeployment = await deploy('SafeWebAuthnSignerSingleton', {
from: deployer,
args: [],
log: true,
deterministicDeployment: true,
})

await deploy('SafeWebAuthnSignerProxyFactory', {
from: deployer,
args: [singletonDeployment.address],
args: [],
log: true,
deterministicDeployment: true,
})
Expand Down
6 changes: 3 additions & 3 deletions modules/passkey/test/4337/WebAuthn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Safe4337Module - WebAuthn Owner', () => {
Safe4337Module,
SafeECDSASignerLaunchpad,
EntryPoint,
SafeWebAuthnSignerFactory,
SafeWebAuthnSignerProxyFactory,
} = await deployments.fixture()

const [user] = await ethers.getSigners()
Expand All @@ -32,7 +32,7 @@ describe('Safe4337Module - WebAuthn Owner', () => {
const signerLaunchpad = await ethers.getContractAt('SafeECDSASignerLaunchpad', SafeECDSASignerLaunchpad.address)
const singleton = await ethers.getContractAt(SafeL2.abi, SafeL2.address)
const verifier = await ethers.getContractAt('IP256Verifier', FCLP256Verifier.address)
const signerFactory = await ethers.getContractAt('SafeWebAuthnSignerFactory', SafeWebAuthnSignerFactory.address)
const signerFactory = await ethers.getContractAt('SafeWebAuthnSignerProxyFactory', SafeWebAuthnSignerProxyFactory.address)

const navigator = {
credentials: new WebAuthnCredentials(),
Expand Down Expand Up @@ -228,7 +228,7 @@ describe('Safe4337Module - WebAuthn Owner', () => {
const publicKey = decodePublicKey(credential.response)
await signerFactory.createSigner(publicKey.x, publicKey.y, verifierAddress)
const signer = await ethers.getContractAt(
'SafeWebAuthnSigner',
'SafeWebAuthnSignerProxy',
await signerFactory.getSigner(publicKey.x, publicKey.y, verifierAddress),
)

Expand Down
4 changes: 2 additions & 2 deletions modules/passkey/test/4337/WebAuthnSigner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('WebAuthn Signers [@4337]', () => {
SafeModuleSetup,
SafeL2,
FCLP256Verifier,
SafeWebAuthnSignerFactory,
SafeWebAuthnSignerProxyFactory,
} = await deployments.run()
const [user] = await prepareAccounts()
const bundler = bundlerRpc()
Expand All @@ -32,7 +32,7 @@ describe('WebAuthn Signers [@4337]', () => {
const signerLaunchpad = await ethers.getContractAt('SafeECDSASignerLaunchpad', SafeECDSASignerLaunchpad.address)
const singleton = await ethers.getContractAt(SafeL2.abi, SafeL2.address)
const verifier = await ethers.getContractAt('IP256Verifier', FCLP256Verifier.address)
const signerFactory = await ethers.getContractAt('SafeWebAuthnSignerFactory', SafeWebAuthnSignerFactory.address)
const signerFactory = await ethers.getContractAt('SafeWebAuthnSignerProxyFactory', SafeWebAuthnSignerProxyFactory.address)

const navigator = {
credentials: new WebAuthnCredentials(),
Expand Down
94 changes: 0 additions & 94 deletions modules/passkey/test/GasBenchmarking.spec.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { buildSignatureBytes } from '@safe-global/safe-4337/src/utils/execution'
describe('Create a Safe with Passkey signer as owner: [@userstory]', () => {
// Create a fixture to setup the contracts and signer(s)
const setupTests = deployments.createFixture(async ({ deployments }) => {
const { EntryPoint, Safe4337Module, SafeProxyFactory, SafeModuleSetup, SafeL2, FCLP256Verifier, SafeWebAuthnSignerFactory } =
const { EntryPoint, Safe4337Module, SafeProxyFactory, SafeModuleSetup, SafeL2, FCLP256Verifier, SafeWebAuthnSignerProxyFactory } =
await deployments.run()

const [user] = await ethers.getSigners()
Expand All @@ -28,7 +28,7 @@ describe('Create a Safe with Passkey signer as owner: [@userstory]', () => {
const safeModuleSetup = await ethers.getContractAt(SafeModuleSetup.abi, SafeModuleSetup.address)
const singleton = await ethers.getContractAt(SafeL2.abi, SafeL2.address)
const verifier = await ethers.getContractAt('IP256Verifier', FCLP256Verifier.address)
const signerFactory = await ethers.getContractAt('SafeWebAuthnSignerFactory', SafeWebAuthnSignerFactory.address)
const signerFactory = await ethers.getContractAt('SafeWebAuthnSignerProxyFactory', SafeWebAuthnSignerProxyFactory.address)

const navigator = {
credentials: new WebAuthnCredentials(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { buildSignatureBytes } from '@safe-global/safe-4337/src/utils/execution'
*/
describe('Execute userOp from Passkey signer [@userstory]', () => {
const setupTests = deployments.createFixture(async ({ deployments }) => {
const { EntryPoint, Safe4337Module, SafeProxyFactory, SafeModuleSetup, SafeL2, FCLP256Verifier, SafeWebAuthnSignerFactory } =
const { EntryPoint, Safe4337Module, SafeProxyFactory, SafeModuleSetup, SafeL2, FCLP256Verifier, SafeWebAuthnSignerProxyFactory } =
await deployments.run()

const [relayer] = await ethers.getSigners()
Expand All @@ -27,7 +27,7 @@ describe('Execute userOp from Passkey signer [@userstory]', () => {
const safeModuleSetup = await ethers.getContractAt(SafeModuleSetup.abi, SafeModuleSetup.address)
const singleton = await ethers.getContractAt(SafeL2.abi, SafeL2.address)
const verifier = await ethers.getContractAt('IP256Verifier', FCLP256Verifier.address)
const signerFactory = await ethers.getContractAt('SafeWebAuthnSignerFactory', SafeWebAuthnSignerFactory.address)
const signerFactory = await ethers.getContractAt('SafeWebAuthnSignerProxyFactory', SafeWebAuthnSignerProxyFactory.address)

const navigator = {
credentials: new WebAuthnCredentials(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import { buildSignatureBytes } from '@safe-global/safe-4337/src/utils/execution'
*/
describe('Offchain Passkey Signature Verification [@userstory]', () => {
const setupTests = deployments.createFixture(async ({ deployments }) => {
const { SafeProxyFactory, SafeL2, FCLP256Verifier, SafeWebAuthnSignerFactory, CompatibilityFallbackHandler } = await deployments.run()
const { SafeProxyFactory, SafeL2, FCLP256Verifier, SafeWebAuthnSignerProxyFactory, CompatibilityFallbackHandler } =
await deployments.run()

const proxyFactory = await ethers.getContractAt(SafeProxyFactory.abi, SafeProxyFactory.address)
const singleton = await ethers.getContractAt(SafeL2.abi, SafeL2.address)
const fallbackHandler = await ethers.getContractAt(CompatibilityFallbackHandler.abi, CompatibilityFallbackHandler.address)
const verifier = await ethers.getContractAt('IP256Verifier', FCLP256Verifier.address)
const signerFactory = await ethers.getContractAt('SafeWebAuthnSignerFactory', SafeWebAuthnSignerFactory.address)
const signerFactory = await ethers.getContractAt('SafeWebAuthnSignerProxyFactory', SafeWebAuthnSignerProxyFactory.address)

const navigator = {
credentials: new WebAuthnCredentials(),
Expand Down Expand Up @@ -49,7 +50,7 @@ describe('Offchain Passkey Signature Verification [@userstory]', () => {
const publicKey = decodePublicKey(credential.response)
await signerFactory.createSigner(publicKey.x, publicKey.y, verifierAddress)
const signerAddress = await signerFactory.getSigner(publicKey.x, publicKey.y, verifierAddress)
const signer = await ethers.getContractAt('SafeWebAuthnSigner', signerAddress)
const signer = await ethers.getContractAt('SafeWebAuthnSignerProxy', signerAddress)

// Deploy Safe with the WebAuthn signer as a single owner.
const singletonAddress = await singleton.getAddress()
Expand Down
Loading

0 comments on commit 3c4fd03

Please sign in to comment.