Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vbridge package #66

Merged
merged 4 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
674 changes: 674 additions & 0 deletions packages/vbridge/LICENSE

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions packages/vbridge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<h1 align="center">Webb Solidity Tokens</h1>

This sub-module is for defining variable-bridge (vbridge) functionality in webb solidity.

## License

<sup>
Licensed under <a href="LICENSE">GPLV3 license</a>.
</sup>

<br/>

<sub>
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this crate by you, as defined in the GPLV3 license, shall
be licensed as above, without any additional terms or conditions.
</sub>

163 changes: 0 additions & 163 deletions packages/vbridge/index.ts

This file was deleted.

34 changes: 34 additions & 0 deletions packages/vbridge/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@webb-tools/vbridge",
"main": "./lib/index.js",
"license": "GPL-3.0-or-later",
"author": "Webb Developers <drew@webb.tools>",
"scripts": {
"build": "yarn run clean && yarn run compile",
"clean": "rimraf -rf ./lib",
"compile": "tsc -p tsconfig.build.json"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "2.0.2",
"hardhat": "^2.6.8"
},
"dependencies": {
"@webb-tools/contracts": "^0.0.1",
"@webb-tools/tokens": "^0.0.1",
"@webb-tools/utils": "^0.0.1",
"circomlibjs": "^0.0.8",
"ethers": "5.5.1",
"ffjavascript": "^0.2.38",
"snarkjs": "0.4.10"
},
"publishConfig": {
"access": "public"
},
"repository": {
"directory": "packages/vbridge",
"type": "git",
"url": "git://github.com/webb-tools/protocol-solidity.git"
},
"version": "0.0.1"
}

35 changes: 35 additions & 0 deletions packages/vbridge/src/AnchorHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ethers } from "ethers";
import { AnchorHandler as AnchorHandlerContract, AnchorHandler__factory } from '@webb-tools/contracts';

