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 fc10f45
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 333 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));
}
}
43 changes: 0 additions & 43 deletions modules/passkey/contracts/base/SignatureValidator.sol

This file was deleted.

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);
}
53 changes: 0 additions & 53 deletions modules/passkey/contracts/test/TestWebAuthnSingletonSigner.sol

This file was deleted.

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
7 changes: 1 addition & 6 deletions modules/passkey/test/4337/WebAuthnSingletonSigner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('WebAuthn Singleton Signers [@4337]', () => {
})
.then((tx) => tx.wait())

const WebAuthnSingletonSigner = await ethers.getContractFactory('TestWebAuthnSingletonSigner')
const WebAuthnSingletonSigner = await ethers.getContractFactory('SafeWebAuthnSignerSingleton')
const signer = await WebAuthnSingletonSigner.deploy()

const navigator = {
Expand Down Expand Up @@ -106,11 +106,6 @@ describe('WebAuthn Singleton Signers [@4337]', () => {
to: safeModuleSetup.target,
data: safeModuleSetup.interface.encodeFunctionData('enableModules', [[module.target]]),
},
{
op: 0 as const,
to: signer.target,
data: signer.interface.encodeFunctionData('setOwner', [{ ...publicKey, verifier: verifier.target }]),
},
]),
]),
module.target,
Expand Down
Loading

0 comments on commit fc10f45

Please sign in to comment.