Skip to content

Commit

Permalink
refactor and use double quotes
Browse files Browse the repository at this point in the history
Signed-off-by: Chengxuan Xing <[email protected]>
  • Loading branch information
Chengxuan committed Oct 1, 2024
1 parent be4a593 commit 6879293
Show file tree
Hide file tree
Showing 84 changed files with 1,173 additions and 1,210 deletions.
3 changes: 0 additions & 3 deletions solidity/.prettierrc

This file was deleted.

29 changes: 0 additions & 29 deletions solidity/contracts/lib/zeto_base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,35 +100,6 @@ abstract contract ZetoBase is IZetoBase, ZetoCommon {
return true;
}

function checkAndPadCommitments(
uint256[] memory inputs,
uint256[] memory outputs,
uint256 batchMax
) internal pure returns (uint256[] memory, uint256[] memory) {
uint256 inputLen = inputs.length;
uint256 outputLen = outputs.length;

// Check if inputs or outputs exceed batchMax and revert with custom error if necessary
if (inputLen > batchMax || outputLen > batchMax) {
revert UTXOCommitmentsExceededMaximumNumber(batchMax);
}

// Ensure both arrays are padded to the same length
uint256 maxLength;

if (inputLen > 2 || outputLen > 2) {
maxLength = batchMax; // Pad both to batchMax if one has more than 2 items
} else {
maxLength = 2; // Otherwise, pad both to 2
}

// Pad both inputs and outputs to the determined maxLength
inputs = Commonlib.padUintArray(inputs, maxLength, 0);
outputs = Commonlib.padUintArray(outputs, maxLength, 0);

return (inputs, outputs);
}

