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

Confidential Transfers feature draft PR #1899

Draft
wants to merge 44 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
3932623
ciphertext example type
dssei Oct 16, 2024
331b7dd
fix linting errors
dssei Oct 16, 2024
ab675e2
commit generated code
dssei Oct 16, 2024
acb87fc
codec + some validation + routing
dssei Oct 16, 2024
bac7c92
adding zk related objects
dssei Oct 17, 2024
8da1dff
tests
dssei Oct 17, 2024
189385e
remove challenge from ciphertext validity proof
dssei Oct 17, 2024
ce03984
revert params.pb.go
dssei Oct 17, 2024
115d3fc
Fix test to use correct result object for proofs. Add range proofs
dssei Oct 29, 2024
de825de
Add decryption test
dssei Oct 29, 2024
4dc2d16
revert params.pb.go
dssei Oct 29, 2024
d31e50a
merge with main
dssei Oct 29, 2024
5b28a39
update go.mod
dssei Oct 29, 2024
98d8458
RemainingBalanceEqualityProof
dssei Oct 29, 2024
dc1935e
TransferAmountLoEqualityProof & TransferAmountHiEqualityProof tests
dssei Oct 29, 2024
a414e5c
fix formatting
dssei Oct 29, 2024
c81ba5d
add missing validations
dssei Oct 29, 2024
7f5379c
auditors
dssei Oct 30, 2024
5ac3ad6
add marshalling/unmarshalling of the messages
dssei Oct 30, 2024
19ac6a1
merge
dssei Oct 30, 2024
b40eafb
go mod tidy
dssei Oct 30, 2024
bfeccba
fix linting issues
dssei Oct 30, 2024
18bc131
add more tests
dssei Oct 30, 2024
7e4fe72
tests for zk.go
dssei Oct 30, 2024
a9e6ad5
more tests
dssei Oct 30, 2024
6ec024a
Scaffolding (#1916)
mj850 Nov 1, 2024
f68d3be
CT types - Apply balance close account (#1919)
dssei Nov 4, 2024
169c150
Add Deposit and InitializeAccount types (#1921)
mj850 Nov 5, 2024
94dce54
Genesis draft (#1924)
dssei Nov 7, 2024
b6ed1a7
Ct queries (#1927)
dssei Nov 12, 2024
27b032b
Add msg_server methods (#1923)
mj850 Nov 13, 2024
3c23484
basic cli and first draft command for ct module (#1929)
dssei Nov 14, 2024
f8e5fac
Add confidential transfer queries to seid (#1931)
mj850 Nov 15, 2024
b7eda30
Update confidential transfers swagger/openAPI spec (#1937)
dssei Nov 18, 2024
08c7505
Add other confidential tx methods to seid (#1933)
mj850 Nov 19, 2024
395fac9
Ct ACL mappings (#1947)
dssei Nov 19, 2024
0be3625
Add query decrypted tx method to confidential transfers client (#1950)
mj850 Nov 21, 2024
3feeaa9
Add Integration tests for CT Module (#1958)
mj850 Nov 26, 2024
d56d863
add ct to load test framework (#1959)
dssei Dec 3, 2024
ad638fd
Use BigInt in CT Module (#1966)
mj850 Dec 3, 2024
330b9fc
Manually consume gas for expensive txes and add params (#1972)
mj850 Dec 6, 2024
ead2625
refactor ct cli to use SDK coin format (#1977)
dssei Dec 6, 2024
51dda95
Use updated CachedRangeVerifier (#1975)
mj850 Dec 6, 2024
21ae7f4
Change decryptable account proto field type to uint64 for consistent …
dssei Dec 6, 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
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