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

Zeto lock support #545

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
0a054a3
support the expected v0.0.12 Zeto release
jimthematrix Jan 29, 2025
742e24a
support the new lock() method
jimthematrix Jan 29, 2025
844361c
Merge branch 'main' into zeto-lock
jimthematrix Jan 29, 2025
ccffb16
rely on config for knowledge about circuit behavior; support renamed …
jimthematrix Jan 30, 2025
6ec726f
fix integration test pvp
jimthematrix Jan 30, 2025
37e8738
update operator menifest for zeto contracts
jimthematrix Jan 31, 2025
968ebe8
Merge branch 'main' into zeto-lock
jimthematrix Jan 31, 2025
90d77d6
fix zeto solidity module path
jimthematrix Jan 31, 2025
dd904ed
Merge branch 'main' into zeto-lock
jimthematrix Jan 31, 2025
84a746a
update solidity/package-lock.json
jimthematrix Jan 31, 2025
0350aee
fix the zeto domain CRD
jimthematrix Jan 31, 2025
4fc1006
init domain instance config
jimthematrix Feb 4, 2025
57e2c5c
fix verifiers order to conform to the factory contract ABI
jimthematrix Feb 5, 2025
f7f1a4b
Merge branch 'main' into zeto-lock
jimthematrix Feb 5, 2025
5035aed
add support for transferLocked
jimthematrix Feb 6, 2025
a164ec8
complete the transferLocked call after the prepare
jimthematrix Feb 6, 2025
67f30bc
add lock() and transferLocked() to operator e2e test
jimthematrix Feb 7, 2025
ccacca5
add handling of locked outputs
jimthematrix Feb 10, 2025
e0edd98
remove unnecessary query object in test helper
jimthematrix Feb 10, 2025
12a7f06
update pvp_test with the new zeto locking
jimthematrix Feb 10, 2025
b252b4b
Merge branch 'main' into zeto-lock
jimthematrix Feb 10, 2025
351f9e2
add copyZetoSolidity as dependency for operator:make
jimthematrix Feb 10, 2025
15a4627
temporarily lower the zeto coverage threshold
jimthematrix Feb 10, 2025
13ea838
update error msg for missing queries states
jimthematrix Feb 10, 2025
fc817fa
fix error msg for input lookup
jimthematrix Feb 10, 2025
da40883
add unit tests
jimthematrix Feb 10, 2025
a41877b
test coverage
jimthematrix Feb 10, 2025
5408e3c
test coverage
jimthematrix Feb 10, 2025
5008d1d
add unit test for error cases in identityresolver
jimthematrix Feb 10, 2025
5773b4e
add coverage for identityresolve
jimthematrix Feb 11, 2025
26ac03f
add support for zeto lock(), delegateLock() and transferLocked()
jimthematrix Feb 12, 2025
757e622
fix the swap example with the zeto lock API
jimthematrix Feb 12, 2025
c1b9182
Merge branch 'main' into zeto-lock-merge
jimthematrix Feb 14, 2025
4532aa3
remove IsFungible from the circuit object
jimthematrix Feb 14, 2025
7a887c4
fix unit tests
jimthematrix Feb 14, 2025
acba236
differentiator prepare vs. send for transferLocked
jimthematrix Feb 14, 2025
be1b7cc
Merge branch 'main' into zeto-lock
jimthematrix Feb 14, 2025
8a16d15
fix sdk import
jimthematrix Feb 14, 2025
06daeff
Merge branch 'main' into zeto-lock
jimthematrix Feb 14, 2025
415d1d7
addressing review comments
jimthematrix Feb 18, 2025
17a18d6
Merge branch 'main' into zeto-lock
jimthematrix Feb 18, 2025
2e74dfc
Merge branch 'main' into zeto-lock
jimthematrix Feb 18, 2025
4316041
Merge branch 'main' into zeto-lock
jimthematrix Feb 18, 2025
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
56 changes: 21 additions & 35 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -209,44 +209,30 @@ task copyZetoZKPFiles(type: Copy) {
include 'anon_enc_batch-vkey.json'
include 'anon_enc_batch_js/anon_enc_batch.wasm'
// anon_nullifier
include 'anon_nullifier.zkey'
include 'anon_nullifier-vkey.json'
include 'anon_nullifier_js/anon_nullifier.wasm'
include 'anon_nullifier_batch.zkey'
include 'anon_nullifier_batch-vkey.json'
include 'anon_nullifier_batch_js/anon_nullifier_batch.wasm'
include 'anon_nullifier_transfer.zkey'
include 'anon_nullifier_transfer-vkey.json'
include 'anon_nullifier_transfer_js/anon_nullifier_transfer.wasm'
include 'anon_nullifier_transfer_batch.zkey'
include 'anon_nullifier_transfer_batch-vkey.json'
include 'anon_nullifier_transfer_batch_js/anon_nullifier_transfer_batch.wasm'
// deposit
include 'check_hashes_value.zkey'
include 'check_hashes_value-vkey.json'
include 'check_hashes_value_js/check_hashes_value.wasm'
include 'deposit.zkey'
include 'deposit-vkey.json'
include 'deposit_js/deposit.wasm'
// withdraw
include 'check_inputs_outputs_value.zkey'
include 'check_inputs_outputs_value-vkey.json'
include 'check_inputs_outputs_value_js/check_inputs_outputs_value.wasm'
include 'check_inputs_outputs_value_batch.zkey'
include 'check_inputs_outputs_value_batch-vkey.json'
include 'check_inputs_outputs_value_batch_js/check_inputs_outputs_value_batch.wasm'
include 'withdraw.zkey'
include 'withdraw-vkey.json'
include 'withdraw_js/withdraw.wasm'
include 'withdraw_batch.zkey'
include 'withdraw_batch-vkey.json'
include 'withdraw_batch_js/withdraw_batch.wasm'
// withdraw_nullifier
include 'check_nullifiers_value.zkey'
include 'check_nullifiers_value-vkey.json'
include 'check_nullifiers_value_js/check_nullifiers_value.wasm'
include 'check_nullifiers_value_batch.zkey'
include 'check_nullifiers_value_batch-vkey.json'
include 'check_nullifiers_value_batch_js/check_nullifiers_value_batch.wasm'
// check_utxos_owner
include 'check_utxos_owner.zkey'
include 'check_utxos_owner-vkey.json'
include 'check_utxos_owner_js/check_utxos_owner.wasm'
include 'check_utxos_owner_batch.zkey'
include 'check_utxos_owner_batch-vkey.json'
include 'check_utxos_owner_batch_js/check_utxos_owner_batch.wasm'
// check_nullifiers_owner
include 'check_nullifiers_owner.zkey'
include 'check_nullifiers_owner-vkey.json'
include 'check_nullifiers_owner_js/check_nullifiers_owner.wasm'
include 'check_nullifiers_owner_batch.zkey'
include 'check_nullifiers_owner_batch-vkey.json'
include 'check_nullifiers_owner_batch_js/check_nullifiers_owner_batch.wasm'
include 'withdraw_nullifier.zkey'
include 'withdraw_nullifier-vkey.json'
include 'withdraw_nullifier_js/withdraw_nullifier.wasm'
include 'withdraw_nullifier_batch.zkey'
include 'withdraw_nullifier_batch-vkey.json'
include 'withdraw_nullifier_batch_js/withdraw_nullifier_batch.wasm'
}
into zetoZkpDir

