-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
685 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: Nightly | ||
|
||
on: | ||
schedule: | ||
- cron: 0 0 * * * | ||
|
||
jobs: | ||
e2e-coordinator: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: dev | ||
- uses: pnpm/action-setup@v4 | ||
with: | ||
version: 9 | ||
|
||
- name: Use Node.js 20 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: "pnpm" | ||
|
||
- name: Install dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install --yes \ | ||
build-essential \ | ||
libgmp-dev \ | ||
libsodium-dev \ | ||
nasm \ | ||
nlohmann-json3-dev | ||
- name: Install | ||
run: | | ||
pnpm install --frozen-lockfile --prefer-offline | ||
- name: Build | ||
run: | | ||
pnpm run build | ||
- name: Download rapidsnark (1c137) | ||
run: | | ||
mkdir -p ~/rapidsnark/build | ||
wget -qO ~/rapidsnark/build/prover https://maci-devops-zkeys.s3.ap-northeast-2.amazonaws.com/rapidsnark-linux-amd64-1c137 | ||
chmod +x ~/rapidsnark/build/prover | ||
- name: Download circom Binary v2.1.6 | ||
run: | | ||
wget -qO ${{ github.workspace }}/circom https://github.com/iden3/circom/releases/download/v2.1.6/circom-linux-amd64 | ||
chmod +x ${{ github.workspace }}/circom | ||
sudo mv ${{ github.workspace }}/circom /bin/circom | ||
- name: Download zkeys | ||
run: | | ||
pnpm download-zkeys:test | ||
- name: Generate keypair | ||
run: | | ||
pnpm generate-keypair | ||
working-directory: packages/coordinator | ||
|
||
- name: E2E tests | ||
run: | | ||
pnpm run test:e2e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { signerToEcdsaValidator } from "@zerodev/ecdsa-validator"; | ||
import { serializePermissionAccount, toPermissionValidator } from "@zerodev/permissions"; | ||
import { toSudoPolicy } from "@zerodev/permissions/policies"; | ||
import { toECDSASigner } from "@zerodev/permissions/signers"; | ||
import { addressToEmptyAccount, createKernelAccount } from "@zerodev/sdk"; | ||
import { KERNEL_V3_1 } from "@zerodev/sdk/constants"; | ||
import dotenv from "dotenv"; | ||
import { ENTRYPOINT_ADDRESS_V07 } from "permissionless"; | ||
import { Hex } from "viem"; | ||
import { privateKeyToAccount } from "viem/accounts"; | ||
|
||
import { ESupportedNetworks } from "../ts/common"; | ||
import { getPublicClient } from "../ts/common/accountAbstraction"; | ||
import { CryptoService } from "../ts/crypto/crypto.service"; | ||
import { FileService } from "../ts/file/file.service"; | ||
import { ProofGeneratorService } from "../ts/proof/proof.service"; | ||
import { SessionKeysService } from "../ts/sessionKeys/sessionKeys.service"; | ||
|
||
dotenv.config(); | ||
|
||
const entryPoint = ENTRYPOINT_ADDRESS_V07; | ||
const kernelVersion = KERNEL_V3_1; | ||
|
||
/** | ||
* Generate an approval for a session key | ||
* | ||
* @returns - the approval | ||
*/ | ||
export const generateApproval = async (sessionKeyAddress: Hex): Promise<string> => { | ||
const publicClient = getPublicClient(ESupportedNetworks.OPTIMISM_SEPOLIA); | ||
|
||
const sessionKeySigner = privateKeyToAccount(process.env.TEST_PRIVATE_KEY! as `0x${string}`); | ||
const ecdsaValidator = await signerToEcdsaValidator(publicClient, { | ||
signer: sessionKeySigner, | ||
entryPoint, | ||
kernelVersion, | ||
}); | ||
|
||
const emptyAccount = addressToEmptyAccount(sessionKeyAddress); | ||
const emptySessionKeySigner = toECDSASigner({ signer: emptyAccount }); | ||
|
||
const permissionPlugin = await toPermissionValidator(publicClient, { | ||
entryPoint, | ||
kernelVersion, | ||
signer: emptySessionKeySigner, | ||
policies: [toSudoPolicy({})], | ||
}); | ||
|
||
const sessionKeyAccount = await createKernelAccount(publicClient, { | ||
entryPoint, | ||
kernelVersion, | ||
plugins: { | ||
sudo: ecdsaValidator, | ||
regular: permissionPlugin, | ||
}, | ||
}); | ||
|
||
return serializePermissionAccount(sessionKeyAccount); | ||
}; | ||
|
||
describe("E2E Account Abstraction Tests", () => { | ||
const fileService = new FileService(); | ||
const sessionKeyService = new SessionKeysService(fileService); | ||
const cryptoService = new CryptoService(); | ||
const proofService = new ProofGeneratorService(cryptoService, fileService, sessionKeyService); | ||
|
||
// using an already deployed maci contract | ||
const maciContract = "0xf281870519822f302B13c07252d0f6A71E8D023e"; | ||
const pollId = 2; | ||
|
||
test("should return true when there are no errors", async () => { | ||
const sessionKey = sessionKeyService.generateSessionKey().sessionKeyAddress; | ||
const approval = await generateApproval(sessionKey); | ||
|
||
const merged = await proofService.merge({ | ||
maciContractAddress: maciContract, | ||
pollId, | ||
sessionKeyAddress: sessionKey, | ||
approval, | ||
chain: ESupportedNetworks.OPTIMISM_SEPOLIA, | ||
}); | ||
|
||
expect(merged).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { ErrorCodes } from "./errors"; | ||
export { ESupportedNetworks } from "./networks"; | ||
export { transformToString } from "./utils"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Transform string to lowercase | ||
* | ||
* @param param0 - string to transform | ||
* @returns lowercase string | ||
*/ | ||
export const transformToString = ({ value }: { value: string }): string => value.toLowerCase(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.