Skip to content

Commit

Permalink
🚀 Add deterministic deployment of the webauthn fcl validator
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed Mar 18, 2024
1 parent 7cf4583 commit a268700
Show file tree
Hide file tree
Showing 8 changed files with 549 additions and 22 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ MIT

## Addresses

<details>
<summary>v TBD</summary>

| Name | Address |
| -------------------- | ------------------------------------------ |
| Kernel | 0xd3082872F8B06073A021b4602e022d5A070d7cfC |
| KernelFactory | 0x5de4839a76cf55d0c90e2061ef4386d962E15ae3 |
| SessionKeyValidator | 0xB8E3c4bEaACAd06f6092793012DA4a8cB23D6123 |
| ECDSA Validator | 0xd9AB5096a832b9ce79914329DAEE236f8Eea0390 |
| FclWebAuthnValidator | 0x42085b533b27B9AfDAF3864a38c72eF853943DAB |
| P256VerifierWrapper | 0x738e3257EE928637fE62c37F91D3e722C45Dcc7C |
</details>

<details>
<summary>v2.4</summary>

Expand Down
120 changes: 120 additions & 0 deletions broadcast/DeployDeterministic.s.sol/137/run-1710798757.json

Large diffs are not rendered by default.

120 changes: 120 additions & 0 deletions broadcast/DeployDeterministic.s.sol/137/run-latest.json

Large diffs are not rendered by default.

120 changes: 120 additions & 0 deletions broadcast/DeployDeterministic.s.sol/80002/run-1710798602.json

Large diffs are not rendered by default.

120 changes: 120 additions & 0 deletions broadcast/DeployDeterministic.s.sol/80002/run-latest.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions script/DeployDeterministic.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "./deterministic/Factory.s.sol";
import "./deterministic/SessionKey.s.sol";
import "./deterministic/Kernel2_2.s.sol";
import "./deterministic/Kernel2_3.s.sol";
import "./deterministic/FclWebAuthNValidator.s.sol";

contract DeployDeterministic is Script {
address constant DEPLOYER = 0x9775137314fE595c943712B0b336327dfa80aE8A;
Expand Down Expand Up @@ -35,6 +36,10 @@ contract DeployDeterministic is Script {
if (!factory.isAllowedImplementation(k23lite)) {
factory.setImplementation(k23lite, true);
}

// Deploy the webauthn fcl validators
FclWebAuthnValidatorDeploy.deployWebAuthnFclVerifier();

vm.stopBroadcast();
}
}
22 changes: 0 additions & 22 deletions script/DeployWebAuthnFclValidator.sol

This file was deleted.

51 changes: 51 additions & 0 deletions script/deterministic/FclWebAuthNValidator.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
pragma solidity ^0.8.0;

import "src/utils/P256VerifierWrapper.sol";
import "src/validator/webauthn//WebAuthnFclValidator.sol";
import "./DeterministicDeploy.s.sol";
import "forge-std/console.sol";

/// @dev Deterministic deployment of FclWebAuthNValidator
library FclWebAuthnValidatorDeploy {
address constant EXPECTED_P256_VERIFIER_VALIDATOR_ADDRESS = 0x738e3257EE928637fE62c37F91D3e722C45Dcc7C;

address constant EXPECTED_WEBAUTHN_VALIDATOR_ADDRESS = 0x42085b533b27B9AfDAF3864a38c72eF853943DAB;

bytes32 constant DEPLOYMENT_SALT = keccak256("WebAuthNValidator by Frak");

/// @dev Deploy the P256VerifierWrapper and WebAuthnFclValidator
function deployWebAuthnFclVerifier() internal {
// Check if the contract of the p256 verifier is already deployed
if (EXPECTED_P256_VERIFIER_VALIDATOR_ADDRESS.code.length == 0) {
_deployOnChainP256();
} else {
console.log("P256VerifierWrapper: already deployed");
}

// Deploy the WebAuthnFclValidator
if (EXPECTED_WEBAUTHN_VALIDATOR_ADDRESS.code.length == 0) {
_deployValidator();
} else {
console.log("WebAuthnFclValidator: already deployed");
}
}

/// @dev Deploy the P256VerifierWrapper contract
function _deployOnChainP256() private {
P256VerifierWrapper p256Wrapper = new P256VerifierWrapper{salt: DEPLOYMENT_SALT}();
require(
address(p256Wrapper) == EXPECTED_P256_VERIFIER_VALIDATOR_ADDRESS,
"FclWebAuthnValidatorDeploy: p256 wrapper address mismatch"
);
}

/// @dev Deploy the P256VerifierWrapper contract
function _deployValidator() private {
WebAuthnFclValidator validator =
new WebAuthnFclValidator{salt: DEPLOYMENT_SALT}(EXPECTED_P256_VERIFIER_VALIDATOR_ADDRESS);
require(
address(validator) == EXPECTED_WEBAUTHN_VALIDATOR_ADDRESS,
"FclWebAuthnValidatorDeploy: validator address mismatch"
);
}
}

0 comments on commit a268700

Please sign in to comment.