Expand Down
53 changes: 53 additions & 0 deletions core/go/internal/identityresolver/identityresolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,64 @@ package identityresolver
import (
"context"
"testing"
"time"

"github.com/kaleido-io/paladin/config/pkg/pldconf"
"github.com/kaleido-io/paladin/core/mocks/componentmocks"
"github.com/kaleido-io/paladin/toolkit/pkg/algorithms"
"github.com/kaleido-io/paladin/toolkit/pkg/cache"
"github.com/kaleido-io/paladin/toolkit/pkg/pldapi"
"github.com/kaleido-io/paladin/toolkit/pkg/verifiers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestResolveVerifier(t *testing.T) {
r := &identityResolver{}
_, err := r.ResolveVerifier(context.Background(), "something$bad", "bad algorithm", "bad type")
assert.ErrorContains(t, err, "PD020006: Locator string something$bad is invalid")

capacity := 100
config := &pldconf.CacheConfig{Capacity: &capacity}
r = &identityResolver{
nodeName: "testnode",
verifierCache: cache.NewCache[string, string](config, config),
keyManager: componentmocks.NewKeyManager(t),
}
waitChan := make(chan time.Time)
resolvedKey := &pldapi.KeyMappingAndVerifier{
Verifier: &pldapi.KeyVerifier{
Verifier: "0x1234567890abcdef",
Type: "ETH_ADDRESS",
},
}
r.keyManager.(*componentmocks.KeyManager).On("ResolveKeyNewDatabaseTX", mock.Anything, mock.Anything, mock.Anything, mock.Anything).WaitUntil(waitChan).Return(resolvedKey, nil)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Millisecond)
defer func() {
cancel()
close(waitChan)
}()

