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

Lock states #110

Merged
merged 14 commits into from
Dec 17, 2024
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
2 changes: 1 addition & 1 deletion go-sdk/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ require (
github.com/iden3/go-rapidsnark/types v0.0.2 // indirect
github.com/iden3/go-rapidsnark/witness/v2 v2.0.0
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
golang.org/x/crypto v0.30.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/sys v0.28.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/postgres v1.5.9
Expand Down
2 changes: 2 additions & 0 deletions go-sdk/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ github.com/x-cray/logrus-prefixed-formatter v0.5.2 h1:00txxvfBM9muc0jiLIEAkAcIMJ
github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE=
golang.org/x/crypto v0.30.0 h1:RwoQn3GkWiMkzlX562cLB7OxWvjH1L8xutO2WoJcRoY=
golang.org/x/crypto v0.30.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
Expand Down
14 changes: 7 additions & 7 deletions go-sdk/integration-test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (s *E2ETestSuite) TearDownSuite() {
assert.NoError(s.T(), err)
}

func (s *E2ETestSuite) TestZeto_1_SuccessfulProving() {
func (s *E2ETestSuite) TestZeto_anon_SuccessfulProving() {
calc, provingKey, err := loadCircuit("anon")
assert.NoError(s.T(), err)
assert.NotNil(s.T(), calc)
Expand Down Expand Up @@ -193,7 +193,7 @@ func (s *E2ETestSuite) TestZeto_1_SuccessfulProving() {
assert.Equal(s.T(), 4, len(proof.PubSignals))
}

func (s *E2ETestSuite) TestZeto_2_SuccessfulProving() {
func (s *E2ETestSuite) TestZeto_anon_enc_SuccessfulProving() {
calc, provingKey, err := loadCircuit("anon_enc")
assert.NoError(s.T(), err)
assert.NotNil(s.T(), calc)
Expand Down Expand Up @@ -271,7 +271,7 @@ func (s *E2ETestSuite) TestZeto_2_SuccessfulProving() {
assert.Equal(s.T(), output1.String(), calculatedHash.String())
}

func (s *E2ETestSuite) TestZeto_3_SuccessfulProving() {
func (s *E2ETestSuite) TestZeto_anon_nullifier_SuccessfulProving() {
calc, provingKey, err := loadCircuit("anon_nullifier")
assert.NoError(s.T(), err)
assert.NotNil(s.T(), calc)
Expand Down Expand Up @@ -355,7 +355,7 @@ func (s *E2ETestSuite) TestZeto_3_SuccessfulProving() {
assert.Equal(s.T(), 7, len(proof.PubSignals))
}

func (s *E2ETestSuite) TestZeto_4_SuccessfulProving() {
func (s *E2ETestSuite) TestZeto_anon_enc_nullifier_SuccessfulProving() {
calc, provingKey, err := loadCircuit("anon_enc_nullifier")
assert.NoError(s.T(), err)
assert.NotNil(s.T(), calc)
Expand Down Expand Up @@ -444,7 +444,7 @@ func (s *E2ETestSuite) TestZeto_4_SuccessfulProving() {
assert.Equal(s.T(), 18, len(proof.PubSignals))
}

func (s *E2ETestSuite) TestZeto_5_SuccessfulProving() {
func (s *E2ETestSuite) TestZeto_nf_anon_SuccessfulProving() {
calc, provingKey, err := loadCircuit("nf_anon")
assert.NoError(s.T(), err)
assert.NotNil(s.T(), calc)
Expand Down Expand Up @@ -503,7 +503,7 @@ func (s *E2ETestSuite) TestZeto_5_SuccessfulProving() {

}

func (s *E2ETestSuite) TestZeto_5_SuccessfulProvingWithConcurrency() {
func (s *E2ETestSuite) TestZeto_nf_anon_SuccessfulProvingWithConcurrency() {
concurrency := 10
resultChan := make(chan struct{}, concurrency)

Expand Down Expand Up @@ -582,7 +582,7 @@ func (s *E2ETestSuite) TestZeto_5_SuccessfulProvingWithConcurrency() {

}

func (s *E2ETestSuite) TestZeto_6_SuccessfulProving() {
func (s *E2ETestSuite) TestZeto_nf_anon_nullifier_SuccessfulProving() {
calc, provingKey, err := loadCircuit("nf_anon_nullifier")
assert.NoError(s.T(), err)
assert.NotNil(s.T(), calc)
Expand Down
25 changes: 21 additions & 4 deletions solidity/contracts/factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pragma solidity ^0.8.20;

import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IZetoFungibleInitializable} from "./lib/interfaces/zeto_fungible_initializable.sol";
import {IZetoNonFungibleInitializable} from "./lib/interfaces/zeto_nf_initializable.sol";
import {IZetoFungibleInitializable} from "./lib/interfaces/izeto_fungible_initializable.sol";
import {IZetoNonFungibleInitializable} from "./lib/interfaces/izeto_nf_initializable.sol";

contract ZetoTokenFactory is Ownable {
// all the addresses needed by the factory to
Expand All @@ -29,9 +29,11 @@ contract ZetoTokenFactory is Ownable {
address implementation;
address depositVerifier;
address withdrawVerifier;
address lockVerifier;
address verifier;
address batchVerifier;
address batchWithdrawVerifier;
address batchLockVerifier;
}

event ZetoTokenDeployed(address indexed zetoToken);
Expand Down Expand Up @@ -84,6 +86,14 @@ contract ZetoTokenFactory is Ownable {
args.batchWithdrawVerifier != address(0),
"Factory: batchWithdrawVerifier address is required"
);
require(
args.lockVerifier != address(0),
"Factory: lockVerifier address is required"
);
require(
args.batchLockVerifier != address(0),
"Factory: batchLockVerifier address is required"
);
address instance = Clones.clone(args.implementation);
require(
instance != address(0),
Expand All @@ -95,7 +105,9 @@ contract ZetoTokenFactory is Ownable {
args.depositVerifier,
args.withdrawVerifier,
args.batchVerifier,
args.batchWithdrawVerifier
args.batchWithdrawVerifier,
args.lockVerifier,
args.batchLockVerifier
);
emit ZetoTokenDeployed(instance);
return instance;
Expand All @@ -110,14 +122,19 @@ contract ZetoTokenFactory is Ownable {
args.implementation != address(0),
"Factory: failed to find implementation"
);
require(
args.lockVerifier != address(0),
"Factory: lockVerifier address is required"
);
address instance = Clones.clone(args.implementation);
require(
instance != address(0),
"Factory: failed to clone implementation"
);
(IZetoNonFungibleInitializable(instance)).initialize(
initialOwner,
args.verifier
args.verifier,
args.lockVerifier
);
emit ZetoTokenDeployed(instance);
return instance;
Expand Down
3 changes: 3 additions & 0 deletions solidity/contracts/lib/interfaces/izeto_base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ interface IZetoBase {
address indexed submitter,
bytes data
);
error UTXONotMinted(uint256 utxo);
error UTXOAlreadyOwned(uint256 utxo);
error UTXOAlreadySpent(uint256 utxo);
}
22 changes: 22 additions & 0 deletions solidity/contracts/lib/interfaces/izeto_common.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pragma solidity ^0.8.20;

uint256 constant MAX_BATCH = 10;
interface IZetoCommon {
error UTXODuplicate(uint256 utxo);
error UTXOArrayTooLarge(uint256 maxAllowed);
}
4 changes: 1 addition & 3 deletions solidity/contracts/lib/interfaces/izeto_encrypted.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
// limitations under the License.
pragma solidity ^0.8.20;

import {IZetoBase} from "./izeto_base.sol";

interface IZetoEncrypted is IZetoBase {
interface IZetoEncrypted {
event UTXOTransferWithEncryptedValues(
uint256[] inputs,
uint256[] outputs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ interface IZetoFungibleInitializable {
address _withdrawVerifier,
address _verifier,
address _batchVerifier,
address _batchWithdrawVerifier
address _batchWithdrawVerifier,
address _lockVerifier,
address _batchLockVerifier
) external;
}
46 changes: 46 additions & 0 deletions solidity/contracts/lib/interfaces/izeto_lockable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
pragma solidity ^0.8.20;

import {Commonlib} from "../common.sol";

interface IZetoLockable {
error UTXOAlreadyLocked(uint256 utxo);
event UTXOsLocked(
uint256[] utxos,
address indexed delegate,
address indexed submitter,
bytes data
);
}

interface ILockVerifier {
function verifyProof(
uint[2] calldata _pA,
uint[2][2] calldata _pB,
uint[2] calldata _pC,
uint[2] calldata _pubSignals
) external view returns (bool);
}

interface IBatchLockVerifier {
function verifyProof(
uint[2] calldata _pA,
uint[2][2] calldata _pB,
uint[2] calldata _pC,
uint[10] calldata _pubSignals
) external view returns (bool);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@
pragma solidity ^0.8.20;

interface IZetoNonFungibleInitializable {
function initialize(address initialOwner, address _verifier) external;
function initialize(
address initialOwner,
address _verifier,
address _lockVerifier
) external;
}
Loading
Loading