export class AnchorHandler {
contract: AnchorHandlerContract;

constructor(
contract: AnchorHandlerContract
) {
this.contract = contract;
}

public static async createAnchorHandler(
bridgeAddress: string,
initResourceIds: string[],
initContractAddresses: string[],
deployer: ethers.Signer
) {
const factory = new AnchorHandler__factory(deployer);
const contract = await factory.deploy(bridgeAddress, initResourceIds, initContractAddresses);
await contract.deployed();

const handler = new AnchorHandler(contract);
return handler;
}

public static async connect(
handlerAddress: string,
signer: ethers.Signer,
) {
const handlerContract = AnchorHandler__factory.connect(handlerAddress, signer);
const handler = new AnchorHandler(handlerContract);
return handler;
}
}
File renamed without changes.
16 changes: 8 additions & 8 deletions packages/vbridge/VAnchor.ts → packages/vbridge/src/VAnchor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BigNumber, BigNumberish, ethers } from "ethers";
import { VAnchor as VAnchorContract, VAnchor__factory, VAnchorEncodeInputs__factory } from '@webb-tools/contracts';
import { p256, toHex } from "../utils";
import { p256, toHex } from '@webb-tools/utils';
import { MerkleTree } from './MerkleTree';
import { RootInfo } from ".";
import { FIELD_SIZE, getExtDataHash, toFixedHex } from "./utils";
Expand Down Expand Up @@ -85,7 +85,7 @@ function checkNativeAddress(tokenAddress: string): boolean {
// It represents a deployed contract throughout its life (e.g. maintains merkle tree state)
// Functionality relevant to anchors in general (proving, verifying) is implemented in static methods
// Functionality relevant to a particular anchor deployment (deposit, withdraw) is implemented in instance methods
class VAnchor {
export class VAnchor {
signer: ethers.Signer;
contract: VAnchorContract;
tree: MerkleTree;
Expand Down Expand Up @@ -124,26 +124,26 @@ class VAnchor {
case 1:
this.smallCircuitWASMPath = 'protocol-solidity-fixtures/fixtures/vanchor_2/2/poseidon_vanchor_2_2.wasm';
this.smallCircuitZkeyPath = 'protocol-solidity-fixtures/fixtures/vanchor_2/2/circuit_final.zkey';
this.smallWitnessCalculator = require("../../protocol-solidity-fixtures/fixtures/vanchor_2/2/witness_calculator.js");
this.smallWitnessCalculator = require("../../../protocol-solidity-fixtures/fixtures/vanchor_2/2/witness_calculator.js");
this.largeCircuitWASMPath = 'protocol-solidity-fixtures/fixtures/vanchor_16/2/poseidon_vanchor_16_2.wasm';
this.largeCircuitZkeyPath = 'protocol-solidity-fixtures/fixtures/vanchor_16/2/circuit_final.zkey';
this.largeWitnessCalculator = require("../../protocol-solidity-fixtures/fixtures/vanchor_16/2/witness_calculator.js");
this.largeWitnessCalculator = require("../../../protocol-solidity-fixtures/fixtures/vanchor_16/2/witness_calculator.js");
break;
case 7:
this.smallCircuitWASMPath = 'protocol-solidity-fixtures/fixtures/vanchor_2/8/poseidon_vanchor_8_2.wasm';
this.smallCircuitZkeyPath = 'protocol-solidity-fixtures/fixtures/vanchor_2/8/circuit_final.zkey';
this.smallWitnessCalculator = require("../../protocol-solidity-fixtures/fixtures/vanchor_2/8/witness_calculator.js");
this.smallWitnessCalculator = require("../../../protocol-solidity-fixtures/fixtures/vanchor_2/8/witness_calculator.js");
this.largeCircuitWASMPath = 'protocol-solidity-fixtures/fixtures/vanchor_16/8/poseidon_vanchor_16_8.wasm';
this.largeCircuitZkeyPath = 'protocol-solidity-fixtures/fixtures/vanchor_16/8/circuit_final.zkey';
this.largeWitnessCalculator = require("../../protocol-solidity-fixtures/fixtures/vanchor_16/8/witness_calculator.js");
this.largeWitnessCalculator = require("../../../protocol-solidity-fixtures/fixtures/vanchor_16/8/witness_calculator.js");
break;
default:
this.smallCircuitWASMPath = 'protocol-solidity-fixtures/fixtures/vanchor_2/2/poseidon_vanchor_2_2.wasm';
this.smallCircuitZkeyPath = 'protocol-solidity-fixtures/fixtures/vanchor_2/2/circuit_final.zkey';
this.smallWitnessCalculator = require("../../protocol-solidity-fixtures/fixtures/vanchor_2/2/witness_calculator.js");
this.smallWitnessCalculator = require("../../../protocol-solidity-fixtures/fixtures/vanchor_2/2/witness_calculator.js");
this.largeCircuitWASMPath = 'protocol-solidity-fixtures/fixtures/vanchor_16/2/poseidon_vanchor_16_2.wasm';
this.largeCircuitZkeyPath = 'protocol-solidity-fixtures/fixtures/vanchor_16/2/circuit_final.zkey';
this.largeWitnessCalculator = require("../../protocol-solidity-fixtures/fixtures/vanchor_16/2/witness_calculator.js");
this.largeWitnessCalculator = require("../../../protocol-solidity-fixtures/fixtures/vanchor_16/2/witness_calculator.js");
break;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers, BigNumber, BigNumberish } from "ethers";
import VBridgeSide from './VBridgeSide';
import VAnchor from './VAnchor';
import { AnchorHandler } from "@webb-tools/fixed-bridge";
import { AnchorHandler } from "./AnchorHandler";
import { MintableToken, GovernedTokenWrapper } from "@webb-tools/tokens";
import { PoseidonT3__factory } from "@webb-tools/contracts";
import Verifier from "./Verifier";
Expand Down Expand Up @@ -78,7 +78,7 @@ function checkNativeAddress(tokenAddress: string): boolean {
}

// A bridge is
class VBridge {
export class VBridge {
private constructor(
// Mapping of chainId => vBridgeSide
public vBridgeSides: Map<number, VBridgeSide>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ethers } from "ethers";
import { Bridge } from '../../typechain/Bridge';
import { Bridge, Bridge__factory } from '@webb-tools/contracts';
import VAnchor from './VAnchor';
import { Bridge__factory } from '../../typechain/factories/Bridge__factory';
import { AnchorHandler } from "@webb-tools/fixed-bridge";
import { AnchorHandler } from "./AnchorHandler";

type Proposal = {
data: string,
Expand All @@ -12,7 +11,7 @@ type Proposal = {
leafIndex: number,
}

class VBridgeSide {
export class VBridgeSide {
contract: Bridge;
admin: ethers.Signer;
handler: AnchorHandler | null;
Expand Down
17 changes: 10 additions & 7 deletions packages/vbridge/Verifier.ts → packages/vbridge/src/Verifier.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { ethers } from "ethers";
import { VAnchorVerifier__factory } from '../../typechain/factories/VAnchorVerifier__factory';
import { Verifier22__factory } from '../../typechain/factories/Verifier22__factory';
import { Verifier82__factory } from '../../typechain/factories/Verifier82__factory';
import { Verifier216__factory } from '../../typechain/factories/Verifier216__factory';
import { Verifier816__factory } from '../../typechain/factories/Verifier816__factory';
import { VAnchorVerifier as VerifierContract} from '../../typechain/VAnchorVerifier';

import {
VAnchorVerifier__factory,
Verifier22__factory,
Verifier82__factory,
Verifier216__factory,
Verifier816__factory,
VAnchorVerifier as VerifierContract
} from '@webb-tools/contracts'

// This convenience wrapper class is used in tests -
// It represents a deployed contract throughout its life (e.g. maintains all verifiers)
class Verifier {
export class Verifier {
signer: ethers.Signer;
contract: VerifierContract;

Expand Down
13 changes: 13 additions & 0 deletions packages/vbridge/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export { VAnchor } from './VAnchor';
export { VBridge, BridgeConfig, VBridgeInput, DeployerConfig, ExistingAssetInput} from './VBridge';
export { VBridgeSide } from './VBridgeSide';
export { MerkleTree } from './MerkleTree';
export { Verifier } from './Verifier';
export { Utxo } from './utxo';
export {poseidonHash2, poseidonHash} from './utils';

import { BigNumberish } from 'ethers';
export interface RootInfo {
merkleRoot: BigNumberish;
chainId: BigNumberish;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions packages/vbridge/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"outDir": "./lib/",
},
"extends": "../../tsconfig.build.json",
"include": [
"src/**/*.ts",
]
}
3 changes: 3 additions & 0 deletions packages/vbridge/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig.json"
}
Loading