done := make(chan bool)
go func() {
_, err := r.ResolveVerifier(ctx, "something@testnode", algorithms.Curve_SECP256K1, verifiers.ETH_ADDRESS)
assert.ErrorContains(t, err, "PD010301: Context canceled")
done <- true
}()
<-done
}

func TestResolveVerifierAsync(t *testing.T) {
r := &identityResolver{}
resolved := func(ctx context.Context, verifier string) {
t.Logf("Resolved verifier: %s", verifier)
}
errhandler := func(ctx context.Context, err error) {
assert.ErrorContains(t, err, "PD020006: Locator string something$bad is invalid")
}
r.ResolveVerifierAsync(context.Background(), "something$bad", "bad algorithm", "bad type", resolved, errhandler)
}

func TestNewIdentityResolver(t *testing.T) {
capacity := 100
ctx := context.Background()
Expand Down
45 changes: 43 additions & 2 deletions domains/integration-test/helpers/zeto_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ package helpers
import (
"context"
_ "embed"
"encoding/json"
"testing"

"github.com/kaleido-io/paladin/core/pkg/testbed"
"github.com/kaleido-io/paladin/domains/zeto/pkg/types"
"github.com/kaleido-io/paladin/toolkit/pkg/pldapi"
"github.com/kaleido-io/paladin/toolkit/pkg/rpcclient"
"github.com/kaleido-io/paladin/toolkit/pkg/solutils"
"github.com/kaleido-io/paladin/toolkit/pkg/tktypes"
"github.com/stretchr/testify/assert"
)

//go:embed abis/Zeto_Anon.json
var ZetoAnonABIJSON []byte

type ZetoHelper struct {
t *testing.T
rpc rpcclient.Client
Expand Down Expand Up @@ -82,14 +89,48 @@ func (n *ZetoHelperFungible) Transfer(ctx context.Context, to string, amount uin
}))
}

