Skip to content

Commit

Permalink
Merge pull request #108 from zkemail/feat/oauth-mvp
Browse files Browse the repository at this point in the history
Feat/oauth mvp
  • Loading branch information
SoraSuegami authored Nov 19, 2024
2 parents 736644d + 4f0b4eb commit d031acf
Show file tree
Hide file tree
Showing 55 changed files with 12,137 additions and 1,760 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ book

# Vs code settings
.vscode

# Oauth-sdk
packages/oauth-sdk/.env
packages/oauth-sdk/dist
5 changes: 4 additions & 1 deletion Relayer.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Use the base image
FROM bisht13/relayer-base:latest
FROM sorasue/relayer:latest

# Copy the project files
COPY packages/relayer /relayer/packages/relayer

# Copy the rust-toolchain.toml file
COPY rust-toolchain.toml /relayer/packages/relayer/rust-toolchain.toml

# Set the working directory for the Rust project
WORKDIR /relayer/packages/relayer

Expand Down
8 changes: 7 additions & 1 deletion packages/contracts/script/04_DeployWallet.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ contract Deploy is Script {
return;
}

address oauth = vm.envAddress("OAUTH");
if (oauth == address(0)) {
console.log("OAUTH env var not set.");
return;
}

vm.startBroadcast(deployerPrivateKey);

// Deploy wallet implementation
Wallet walletImpl = new Wallet(address(weth));
Wallet walletImpl = new Wallet(address(weth), address(oauth));

vm.stopBroadcast();

Expand Down
207 changes: 205 additions & 2 deletions packages/contracts/script/DefaultSetupScript.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ pragma solidity ^0.8.13;
import "forge-std/Script.sol";
import "forge-std/console.sol";
import "../src/verifier/Verifier.sol";
import "../src/utils/OauthCore.sol";
import "../src/utils/ECDSAOwnedDKIMRegistry.sol";
import "../src/utils/UniswapTWAPOracle.sol";
import "../src/extensions/NFTExtension.sol";
import "../src/extensions/UniswapExtension.sol";
import "../src/extensions/Safe2FAExtension.sol";
import "../src/extensions/OauthSignupExtension.sol";
import "../src/extensions/OauthSigninExtension.sol";
import "../src/EmailWalletCore.sol";

