Skip to content

Commit

Permalink
Emit Event on Shared Signer Configuration
Browse files Browse the repository at this point in the history
This PR adds an event that is emitted on shared signer configuration.
Note that the event is emitted in the context of the configured Safe
account. In order to prevent event `topic0` collisions, we chose an
explicitely verbose name.
  • Loading branch information
nlordell committed Jun 21, 2024
1 parent 75e56fd commit 535cb6c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
24 changes: 19 additions & 5 deletions modules/passkey/contracts/4337/SafeWebAuthnSharedSigner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ contract SafeWebAuthnSharedSigner is SignatureValidator {
*/
uint256 private constant _SIGNER_MAPPING_SLOT = 0x2e0aed53485dc2290ceb5ce14725558ad3e3a09d38c69042410ad15c2b4ea4e8;

/**
* @notice An error indicating a `CALL` to a function that should only be `DELEGATECALL`-ed.
*/
error NotDelegateCalled();

/**
* @notice Address of the shared signer contract itself.
* @dev This is used for determining whether or not the contract is being `DELEGATECALL`-ed when
Expand All @@ -49,6 +44,23 @@ contract SafeWebAuthnSharedSigner is SignatureValidator {
*/
uint256 public immutable SIGNER_SLOT;

/**
* @notice Emitted when the shared signer is configured for an account.
* @dev Note that the configured account is not included in the event data. Since configuration
* is done as a `DELEGATECALL`, the contract emitting the event is the configured account. This
* is also why the event name is prefixed with `SafeWebAuthnSharedSigner`, in order to avoid
* event `topic0` collisions with other contracts (seeing as "configured" is a common term).
* @param x The x-coordinate of the public key.
* @param y The y-coordinate of the public key.
* @param verifiers The P-256 verifiers to use.
*/
event SafeWebAuthnSharedSignerConfigured(uint256 x, uint256 y, P256.Verifiers verifiers);

/**
* @notice An error indicating a `CALL` to a function that should only be `DELEGATECALL`-ed.
*/
error NotDelegateCalled();

/**
* @notice Create a new shared WebAuthn signer instance.
*/
Expand Down Expand Up @@ -133,6 +145,8 @@ contract SafeWebAuthnSharedSigner is SignatureValidator {
signerStorage.x = signer.x;
signerStorage.y = signer.y;
signerStorage.verifiers = signer.verifiers;

emit SafeWebAuthnSharedSignerConfigured(signer.x, signer.y, signer.verifiers);
}

/**
Expand Down
26 changes: 26 additions & 0 deletions modules/passkey/test/4337/SafeWebAuthnSharedSigner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,32 @@ describe('SafeWebAuthnSharedSigner', () => {
expect(await ethers.provider.getStorage(account, BigInt(signerSlot) + 2n)).to.equal(config.verifiers)
})

it('Should emit an event', async () => {
const { safeSingleton, proxyFactory, sharedSigner, mockVerifier } = await setupTests()

const config = {
x: ethers.id('publicKey.x'),
y: ethers.id('publicKey.y'),
verifiers: ethers.toBeHex(await mockVerifier.getAddress(), 32),
}

const initializer = safeSingleton.interface.encodeFunctionData('setup', [
[sharedSigner.target],
1,
sharedSigner.target,
sharedSigner.interface.encodeFunctionData('configure', [config]),
ethers.ZeroAddress,
ethers.ZeroAddress,
0,
ethers.ZeroAddress,
])

const account = await proxyFactory.createProxyWithNonce.staticCall(safeSingleton, initializer, 0)
await expect(proxyFactory.createProxyWithNonce(safeSingleton, initializer, 0))
.to.emit(sharedSigner.attach(account), 'SafeWebAuthnSharedSignerConfigured')
.withArgs(config.x, config.y, config.verifiers)
})

it('Should revert if not DELEGATECALL-ed', async () => {
const { sharedSigner } = await setupTests()

Expand Down

0 comments on commit 535cb6c

Please sign in to comment.