func (z *ZetoHelperFungible) Lock(ctx context.Context, delegate *tktypes.EthAddress, call []byte) *DomainTransactionHelper {
func (n *ZetoHelper) TransferLocked(ctx context.Context, lockedUtxo *tktypes.HexUint256, delegate string, to string, amount uint64) *DomainTransactionHelper {
fn := types.ZetoFungibleABI.Functions()["transferLocked"]
return NewDomainTransactionHelper(ctx, n.t, n.rpc, n.Address, fn, toJSON(n.t, &types.FungibleTransferLockedParams{
LockedInputs: []*tktypes.HexUint256{lockedUtxo},
Delegate: delegate,
Transfers: []*types.FungibleTransferParamEntry{
{
To: to,
Amount: tktypes.Uint64ToUint256(amount),
},
},
}))
}

func (z *ZetoHelper) Lock(ctx context.Context, delegate *tktypes.EthAddress, amount int) *DomainTransactionHelper {
fn := types.ZetoFungibleABI.Functions()["lock"]
return NewDomainTransactionHelper(ctx, z.t, z.rpc, z.Address, fn, toJSON(z.t, &types.LockParams{
Delegate: delegate,
Call: call,
Amount: tktypes.Uint64ToUint256(uint64(amount)),
}))
}

func (z *ZetoHelper) DelegateLock(ctx context.Context, tb testbed.Testbed, lockedUtxo *tktypes.HexUint256, delegate *tktypes.EthAddress, sender string) {
txInput := map[string]any{
"utxos": []string{lockedUtxo.String()},
"delegate": delegate.String(),
"data": "0x",
}
txInputJson, _ := json.Marshal(txInput)
_, err := tb.ExecTransactionSync(ctx, &pldapi.TransactionInput{
TransactionBase: pldapi.TransactionBase{
Type: pldapi.TransactionTypePublic.Enum(),
From: sender,
To: z.Address,
Function: "delegateLock",
Data: txInputJson,
},
ABI: solutils.MustLoadBuild(ZetoAnonABIJSON).ABI,
})
assert.NoError(z.t, err)
}

// =============================================================================
//
// NonFungible
Expand Down
21 changes: 14 additions & 7 deletions domains/integration-test/pvp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,15 @@ func (s *pvpTestSuite) TestNotoForZeto() {
require.NoError(t, err)

log.L(ctx).Infof("Prepare the Zeto transfer")
transferZeto := zeto.Transfer(ctx, alice, 1).Prepare(bob)
zeto.Lock(ctx, tktypes.MustEthAddress(bobKey.Verifier.Verifier), transferZeto.EncodedCall).SignAndSend(bob).Wait()
zeto.Lock(ctx, tktypes.MustEthAddress(bobKey.Verifier.Verifier), 1).SignAndSend(bob).Wait()

jq := query.NewQueryBuilder().Limit(100).Equal("locked", true).Query()
lockedZetoCoins := findAvailableCoins(t, ctx, rpc, zetoDomain.Name(), zetoDomain.CoinSchemaID(), zeto.Address, jq, func(coins []*zetotypes.ZetoCoinState) bool {
return len(coins) >= 1
})
lockedZeto, _ := lockedZetoCoins[0].Data.Hash(ctx)

transferZeto := zeto.TransferLocked(ctx, lockedZeto, bobKey.Verifier.Verifier, alice, 1).Prepare(bob)

// TODO: this should actually be a Pente state transition
log.L(ctx).Infof("Prepare the trade execute")
Expand Down Expand Up @@ -488,7 +495,7 @@ func (s *pvpTestSuite) TestNotoForZeto() {
Unlock: unlockParams,
Delegate: transferAtom.Address,
}).SignAndSend(alice).Wait()
zeto.Lock(ctx, transferAtom.Address, transferZeto.EncodedCall).SignAndSend(bob).Wait()
zeto.DelegateLock(ctx, tb, lockedZeto, transferAtom.Address, bobKey.Identifier)

log.L(ctx).Infof("Execute the atomic operation")
sent = transferAtom.Execute(ctx).SignAndSend(alice).Wait(5 * time.Second)
Expand All @@ -508,9 +515,9 @@ func (s *pvpTestSuite) TestNotoForZeto() {
zetoCoins = findAvailableCoins[zetotypes.ZetoCoinState](t, ctx, rpc, zetoDomain.Name(), zetoDomain.CoinSchemaID(), zeto.Address, nil)
require.NoError(t, err)
require.Len(t, zetoCoins, 2)
assert.Equal(t, int64(1), zetoCoins[0].Data.Amount.Int().Int64())
assert.Equal(t, int64(1), zetoCoins[1].Data.Amount.Int().Int64())
alicesKey := resolveZetoKey(t, ctx, rpc, zetoDomain.Name(), alice)
assert.Equal(t, alicesKey, zetoCoins[0].Data.Owner.String())
assert.Equal(t, int64(9), zetoCoins[1].Data.Amount.Int().Int64())
assert.Equal(t, bobsKey, zetoCoins[1].Data.Owner.String())
assert.Equal(t, alicesKey, zetoCoins[1].Data.Owner.String())
assert.Equal(t, int64(9), zetoCoins[0].Data.Amount.Int().Int64())
assert.Equal(t, bobsKey, zetoCoins[0].Data.Owner.String())
}
38 changes: 20 additions & 18 deletions domains/integration-test/zeto/config-for-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,32 @@ contracts:
- name: Groth16Verifier_AnonBatch
abiAndBytecode:
path: ./helpers/abis/Groth16Verifier_AnonBatch.json
- name: Groth16Verifier_CheckHashesValue
- name: Groth16Verifier_Deposit
abiAndBytecode:
path: ./helpers/abis/Groth16Verifier_CheckHashesValue.json
- name: Groth16Verifier_CheckInputsOutputsValue
path: ./helpers/abis/Groth16Verifier_Deposit.json
- name: Groth16Verifier_Withdraw
abiAndBytecode:
path: ./helpers/abis/Groth16Verifier_CheckInputsOutputsValue.json
- name: Groth16Verifier_CheckInputsOutputsValueBatch
path: ./helpers/abis/Groth16Verifier_Withdraw.json
- name: Groth16Verifier_WithdrawBatch
abiAndBytecode:
path: ./helpers/abis/Groth16Verifier_CheckInputsOutputsValueBatch.json
- name: Groth16Verifier_CheckUtxosOwner
abiAndBytecode:
path: ./helpers/abis/Groth16Verifier_CheckUtxosOwner.json
- name: Groth16Verifier_CheckUtxosOwnerBatch
abiAndBytecode:
path: ./helpers/abis/Groth16Verifier_CheckUtxosOwnerBatch.json
path: ./helpers/abis/Groth16Verifier_WithdrawBatch.json
- name: Zeto_Anon
verifier: Groth16Verifier_Anon
batchVerifier: Groth16Verifier_AnonBatch
depositVerifier: Groth16Verifier_CheckHashesValue
withdrawVerifier: Groth16Verifier_CheckInputsOutputsValue
batchWithdrawVerifier: Groth16Verifier_CheckInputsOutputsValueBatch
lockVerifier: Groth16Verifier_CheckUtxosOwner
batchLockVerifier: Groth16Verifier_CheckUtxosOwnerBatch
circuitId: anon
depositVerifier: Groth16Verifier_Deposit
withdrawVerifier: Groth16Verifier_Withdraw
batchWithdrawVerifier: Groth16Verifier_WithdrawBatch
lockVerifier: Groth16Verifier_Anon
batchLockVerifier: Groth16Verifier_AnonBatch
circuits:
deposit:
name: deposit
withdraw:
name: withdraw
transfer:
name: anon
transferLocked:
name: anon
cloneable: true
abiAndBytecode:
path: ./helpers/abis/Zeto_Anon.json
4 changes: 2 additions & 2 deletions domains/zeto/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ ext {
goFilesE2E = fileTree(".") {
include "integration-test/**/*.go"
}
targetCoverage = 92.0
targetCoverage = 92.5 // temporary
maxCoverageBarGap = 1
coveragePackages = [
"github.com/kaleido-io/paladin/domains/zeto/internal/...",
"github.com/kaleido-io/paladin/domains/zeto/pkg/types",
"github.com/kaleido-io/paladin/domains/zeto/pkg/zetosigner",
]

zetoVersion = "v0.0.11"
zetoVersion = "v0.0.12"
zetoHost = "hyperledger-labs"
zkpOut = "${projectDir}/zkp"
toolsOut = "${projectDir}/tools"
Expand Down
Loading
Loading