function processInputsAndOutputs(
uint256[] memory inputs,
uint256[] memory outputs
Expand Down
27 changes: 27 additions & 0 deletions solidity/contracts/lib/zeto_common.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,34 @@ abstract contract ZetoCommon is OwnableUpgradeable {
);
lockedProofs[proofHash] = delegate;
}
function checkAndPadCommitments(
uint256[] memory inputs,
uint256[] memory outputs,
uint256 batchMax
) internal pure returns (uint256[] memory, uint256[] memory) {
uint256 inputLen = inputs.length;
uint256 outputLen = outputs.length;

// Check if inputs or outputs exceed batchMax and revert with custom error if necessary
if (inputLen > batchMax || outputLen > batchMax) {
revert UTXOCommitmentsExceededMaximumNumber(batchMax);
}

// Ensure both arrays are padded to the same length
uint256 maxLength;

if (inputLen > 2 || outputLen > 2) {
maxLength = batchMax; // Pad both to batchMax if one has more than 2 items
} else {
maxLength = 2; // Otherwise, pad both to 2
}

// Pad both inputs and outputs to the determined maxLength
inputs = Commonlib.padUintArray(inputs, maxLength, 0);
outputs = Commonlib.padUintArray(outputs, maxLength, 0);

return (inputs, outputs);
}
function sortInputsAndOutputs(
uint256[] memory inputs,
uint256[] memory outputs
Expand Down
29 changes: 0 additions & 29 deletions solidity/contracts/lib/zeto_nullifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,6 @@ abstract contract ZetoNullifier is IZetoBase, ZetoCommon {
_commitmentsTree.initialize(MAX_SMT_DEPTH);
}

function checkAndPadCommitments(
uint256[] memory inputs,
uint256[] memory outputs,
uint256 batchMax
) internal pure returns (uint256[] memory, uint256[] memory) {
uint256 inputLen = inputs.length;
uint256 outputLen = outputs.length;

// Check if inputs or outputs exceed batchMax and revert with custom error if necessary
if (inputLen > batchMax || outputLen > batchMax) {
revert UTXOCommitmentsExceededMaximumNumber(batchMax);
}

// Ensure both arrays are padded to the same length
uint256 maxLength;

if (inputLen > 2 || outputLen > 2) {
maxLength = batchMax; // Pad both to batchMax if one has more than 2 items
} else {
maxLength = 2; // Otherwise, pad both to 2
}

// Pad both inputs and outputs to the determined maxLength
inputs = Commonlib.padUintArray(inputs, maxLength, 0);
outputs = Commonlib.padUintArray(outputs, maxLength, 0);

return (inputs, outputs);
}

function validateTransactionProposal(
uint256[] memory nullifiers,
uint256[] memory outputs,
Expand Down
6 changes: 3 additions & 3 deletions solidity/ignition/modules/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { buildModule } from '@nomicfoundation/hardhat-ignition/modules';
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";

export default buildModule('SampleERC20', (m) => {
export default buildModule("SampleERC20", (m) => {
const owner = m.getAccount(0);
const erc20 = m.contract('SampleERC20', [owner], { from: owner });
const erc20 = m.contract("SampleERC20", [owner], { from: owner });
return { erc20 };
});
32 changes: 16 additions & 16 deletions solidity/ignition/modules/lib/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { buildModule } from '@nomicfoundation/hardhat-ignition/modules';
import { poseidonContract } from 'circomlibjs';
import { Artifact } from 'hardhat/types';
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import { poseidonContract } from "circomlibjs";
import { Artifact } from "hardhat/types";

export const SmtLibModule = buildModule('SmtLib', (m) => {
const poseidon2 = m.library('Poseidon2', PoseidonArtifact(2));
const poseidon3 = m.library('Poseidon3', PoseidonArtifact(3));
const smtLib = m.contract('SmtLib', [], {
export const SmtLibModule = buildModule("SmtLib", (m) => {
const poseidon2 = m.library("Poseidon2", PoseidonArtifact(2));
const poseidon3 = m.library("Poseidon3", PoseidonArtifact(3));
const smtLib = m.contract("SmtLib", [], {
libraries: {
PoseidonUnit2L: poseidon2,
PoseidonUnit3L: poseidon3,
Expand All @@ -31,25 +31,25 @@ export const SmtLibModule = buildModule('SmtLib', (m) => {
});

export const DepositVerifierModule = buildModule(
'Groth16Verifier_CheckHashesValue',
"Groth16Verifier_CheckHashesValue",
(m) => {
const verifier = m.contract('Groth16Verifier_CheckHashesValue', []);
const verifier = m.contract("Groth16Verifier_CheckHashesValue", []);
return { verifier };
},
);

export const WithdrawNullifierVerifierModule = buildModule(
'Groth16Verifier_CheckNullifierValue',
"Groth16Verifier_CheckNullifierValue",
(m) => {
const verifier = m.contract('Groth16Verifier_CheckNullifierValue', []);
const verifier = m.contract("Groth16Verifier_CheckNullifierValue", []);
return { verifier };
},
);

export const WithdrawVerifierModule = buildModule(
'Groth16Verifier_CheckInputsOutputsValue',
"Groth16Verifier_CheckInputsOutputsValue",
(m) => {
const verifier = m.contract('Groth16Verifier_CheckInputsOutputsValue', []);
const verifier = m.contract("Groth16Verifier_CheckInputsOutputsValue", []);
return { verifier };
},
);
Expand All @@ -58,12 +58,12 @@ function PoseidonArtifact(param: number): Artifact {
const abi = poseidonContract.generateABI(param);
const bytecode = poseidonContract.createCode(param);
const artifact: Artifact = {
_format: 'hh-sol-artifact-1',
_format: "hh-sol-artifact-1",
contractName: `Poseidon${param}`,
sourceName: '',
sourceName: "",
abi: abi,
bytecode: bytecode,
deployedBytecode: '', // "0x"-prefixed hex string
deployedBytecode: "", // "0x"-prefixed hex string
linkReferences: {},
deployedLinkReferences: {},
};
Expand Down
14 changes: 7 additions & 7 deletions solidity/ignition/modules/zeto_anon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { buildModule } from '@nomicfoundation/hardhat-ignition/modules';
import { DepositVerifierModule, WithdrawVerifierModule } from './lib/deps';
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import { DepositVerifierModule, WithdrawVerifierModule } from "./lib/deps";

const VerifierModule = buildModule('Groth16Verifier_Anon', (m) => {
const verifier = m.contract('Groth16Verifier_Anon', []);
const VerifierModule = buildModule("Groth16Verifier_Anon", (m) => {
const verifier = m.contract("Groth16Verifier_Anon", []);
return { verifier };
});

const BatchVerifierModule = buildModule('Groth16Verifier_AnonBatch', (m) => {
const verifier = m.contract('Groth16Verifier_AnonBatch', []);
const BatchVerifierModule = buildModule("Groth16Verifier_AnonBatch", (m) => {
const verifier = m.contract("Groth16Verifier_AnonBatch", []);
return { verifier };
});

export default buildModule('Zeto_Anon', (m) => {
export default buildModule("Zeto_Anon", (m) => {
const { verifier } = m.useModule(VerifierModule);
const { verifier: batchVerifier } = m.useModule(BatchVerifierModule);
const { verifier: depositVerifier } = m.useModule(DepositVerifierModule);
Expand Down
14 changes: 7 additions & 7 deletions solidity/ignition/modules/zeto_anon_enc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { buildModule } from '@nomicfoundation/hardhat-ignition/modules';
import { DepositVerifierModule, WithdrawVerifierModule } from './lib/deps';
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import { DepositVerifierModule, WithdrawVerifierModule } from "./lib/deps";

const VerifierModule = buildModule('Groth16Verifier_AnonEnc', (m) => {
const verifier = m.contract('Groth16Verifier_AnonEnc', []);
const VerifierModule = buildModule("Groth16Verifier_AnonEnc", (m) => {
const verifier = m.contract("Groth16Verifier_AnonEnc", []);
return { verifier };
});

const BatchVerifierModule = buildModule('Groth16Verifier_AnonEncBatch', (m) => {
const verifier = m.contract('Groth16Verifier_AnonEncBatch', []);
const BatchVerifierModule = buildModule("Groth16Verifier_AnonEncBatch", (m) => {
const verifier = m.contract("Groth16Verifier_AnonEncBatch", []);
return { verifier };
});

export default buildModule('Zeto_AnonEnc', (m) => {
export default buildModule("Zeto_AnonEnc", (m) => {
const { verifier } = m.useModule(VerifierModule);
const { verifier: batchVerifier } = m.useModule(BatchVerifierModule);
const { verifier: depositVerifier } = m.useModule(DepositVerifierModule);
Expand Down
14 changes: 7 additions & 7 deletions solidity/ignition/modules/zeto_anon_enc_nullifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { buildModule } from '@nomicfoundation/hardhat-ignition/modules';
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import {
SmtLibModule,
DepositVerifierModule,
WithdrawNullifierVerifierModule,
} from './lib/deps';
} from "./lib/deps";

const VerifierModule = buildModule('Groth16Verifier_AnonEncNullifier', (m) => {
const verifier = m.contract('Groth16Verifier_AnonEncNullifier', []);
const VerifierModule = buildModule("Groth16Verifier_AnonEncNullifier", (m) => {
const verifier = m.contract("Groth16Verifier_AnonEncNullifier", []);
return { verifier };
});

const BatchVerifierModule = buildModule(
'Groth16Verifier_AnonEncNullifierBatch',
"Groth16Verifier_AnonEncNullifierBatch",
(m) => {
const verifier = m.contract('Groth16Verifier_AnonEncNullifierBatch', []);
const verifier = m.contract("Groth16Verifier_AnonEncNullifierBatch", []);
return { verifier };
},
);

export default buildModule('Zeto_AnonEncNullifier', (m) => {
export default buildModule("Zeto_AnonEncNullifier", (m) => {
const { smtLib, poseidon3 } = m.useModule(SmtLibModule);
const { verifier } = m.useModule(VerifierModule);
const { verifier: batchVerifier } = m.useModule(BatchVerifierModule);
Expand Down
14 changes: 7 additions & 7 deletions solidity/ignition/modules/zeto_anon_enc_nullifier_kyc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { buildModule } from '@nomicfoundation/hardhat-ignition/modules';
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import {
SmtLibModule,
DepositVerifierModule,
WithdrawNullifierVerifierModule,
} from './lib/deps';
} from "./lib/deps";

const VerifierModule = buildModule(
'Groth16Verifier_AnonEncNullifierKyc',
"Groth16Verifier_AnonEncNullifierKyc",
(m) => {
const verifier = m.contract('Groth16Verifier_AnonEncNullifierKyc', []);
const verifier = m.contract("Groth16Verifier_AnonEncNullifierKyc", []);
return { verifier };
},
);

const BatchVerifierModule = buildModule(
'Groth16Verifier_AnonEncNullifierKycBatch',
"Groth16Verifier_AnonEncNullifierKycBatch",
(m) => {
const verifier = m.contract('Groth16Verifier_AnonEncNullifierKycBatch', []);
const verifier = m.contract("Groth16Verifier_AnonEncNullifierKycBatch", []);
return { verifier };
},
);

export default buildModule('Zeto_AnonEncNullifierKyc', (m) => {
export default buildModule("Zeto_AnonEncNullifierKyc", (m) => {
const { smtLib, poseidon2, poseidon3 } = m.useModule(SmtLibModule);
const { verifier } = m.useModule(VerifierModule);
const { verifier: batchVerifier } = m.useModule(BatchVerifierModule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,36 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { buildModule } from '@nomicfoundation/hardhat-ignition/modules';
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import {
SmtLibModule,
DepositVerifierModule,
WithdrawNullifierVerifierModule,
} from './lib/deps';
} from "./lib/deps";

const VerifierModule = buildModule(
'Groth16Verifier_AnonEncNullifierNonRepudiation',
"Groth16Verifier_AnonEncNullifierNonRepudiation",
(m) => {
const verifier = m.contract(
'Groth16Verifier_AnonEncNullifierNonRepudiation',
"Groth16Verifier_AnonEncNullifierNonRepudiation",
[],
);
return { verifier };
},
);

const BatchVerifierModule = buildModule(
'Groth16Verifier_AnonEncNullifierNonRepudiationBatch',
"Groth16Verifier_AnonEncNullifierNonRepudiationBatch",
(m) => {
const verifier = m.contract(
'Groth16Verifier_AnonEncNullifierNonRepudiationBatch',
"Groth16Verifier_AnonEncNullifierNonRepudiationBatch",
[],
);
return { verifier };
},
);

export default buildModule('Zeto_AnonEncNullifierNonRepudiation', (m) => {
export default buildModule("Zeto_AnonEncNullifierNonRepudiation", (m) => {
const { smtLib, poseidon3 } = m.useModule(SmtLibModule);
const { verifier } = m.useModule(VerifierModule);
const { verifier: batchVerifier } = m.useModule(BatchVerifierModule);
Expand Down
Loading

0 comments on commit 6879293

Please sign in to comment.