contract TestERC20 is ERC20 {
Expand Down Expand Up @@ -36,6 +39,9 @@ contract Deploy is Script {

ECDSAOwnedDKIMRegistry dkim;

OauthCore oauthCoreImpl;
OauthCore oauthCore;

Wallet walletImpl;

RelayerHandler relayerHandler;
Expand Down Expand Up @@ -66,6 +72,12 @@ contract Deploy is Script {
Safe2FAExtension safeExt;
Safe2FAExtension safeExtImpl;

OauthSignupExtension oauthUpExt;
OauthSignupExtension oauthUpExtImpl;

OauthSigninExtension oauthInExt;
OauthSigninExtension oauthInExtImpl;

uint256 constant emailValidityDuration = 14 days;
uint256 constant unclaimedFundClaimGas = 450000;
uint256 constant unclaimedStateClaimGas = 500000;
Expand All @@ -75,6 +87,8 @@ contract Deploy is Script {
string[][] nftExtTemplates = new string[][](3);
string[][] uniswapExtTemplates = new string[][](4);
string[][] safeExtTemplates = new string[][](1);
string[][] oauthUpExtTemplates = new string[][](9);
string[][] oauthInExtTemplates = new string[][](8);

function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
Expand Down Expand Up @@ -126,7 +140,14 @@ contract Deploy is Script {

dkim = new ECDSAOwnedDKIMRegistry(signer);

walletImpl = new Wallet(address(weth));
{
oauthCoreImpl = new OauthCore();
bytes memory data = abi.encodeWithSelector(OauthCore(oauthCoreImpl).initialize.selector);
ERC1967Proxy proxy = new ERC1967Proxy(address(oauthCoreImpl), data);
oauthCore = OauthCore(payable(address(proxy)));
}

walletImpl = new Wallet(address(weth), address(oauthCore));

{
relayerHandlerImpl = new RelayerHandler();
Expand Down Expand Up @@ -203,7 +224,7 @@ contract Deploy is Script {
tokenRegistry.setChainId(chainName, chainId);
tokenRegistry.setTokenAddress(chainId, tokenName, address(testToken));

bytes[] memory defaultExtensions = new bytes[](3);
bytes[] memory defaultExtensions = new bytes[](5);

{
nftExtImpl = new NFTExtension();
Expand Down Expand Up @@ -273,6 +294,181 @@ contract Deploy is Script {
safeExtTemplates[0] = ["Safe", "Transaction:", "Approve", "{string}", "from", "{address}"];
defaultExtensions[2] = abi.encode("Safe2FAExtension", address(safeExt), safeExtTemplates, 0.001 ether); // TODO: Check max exec gas

{
oauthUpExtImpl = new OauthSignupExtension();
bytes memory data = abi.encodeWithSelector(
OauthSignupExtension(oauthUpExtImpl).initialize.selector,
address(core)
);
ERC1967Proxy proxy = new ERC1967Proxy(address(oauthUpExtImpl), data);
oauthUpExt = OauthSignupExtension(payable(address(proxy)));
}
oauthUpExtTemplates[0] = ["Sign-up", "{string}"];
// (0,0) = 0
oauthUpExtTemplates[1] = ["Sign-up", "{string}", "on", "device", "{uint}"];
// (0,1) = 1
oauthUpExtTemplates[2] = ["Sign-up", "{string}", "on", "device", "{uint}", "for", "{tokenAmount}"];
// (0,2) = 2
oauthUpExtTemplates[3] = [
"Sign-up",
"{string}",
"on",
"device",
"{uint}",
"for",
"{tokenAmount}",
"{tokenAmount}"
];
// (0,3) = 3
oauthUpExtTemplates[4] = [
"Sign-up",
"{string}",
"on",
"device",
"{uint}",
"for",
"{tokenAmount}",
"{tokenAmount}",
"{tokenAmount}"
];
// (1,0) = 4
oauthUpExtTemplates[5] = ["Sign-up", "{string}", "on", "device", "{uint}", "until", "timestamp", "{uint}"];
// (1,1) = 4 + 1 = 5
oauthUpExtTemplates[6] = [
"Sign-up",
"{string}",
"on",
"device",
"{uint}",
"until",
"timestamp",
"{uint}",
"for",
"{tokenAmount}"
];
// (1,2) = 4 + 2 = 6
oauthUpExtTemplates[7] = [
"Sign-up",
"{string}",
"on",
"device",
"{uint}",
"until",
"timestamp",
"{uint}",
"for",
"{tokenAmount}",
"{tokenAmount}"
];
// (1,3) = 4 + 3 = 7
oauthUpExtTemplates[8] = [
"Sign-up",
"{string}",
"on",
"device",
"{uint}",
"until",
"timestamp",
"{uint}",
"for",
"{tokenAmount}",
"{tokenAmount}",
"{tokenAmount}"
];
defaultExtensions[3] = abi.encode(
"OauthSignupExtension",
address(oauthUpExt),
oauthUpExtTemplates,
0.001 ether
); // TODO: Check max exec gas

{
oauthInExtImpl = new OauthSigninExtension();
bytes memory data = abi.encodeWithSelector(
OauthSigninExtension(oauthInExtImpl).initialize.selector,
address(core)
);
ERC1967Proxy proxy = new ERC1967Proxy(address(oauthInExtImpl), data);
oauthInExt = OauthSigninExtension(payable(address(proxy)));
}
// (0,0) = 0
oauthInExtTemplates[0] = ["Sign-in", "{string}", "on", "device", "{uint}"];
// (0,1) = 1
oauthInExtTemplates[1] = ["Sign-in", "{string}", "on", "device", "{uint}", "for", "{tokenAmount}"];
// (0,2) = 2
oauthInExtTemplates[2] = [
"Sign-in",
"{string}",
"on",
"device",
"{uint}",
"for",
"{tokenAmount}",
"{tokenAmount}"
];
// (0,3) = 3
oauthInExtTemplates[3] = [
"Sign-in",
"{string}",
"on",
"device",
"{uint}",
"for",
"{tokenAmount}",
"{tokenAmount}",
"{tokenAmount}"
];
// (1,0) = 4
oauthInExtTemplates[4] = ["Sign-in", "{string}", "on", "device", "{uint}", "until", "timestamp", "{uint}"];
// (1,1) = 4 + 1 = 5
oauthInExtTemplates[5] = [
"Sign-in",
"{string}",
"on",
"device",
"{uint}",
"until",
"timestamp",
"{uint}",
"for",
"{tokenAmount}"
];
// (1,2) = 4 + 2 = 6
oauthInExtTemplates[6] = [
"Sign-in",
"{string}",
"on",
"device",
"{uint}",
"until",
"timestamp",
"{uint}",
"for",
"{tokenAmount}",
"{tokenAmount}"
];
// (1,3) = 4 + 3 = 7
oauthInExtTemplates[7] = [
"Sign-in",
"{string}",
"on",
"device",
"{uint}",
"until",
"timestamp",
"{uint}",
"for",
"{tokenAmount}",
"{tokenAmount}",
"{tokenAmount}"
];
defaultExtensions[4] = abi.encode(
"OauthSigninExtension",
address(oauthInExt),
oauthInExtTemplates,
0.001 ether
); // TODO: Check max exec gas

core.initializeExtension(defaultExtensions);

vm.stopBroadcast();
Expand All @@ -282,6 +478,7 @@ contract Deploy is Script {
console.log("AllVerifiers implementation deployed at: %s", address(verifierImpl));
console.log("ECDSAOwnedDKIMRegistry deployed at: %s", address(dkim));
console.log("Wallet implementation deployed at: %s", address(walletImpl));
console.log("Oauth core deployed at: %s", address(oauthCore));
console.log("RelayerHandler proxy deployed at: %s", address(relayerHandler));
console.log("RelayerHandler implementation deployed at: %s", address(relayerHandlerImpl));
console.log("ExtensionHandler proxy deployed at: %s", address(extensionHandler));
Expand All @@ -298,6 +495,12 @@ contract Deploy is Script {
console.log("NFTExtension implementation deployed at: %s", address(nftExtImpl));
console.log("UniswapExtension proxy deployed at: %s", address(uniExt));
console.log("UniswapExtension implementation deployed at: %s", address(uniExtImpl));
console.log("Safe2FAExtension proxy deployed at: %s", address(safeExt));
console.log("Safe2FAExtension implementation deployed at: %s", address(safeExtImpl));
console.log("OauthSignupExtension proxy deployed at: %s", address(oauthUpExt));
console.log("OauthSignupExtension implementation deployed at: %s", address(oauthUpExtImpl));
console.log("OauthSigninExtension proxy deployed at: %s", address(oauthInExt));
console.log("OauthSigninExtension implementation deployed at: %s", address(oauthInExtImpl));
console.log("---- DONE ----");
}
}
40 changes: 40 additions & 0 deletions packages/contracts/script/UpgradeOauthCore.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import "forge-std/Script.sol";
import "forge-std/console.sol";
import "../src/utils/OauthCore.sol";

contract Deploy is Script {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
if (deployerPrivateKey == 0) {
console.log("PRIVATE_KEY env var not set");
return;
}

address oauthCore = vm.envAddress("OAUTH_CORE");
if (oauthCore == address(0)) {
console.log("OAUTH_CORE env var not set. Deploy OAUTH_CORE and set env var");
return;
}

vm.startBroadcast(deployerPrivateKey);

OauthCore oauthCoreImpl = new OauthCore();

OauthCore oauthCoreProxy = OauthCore(payable(address(oauthCore)));
oauthCoreProxy.upgradeTo(address(oauthCoreImpl));

// If you want to call some v2 function, refer to the following steps
//
// TokenRegistryV2 tokenRegistryV2 = TokenRegistryV2(address(tokenRegistry));
// address usdc = tokenRegistry.getTokenAddress(0, "USDC");

vm.stopBroadcast();

console.log("OauthCore implementation deployed at: %s", address(oauthCoreImpl));
console.log("---- DONE ----");
}
}
2 changes: 1 addition & 1 deletion packages/contracts/src/EmailWalletCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ contract EmailWalletCore is Initializable, UUPSUpgradeable, OwnableUpgradeable {
require(_getFeeConversionRate(emailOp.feeTokenName) != 0, "unsupported fee token");
require(emailOp.feePerGas <= maxFeePerGas, "fee per gas too high");
require(emailNullifiers[emailOp.emailNullifier] == false, "email nullified");
require(accountHandler.emailNullifiers(emailOp.emailNullifier) == false, "email nullified");
// require(accountHandler.emailNullifiers(emailOp.emailNullifier) == false, "email nullified");
require(
accountHandler.isDKIMPublicKeyHashValid(
emailOp.accountSalt,
Expand Down
Loading

0 comments on commit d031acf

Please sign in to comment.