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

Add Confidential Transfers Module #1980

Open
wants to merge 61 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
b667e02
ciphertext example type
dssei Oct 16, 2024
e6dab7b
fix linting errors
dssei Oct 16, 2024
4bd729e
commit generated code
dssei Oct 16, 2024
aad5138
codec + some validation + routing
dssei Oct 16, 2024
6797664
adding zk related objects
dssei Oct 17, 2024
592beb2
tests
dssei Oct 17, 2024
b33ad17
remove challenge from ciphertext validity proof
dssei Oct 17, 2024
a565c04
revert params.pb.go
dssei Oct 17, 2024
3333a06
Fix test to use correct result object for proofs. Add range proofs
dssei Oct 29, 2024
46aac3c
Add decryption test
dssei Oct 29, 2024
085deb9
RemainingBalanceEqualityProof
dssei Oct 29, 2024
675c39e
TransferAmountLoEqualityProof & TransferAmountHiEqualityProof tests
dssei Oct 29, 2024
3e15326
fix formatting
dssei Oct 29, 2024
8a73f57
add missing validations
dssei Oct 29, 2024
7f7550f
auditors
dssei Oct 30, 2024
a792340
add marshalling/unmarshalling of the messages
dssei Oct 30, 2024
81265bc
go mod tidy
dssei Oct 30, 2024
bcdb017
fix linting issues
dssei Oct 30, 2024
fd16a60
add more tests
dssei Oct 30, 2024
0775f98
tests for zk.go
dssei Oct 30, 2024
1b07386
more tests
dssei Oct 30, 2024
ee14d68
Scaffolding (#1916)
mj850 Nov 1, 2024
6129d89
CT types - Apply balance close account (#1919)
dssei Nov 4, 2024
71ad41a
Add Deposit and InitializeAccount types (#1921)
mj850 Nov 5, 2024
92bbcf5
Genesis draft (#1924)
dssei Nov 7, 2024
77c7fb4
Ct queries (#1927)
dssei Nov 12, 2024
094bf82
Add msg_server methods (#1923)
mj850 Nov 13, 2024
26a9971
basic cli and first draft command for ct module (#1929)
dssei Nov 14, 2024
6c66a70
Add confidential transfer queries to seid (#1931)
mj850 Nov 15, 2024
a7d5cc5
Update confidential transfers swagger/openAPI spec (#1937)
dssei Nov 18, 2024
c51f80d
Add other confidential tx methods to seid (#1933)
mj850 Nov 19, 2024
a45b042
Ct ACL mappings (#1947)
dssei Nov 19, 2024
435c029
Add query decrypted tx method to confidential transfers client (#1950)
mj850 Nov 21, 2024
9a565b8
Add Integration tests for CT Module (#1958)
mj850 Nov 26, 2024
fcfa23b
add ct to load test framework (#1959)
dssei Dec 3, 2024
193a429
Use BigInt in CT Module (#1966)
mj850 Dec 3, 2024
8f1b057
Manually consume gas for expensive txes and add params (#1972)
mj850 Dec 6, 2024
cb36ad7
refactor ct cli to use SDK coin format (#1977)
dssei Dec 6, 2024
03f7e49
Use updated CachedRangeVerifier (#1975)
mj850 Dec 6, 2024
2147df3
params revert
mj850 Dec 7, 2024
a04736a
fix deps
mj850 Dec 7, 2024
7f04330
Merge branch 'main' of github.com:sei-protocol/sei-chain into feature…
dssei Dec 9, 2024
49203d9
rollback evm params
dssei Dec 9, 2024
e5953b7
change pendingBalanceLo in decryptable account object
dssei Dec 6, 2024
06ab705
Bump coinbase crypto lib version (#1985)
dssei Dec 10, 2024
b18cbc9
Increase test coverage (#1986)
dssei Dec 11, 2024
2a61565
Merge branch 'main' into feature/ct_module
dssei Dec 11, 2024
2a81859
increase test time-out
dssei Dec 11, 2024
dccadcc
tests for VerifyAuditorProof
dssei Dec 11, 2024
3ea3b67
manual merge with main
dssei Dec 11, 2024
5ff5ab3
MsgInitializeAccount tests
dssei Dec 12, 2024
5e292e3
MsgTransfer#FromProto invalid inputs tests
dssei Dec 12, 2024
dd546bc
Merge branch 'main' of github.com:sei-protocol/sei-chain into feature…
dssei Dec 12, 2024
1f75a8e
- tests for transfer msg decrypt
dssei Dec 12, 2024
616733e
- tests for InitializeAccount invalid fields
dssei Dec 12, 2024
5073bd0
- tests for MsgInitializeAccount_Decrypt
dssei Dec 12, 2024
c1d2146
- tests for MsgApplyPendingBalance
dssei Dec 12, 2024
88dd53d
- tests for MsgWithdraw
dssei Dec 13, 2024
2b6bea0
- route and type message tests
dssei Dec 13, 2024
0999e20
Use Signed Message for Key Devrivation (#1981)
mj850 Dec 13, 2024
e19c16c
Consume gas before verifying range proof (#1987)
mj850 Dec 13, 2024
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
12 changes: 12 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- main
- seiv2
- evm
- feature/ct_types # Remove after done testing

defaults:
run:
Expand Down Expand Up @@ -122,6 +123,17 @@ jobs:
"./integration_test/evm_module/scripts/evm_interoperability_tests.sh"
]
},
{
name: "Confidential Transfers Module",
scripts: [
"python3 integration_test/scripts/runner.py integration_test/confidential_transfers_module/initialize_account_test.yaml",
"python3 integration_test/scripts/runner.py integration_test/confidential_transfers_module/deposit_test.yaml",
"python3 integration_test/scripts/runner.py integration_test/confidential_transfers_module/apply_pending_balance_test.yaml",
"python3 integration_test/scripts/runner.py integration_test/confidential_transfers_module/withdraw_test.yaml",
"python3 integration_test/scripts/runner.py integration_test/confidential_transfers_module/transfer_test.yaml",
"python3 integration_test/scripts/runner.py integration_test/confidential_transfers_module/close_account_test.yaml",
]
},
{
name: "dApp Tests",
scripts: [
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ docker-cluster-start-skipbuild: docker-cluster-stop build-docker-node
# Stop 4-node docker containers
docker-cluster-stop:
@cd docker && USERID=$(shell id -u) GROUPID=$(shell id -g) GOCACHE=$(shell go env GOCACHE) docker compose down
.PHONY: localnet-stop
.PHONY: localnet-stop ddd


# Implements test splitting and running. This is pulled directly from
Expand All @@ -227,4 +227,4 @@ $(BUILDDIR)/packages.txt:$(GO_TEST_FILES) $(BUILDDIR)
split-test-packages:$(BUILDDIR)/packages.txt
split -d -n l/$(NUM_SPLIT) $< $<.
test-group-%:split-test-packages
cat $(BUILDDIR)/packages.txt.$* | xargs go test -parallel 4 -mod=readonly -timeout=10m -race -coverprofile=$*.profile.out -covermode=atomic
cat $(BUILDDIR)/packages.txt.$* | xargs go test -parallel 4 -mod=readonly -timeout=12m -race -coverprofile=$*.profile.out -covermode=atomic
264 changes: 264 additions & 0 deletions aclmapping/confidentialtransfers/mappings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
package confidentialtransfers

import (
"encoding/hex"

banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol"
aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper"
acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types"
"github.com/sei-protocol/sei-chain/x/confidentialtransfers/types"
)

var ErrorInvalidMsgType = fmt.Errorf("invalid message received for confidential transfers module")

func GetConfidentialTransfersDependencyGenerators() aclkeeper.DependencyGeneratorMap {
dependencyGeneratorMap := make(aclkeeper.DependencyGeneratorMap)

initializeAccountMsgKey := acltypes.GenerateMessageKey(&types.MsgInitializeAccount{})
depositMsgKey := acltypes.GenerateMessageKey(&types.MsgDeposit{})
applyPendingBalanceMsgKey := acltypes.GenerateMessageKey(&types.MsgApplyPendingBalance{})
transferMsgKey := acltypes.GenerateMessageKey(&types.MsgTransfer{})
withdrawMsgKey := acltypes.GenerateMessageKey(&types.MsgWithdraw{})
closeAccountMsgKey := acltypes.GenerateMessageKey(&types.MsgCloseAccount{})

dependencyGeneratorMap[initializeAccountMsgKey] = MsgInitializeAccountDependencyGenerator
dependencyGeneratorMap[depositMsgKey] = MsgDepositDependencyGenerator
dependencyGeneratorMap[applyPendingBalanceMsgKey] = MsgApplyPendingBalanceDependencyGenerator
dependencyGeneratorMap[transferMsgKey] = MsgTransferDependencyGenerator
dependencyGeneratorMap[withdrawMsgKey] = MsgWithdrawDependencyGenerator
dependencyGeneratorMap[closeAccountMsgKey] = MsgCloseAccountDependencyGenerator

return dependencyGeneratorMap
}

func MsgInitializeAccountDependencyGenerator(_ aclkeeper.Keeper, _ sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) {
msgInitializeAccount, ok := msg.(*types.MsgInitializeAccount)
if !ok {
return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType
}

fromAddrIdentifier := hex.EncodeToString(types.GetAccountPrefixFromBech32(msgInitializeAccount.FromAddress))

accessOperations := []sdkacltypes.AccessOperation{
// Checks if the account already exists
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_CT_ACCOUNT,
IdentifierTemplate: fromAddrIdentifier,
},
// Created new account
{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_CT_ACCOUNT,
IdentifierTemplate: fromAddrIdentifier,
},

*acltypes.CommitAccessOp(),
}
return accessOperations, nil
}

func MsgDepositDependencyGenerator(aclkeeper aclkeeper.Keeper, _ sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) {
msgDeposit, ok := msg.(*types.MsgDeposit)
if !ok {
return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType
}

moduleAddress := aclkeeper.AccountKeeper.GetModuleAddress(types.ModuleName)

fromAddrIdentifier := hex.EncodeToString(types.GetAccountPrefixFromBech32(msgDeposit.FromAddress))

accessOperations := []sdkacltypes.AccessOperation{
// Gets account state
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_CT_ACCOUNT,
IdentifierTemplate: fromAddrIdentifier,
},
// Withdraws from sender's bank Balance
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES,
IdentifierTemplate: hex.EncodeToString(banktypes.CreateAccountBalancesPrefixFromBech32(msgDeposit.FromAddress)),
},
{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES,
IdentifierTemplate: hex.EncodeToString(banktypes.CreateAccountBalancesPrefixFromBech32(msgDeposit.FromAddress)),
},

// Transfer to module account
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES,
IdentifierTemplate: hex.EncodeToString(banktypes.CreateAccountBalancesPrefixFromBech32(moduleAddress.String())),
},
{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES,
IdentifierTemplate: hex.EncodeToString(banktypes.CreateAccountBalancesPrefixFromBech32(moduleAddress.String())),
},

// Modifies account state
{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_CT_ACCOUNT,
IdentifierTemplate: fromAddrIdentifier,
},

*acltypes.CommitAccessOp(),
}
return accessOperations, nil
}

func MsgApplyPendingBalanceDependencyGenerator(_ aclkeeper.Keeper, _ sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) {
msgApplyPendingBalance, ok := msg.(*types.MsgApplyPendingBalance)
if !ok {
return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType
}

fromAddrIdentifier := hex.EncodeToString(types.GetAccountPrefixFromBech32(msgApplyPendingBalance.Address))

accessOperations := []sdkacltypes.AccessOperation{
// Get account state
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_CT_ACCOUNT,
IdentifierTemplate: fromAddrIdentifier,
},
// Apply pending balance
{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_CT_ACCOUNT,
IdentifierTemplate: fromAddrIdentifier,
},

*acltypes.CommitAccessOp(),
}
return accessOperations, nil
}

func MsgTransferDependencyGenerator(_ aclkeeper.Keeper, _ sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) {
msgTransfer, ok := msg.(*types.MsgTransfer)
if !ok {
return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType
}

fromAddrIdentifier := hex.EncodeToString(types.GetAccountPrefixFromBech32(msgTransfer.FromAddress))
toAddrIdentifier := hex.EncodeToString(types.GetAccountPrefixFromBech32(msgTransfer.ToAddress))

accessOperations := []sdkacltypes.AccessOperation{
// Checks balance of sender
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_CT_ACCOUNT,
IdentifierTemplate: fromAddrIdentifier,
},
// Reduce the amount from the sender's balance
{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_CT_ACCOUNT,
IdentifierTemplate: fromAddrIdentifier,
},

// Checks balance for receiver
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_CT_ACCOUNT,
IdentifierTemplate: toAddrIdentifier,
},
// Increase the amount to the receiver's balance
{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_CT_ACCOUNT,
IdentifierTemplate: toAddrIdentifier,
},

*acltypes.CommitAccessOp(),
}
return accessOperations, nil
}

func MsgWithdrawDependencyGenerator(aclkeeper aclkeeper.Keeper, _ sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) {
msgWithdraw, ok := msg.(*types.MsgWithdraw)
if !ok {
return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType
}

moduleAddress := aclkeeper.AccountKeeper.GetModuleAddress(types.ModuleName)

addrIdentifier := hex.EncodeToString(types.GetAccountPrefixFromBech32(msgWithdraw.FromAddress))

accessOperations := []sdkacltypes.AccessOperation{
// Get account state
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_CT_ACCOUNT,
IdentifierTemplate: addrIdentifier,
},
// Withdraws from module's bank Balance
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES,
IdentifierTemplate: hex.EncodeToString(banktypes.CreateAccountBalancesPrefixFromBech32(moduleAddress.String())),
},
{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES,
IdentifierTemplate: hex.EncodeToString(banktypes.CreateAccountBalancesPrefixFromBech32(moduleAddress.String())),
},
// Transfer to user's bank Balance
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES,
IdentifierTemplate: hex.EncodeToString(banktypes.CreateAccountBalancesPrefixFromBech32(msgWithdraw.FromAddress)),
},
{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES,
IdentifierTemplate: hex.EncodeToString(banktypes.CreateAccountBalancesPrefixFromBech32(msgWithdraw.FromAddress)),
},

// Modifies account state
{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_CT_ACCOUNT,
IdentifierTemplate: addrIdentifier,
},

*acltypes.CommitAccessOp(),
}
return accessOperations, nil
}

func MsgCloseAccountDependencyGenerator(_ aclkeeper.Keeper, _ sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) {
msgCloseAccount, ok := msg.(*types.MsgCloseAccount)
if !ok {
return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType
}

fromAddrIdentifier := hex.EncodeToString(types.GetAccountPrefixFromBech32(msgCloseAccount.Address))

accessOperations := []sdkacltypes.AccessOperation{
// Get account state
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_CT_ACCOUNT,
IdentifierTemplate: fromAddrIdentifier,
},
// Close account
{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_CT_ACCOUNT,
IdentifierTemplate: fromAddrIdentifier,
},

*acltypes.CommitAccessOp(),
}
return accessOperations, nil
}
Loading
Loading