Skip to content

Commit

Permalink
Merge branch 'main' of github.com:safe-global/safe-contracts into zksync
Browse files Browse the repository at this point in the history
  • Loading branch information
mmv08 committed Feb 3, 2023
2 parents 4d763ea + 92de184 commit 362405b
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 112 deletions.
2 changes: 1 addition & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ INFURA_KEY=""
NODE_URL=""
ETHERSCAN_API_KEY=""
# Target for the compilation and testing. Supported targets are "evm" and "zksync"
TARGET="zksync"
TARGET="evm"
54 changes: 34 additions & 20 deletions benchmark/utils/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ import {
SafeSignature,
executeContractCallWithSigners,
} from "../../src/utils/execution";
import { Wallet, Contract } from "ethers";
import { HHEthersSigner } from "../../src/types";
import { Contract } from "ethers";
import { AddressZero } from "@ethersproject/constants";

const [user1, user2, user3, user4, user5] = await hre.ethers.getSigners();
const getSigners = async (count: number) => {
const signers = await hre.ethers.getSigners();
return signers.slice(0, count);
};

export interface Contracts {
targets: Contract[];
additions: any | undefined;
}

const generateTarget = async (owners: Wallet[], threshold: number, guardAddress: string, logGasUsage?: boolean) => {
const generateTarget = async (owners: HHEthersSigner[], threshold: number, guardAddress: string, logGasUsage?: boolean) => {
const fallbackHandler = await getDefaultCallbackHandler();
const safe = await getSafeWithOwners(
owners.map((owner) => owner.address),
Expand All @@ -32,12 +36,19 @@ const generateTarget = async (owners: Wallet[], threshold: number, guardAddress:
return safe;
};

export const configs = [
{ name: "single owner", signers: [user1], threshold: 1 },
{ name: "single owner and guard", signers: [user1], threshold: 1, useGuard: true },
{ name: "2 out of 2", signers: [user1, user2], threshold: 2 },
{ name: "3 out of 3", signers: [user1, user2, user3], threshold: 3 },
{ name: "3 out of 5", signers: [user1, user2, user3, user4, user5], threshold: 3 },
type BenchmarkConfig = {
name: string;
signers: number;
threshold: number;
useGuard?: boolean;
};

export const BENCHMARKS: BenchmarkConfig[] = [
{ name: "single owner", signers: 1, threshold: 1 },
{ name: "single owner and guard", signers: 1, threshold: 1, useGuard: true },
{ name: "2 out of 2", signers: 2, threshold: 2 },
{ name: "3 out of 3", signers: 3, threshold: 3 },
{ name: "3 out of 5", signers: 5, threshold: 3 },
];

export const setupBenchmarkContracts = (benchmarkFixture?: () => Promise<any>, logGasUsage?: boolean) => {
Expand All @@ -46,10 +57,11 @@ export const setupBenchmarkContracts = (benchmarkFixture?: () => Promise<any>, l
const guardFactory = await hre.ethers.getContractFactory("DelegateCallTransactionGuard");
const guard = await guardFactory.deploy(AddressZero);
const targets: Contract[] = [];
for (const config of configs) {
targets.push(
await generateTarget(config.signers, config.threshold, config.useGuard ? guard.address : AddressZero, logGasUsage),
);
for (const config of BENCHMARKS) {
const signers = await getSigners(config.signers);
const guardAddress = config.useGuard ? guard.address : AddressZero;

targets.push(await generateTarget(signers, config.threshold, guardAddress, logGasUsage));
}
return {
targets,
Expand All @@ -65,34 +77,36 @@ export interface Benchmark {
fixture?: () => Promise<any>;
}

export const benchmark = async (topic: string, benchmarks: Benchmark[]) => {
export const benchmark = async (topic: string, benchmarks: Benchmark[]): Promise<void> => {
for (const benchmark of benchmarks) {
const { name, prepare, after, fixture } = benchmark;
const contractSetup = setupBenchmarkContracts(fixture);
describe(`${topic} - ${name}`, async () => {
it("with an EOA", async () => {
const contracts = await contractSetup();
const tx = await prepare(contracts, user2.address, 0);
const signer = (await getSigners(1))[0];
const tx = await prepare(contracts, signer.address, 0);
await logGas(
name,
user2.sendTransaction({
signer.sendTransaction({
to: tx.to,
value: tx.value,
data: tx.data,
}),
);
if (after) await after(contracts);
});
for (const i in configs) {
const config = configs[i];
it(`with a ${config.name} Safe`, async () => {
for (const i in BENCHMARKS) {
const benchmark = BENCHMARKS[i];
it(`with a ${benchmark.name} Safe`, async () => {
const contracts = await contractSetup();
const target = contracts.targets[i];
const nonce = await target.nonce();
const tx = await prepare(contracts, target.address, nonce);
const threshold = await target.getThreshold();
const signers = await getSigners(benchmark.signers);
const sigs: SafeSignature[] = await Promise.all(
config.signers.slice(0, threshold).map(async (signer) => {
signers.slice(0, threshold).map(async (signer) => {
return await safeSignTypedData(signer, target, tx);
}),
);
Expand Down
2 changes: 2 additions & 0 deletions contracts/test/Imports.sol
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
pragma solidity ^0.6.0;

import "@gnosis.pm/mock-contract/contracts/MockContract.sol";
170 changes: 85 additions & 85 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
{
"name": "@safe-global/safe-contracts",
"version": "1.3.0",
"description": "Ethereum multisig contract",
"homepage": "https://github.com/safe-global/safe-contracts/",
"license": "GPL-3.0",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
"contracts",
"dist",
"src",
"test",
"build"
],
"scripts": {
"build": "hardhat compile",
"build:ts": "yarn rimraf dist && tsc",
"test": "hardhat test",
"coverage": "hardhat coverage",
"benchmark": "yarn test benchmark/*.ts",
"deploy-custom": "rm -rf deployments/custom && yarn deploy-all custom",
"deploy-all": "hardhat deploy-contracts --network",
"deploy": "hardhat deploy --network",
"lint": "yarn lint:sol && yarn lint:ts",
"lint:sol": "solhint 'contracts/**/*.sol'",
"lint:ts": "eslint --max-warnings 0 .",
"fmt:sol": "prettier 'contracts/**/*.sol' -w",
"prepare": "husky install",
"prepublish": "yarn rimraf build && yarn build && yarn build:ts"
},
"repository": {
"type": "git",
"url": "git+https://github.com/safe-global/safe-contracts.git"
},
"keywords": [
"Ethereum",
"Wallet",
"Safe"
],
"author": "richard@safe.global",
"bugs": {
"url": "https://github.com/safe-global/safe-contracts/issues"
},
"devDependencies": {
"@gnosis.pm/mock-contract": "^4.0.0",
"@gnosis.pm/safe-singleton-factory": "^1.0.12",
"@matterlabs/hardhat-zksync-deploy": "^0.6.1",
"@matterlabs/hardhat-zksync-solc": "^0.3.13",
"@nomiclabs/hardhat-ethers": "2.0.2",
"@nomiclabs/hardhat-etherscan": "^2.1.0",
"@nomiclabs/hardhat-waffle": "2.0.1",
"@openzeppelin/contracts": "^3.4.0",
"@types/chai": "^4.2.14",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.21",
"@types/yargs": "^15.0.10",
"@typescript-eslint/eslint-plugin": "^4.7.0",
"@typescript-eslint/parser": "^4.7.0",
"argv": "^0.0.2",
"chai": "^4.2.0",
"debug": "^4.2.0",
"dotenv": "^8.0.0",
"eslint": "^7.13.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-no-only-tests": "^2.4.0",
"eslint-plugin-prettier": "^3.1.4",
"ethereum-waffle": "^3.3.0",
"ethers": "5.4.0",
"hardhat": "^2.2.1",
"hardhat-deploy": "0.9.2",
"husky": "^5.1.3",
"prettier": "^2.1.2",
"prettier-plugin-solidity": "1.0.0-beta.10",
"solc": "0.7.6",
"solhint": "3.3.4",
"solhint-plugin-prettier": "0.0.5",
"solidity-coverage": "^0.7.17",
"ts-node": "^9.1.1",
"typescript": "^4.2.4",
"yargs": "^16.1.1"
},
"peerDependencies": {
"ethers": "5.4.0"
}
"name": "@safe-global/safe-contracts",
"version": "1.3.0",
"description": "Ethereum multisig contract",
"homepage": "https://github.com/safe-global/safe-contracts/",
"license": "GPL-3.0",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
"contracts",
"dist",
"src",
"test",
"build"
],
"scripts": {
"build": "hardhat compile",
"build:ts": "yarn rimraf dist && tsc",
"test": "hardhat test",
"coverage": "hardhat coverage",
"benchmark": "yarn test benchmark/*.ts",
"deploy-custom": "rm -rf deployments/custom && yarn deploy-all custom",
"deploy-all": "hardhat deploy-contracts --network",
"deploy": "hardhat deploy --network",
"lint": "yarn lint:sol && yarn lint:ts",
"lint:sol": "solhint 'contracts/**/*.sol'",
"lint:ts": "eslint --max-warnings 0 .",
"fmt:sol": "prettier 'contracts/**/*.sol' -w",
"prepare": "husky install",
"prepublish": "yarn rimraf build && yarn build && yarn build:ts"
},
"repository": {
"type": "git",
"url": "git+https://github.com/safe-global/safe-contracts.git"
},
"keywords": [
"Ethereum",
"Wallet",
"Safe"
],
"author": "richard@safe.global",
"bugs": {
"url": "https://github.com/safe-global/safe-contracts/issues"
},
"devDependencies": {
"@gnosis.pm/mock-contract": "^4.0.0",
"@gnosis.pm/safe-singleton-factory": "^1.0.12",
"@matterlabs/hardhat-zksync-deploy": "^0.6.1",
"@matterlabs/hardhat-zksync-solc": "^0.3.13",
"@nomiclabs/hardhat-ethers": "2.0.2",
"@nomiclabs/hardhat-etherscan": "^2.1.0",
"@nomiclabs/hardhat-waffle": "2.0.1",
"@openzeppelin/contracts": "^3.4.0",
"@types/chai": "^4.2.14",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.21",
"@types/yargs": "^15.0.10",
"@typescript-eslint/eslint-plugin": "^4.7.0",
"@typescript-eslint/parser": "^4.7.0",
"argv": "^0.0.2",
"chai": "^4.2.0",
"debug": "^4.2.0",
"dotenv": "^8.0.0",
"eslint": "^7.13.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-no-only-tests": "^2.4.0",
"eslint-plugin-prettier": "^3.1.4",
"ethereum-waffle": "^3.3.0",
"ethers": "5.4.0",
"hardhat": "^2.2.1",
"hardhat-deploy": "0.9.2",
"husky": "^5.1.3",
"prettier": "^2.1.2",
"prettier-plugin-solidity": "1.0.0-beta.10",
"solc": "0.7.6",
"solhint": "3.3.4",
"solhint-plugin-prettier": "0.0.5",
"solidity-coverage": "^0.7.17",
"ts-node": "^9.1.1",
"typescript": "^4.2.4",
"yargs": "^16.1.1"
},
"peerDependencies": {
"ethers": "5.4.0"
}
}
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5875,9 +5875,9 @@ hosted-git-info@^2.1.4, hosted-git-info@^2.6.0:
integrity sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==

http-cache-semantics@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz#49e91c5cbf36c9b94bcfcd71c23d5249ec74e390"
integrity sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==
version "4.1.1"
resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz#abe02fcb2985460bf0323be664436ec3476a6d5a"
integrity sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==

http-errors@2.0.0:
version "2.0.0"
Expand Down Expand Up @@ -6564,9 +6564,9 @@ json5@^0.5.1:
integrity sha512-4xrs1aW+6N5DalkqSVA8fxh458CXvR99WU8WLKmq4v8eWAL86Xo3BVqyd3SkA9wEVjCMqyvvRRkshAdOnBp5rw==

json5@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.1.tgz#779fb0018604fa854eacbf6252180d83543e3dbe"
integrity sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==
version "1.0.2"
resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.2.tgz#63d98d60f21b313b77c4d6da18bfa69d80e1d593"
integrity sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==
dependencies:
minimist "^1.2.0"

Expand Down

0 comments on commit 362405b

Please sign in to comment.