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

feat(v2.11): smart accounts #270

Open
wants to merge 70 commits into
base: release/v2.11
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
b50947e
create smartaccounts skeleton
freeelancer Feb 16, 2024
51510f6
added setting proto
freeelancer Feb 17, 2024
6cbcb55
added ante and post handlers
freeelancer Feb 18, 2024
deb83ca
created msg skeletons
freeelancer Feb 18, 2024
b0ddee5
added basic impl for msgserver
freeelancer Feb 18, 2024
27bebde
added genesis file
freeelancer Feb 18, 2024
e15310e
updated readme
freeelancer Feb 18, 2024
b6b8712
feat: added wasm interfaces
javiersuweijie Feb 20, 2024
f85d59b
added wasmkeeper
freeelancer Feb 20, 2024
84a6d23
able to call create-smart-account
freeelancer Feb 21, 2024
b80ca06
added setting query
freeelancer Feb 21, 2024
4de7aaf
fixed linting errors
freeelancer Feb 21, 2024
ae663b9
feat: added pre-txn hooks + testing framework
javiersuweijie Feb 21, 2024
515e46a
feat: store settings in ctx
javiersuweijie Feb 22, 2024
777132c
fix lint
freeelancer Feb 22, 2024
965500f
Merge pull request #264 from terra-money/feat/pre-transaction-hooks
freeelancer Feb 22, 2024
b65a038
test: added sample auth contract wasm for testing
javiersuweijie Feb 22, 2024
73b0173
only support single sig
freeelancer Feb 23, 2024
23fe780
fix review
freeelancer Feb 26, 2024
b8f2482
reduce branching
freeelancer Feb 26, 2024
23c8508
Merge pull request #263 from terra-money/feat/smartaccounts/wasm
javiersuweijie Feb 26, 2024
cb6f9c1
make decorator format consistent
freeelancer Feb 28, 2024
3b763db
Added sudo msgs
freeelancer Feb 28, 2024
63ffbb3
added auth tests
freeelancer Feb 28, 2024
49a40be
fix: wasm contract interface
javiersuweijie Feb 29, 2024
f1bbecf
latest contracts
freeelancer Feb 29, 2024
c967ef9
only support single sig for now
freeelancer Feb 29, 2024
5f9603a
update to latest interface
freeelancer Feb 29, 2024
f5c7fcf
update auth interface and wasm contract
javiersuweijie Feb 29, 2024
7b16b90
Revert "only support single sig for now"
freeelancer Feb 29, 2024
4f0114f
Merge branch 'release/v2.10' of https://github.com/terra-money/core i…
emidev98 Feb 29, 2024
8e08a83
passed auth_test
freeelancer Mar 1, 2024
a859d3a
fix tests
freeelancer Mar 2, 2024
fb448bb
added posttx tests
freeelancer Mar 2, 2024
113c6c4
added msg_server tests
freeelancer Mar 4, 2024
307363b
added test for update auth
freeelancer Mar 4, 2024
08771d4
add amino codec
freeelancer Mar 4, 2024
7549699
added test for updateTxHooks
freeelancer Mar 4, 2024
1ef05b7
update setting api url
freeelancer Mar 5, 2024
ef4ba86
changed fallback casing
freeelancer Mar 5, 2024
33943b0
added smartaccount.test.ts
freeelancer Mar 7, 2024
d8a0a4f
change to senderAcc
freeelancer Mar 7, 2024
519bdca
init auth account from update auth
freeelancer Mar 7, 2024
07092bc
change update auth message
freeelancer Mar 7, 2024
b68ffad
fixed UpdateAuth tests
freeelancer Mar 7, 2024
29004fb
changed query to return human readable base64
freeelancer Mar 8, 2024
dea147e
refactor: remove bad comments
javiersuweijie Mar 11, 2024
67596fe
changed initialization proto
freeelancer Mar 11, 2024
6af225b
fixed smartaccount test
freeelancer Mar 11, 2024
d89467f
split to two files
freeelancer Mar 11, 2024
50629a4
feat: handle multi signatures
javiersuweijie Mar 12, 2024
5d95841
removed adding ctx setting
freeelancer Mar 12, 2024
de029a4
added msgdisable test
freeelancer Mar 12, 2024
8c23207
tests + fixes: custom multisig tests
javiersuweijie Mar 12, 2024
7663195
fix all tests
freeelancer Mar 12, 2024
4e1ab0c
Update x/smartaccount/ante/auth.go
javiersuweijie Mar 12, 2024
cd5bdfd
feat: handle nested native multisigs
javiersuweijie Mar 12, 2024
e37dcd5
Merge branch 'feat/smartaccounts/multisig' of github.com:terra-money/…
javiersuweijie Mar 12, 2024
7704816
fix: get sa settings using ctx
javiersuweijie Mar 12, 2024
bbb9e44
fix: get settings when simulating
javiersuweijie Mar 12, 2024
2a77d90
refactor: moved simulation check
javiersuweijie Mar 12, 2024
e0989c7
update package.json
freeelancer Mar 12, 2024
eae5583
Merge pull request #278 from terra-money/fix/setting-with-value
javiersuweijie Mar 12, 2024
7052fa9
change sender to senders
freeelancer Mar 12, 2024
48a1b2f
Merge pull request #277 from terra-money/feat/smartaccounts/multisig
javiersuweijie Mar 12, 2024
c8fbdb0
added unit test for limit min coins hooks
freeelancer Mar 14, 2024
3394cc5
added posttx tests
freeelancer Mar 14, 2024
2871b26
fixed tests
freeelancer Mar 14, 2024
f764d50
Merge pull request #281 from terra-money/feat/smartaccounts/posttx
emidev98 Mar 19, 2024
00969a1
Merge branch 'release/v2.11' of https://github.com/terra-money/core i…
emidev98 Mar 25, 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
Prev Previous commit
Next Next commit
tests + fixes: custom multisig tests
  • Loading branch information
javiersuweijie committed Mar 12, 2024

Verified

This commit was signed with the committer’s verified signature.
ipmb Peter Baumgartner
commit 8c2320786ac2919b8414d818b8ca09a8d8fb86ea
27 changes: 17 additions & 10 deletions x/smartaccount/ante/auth.go
Original file line number Diff line number Diff line change
@@ -115,7 +115,7 @@ func (sad SmartAccountAuthDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
if success {
return next(ctx, tx, simulate)
} else if !setting.Fallback {
return ctx, sdkerrors.ErrUnauthorized.Wrap("authorization failed")
return ctx, sdkerrors.ErrUnauthorized.Wrap(fmt.Sprintf("authorization failed: %s", err))
}
}

@@ -136,7 +136,7 @@ func (sad SmartAccountAuthDecorator) GetParamsForCustomAuthVerification(
) (
senderAddrs []string,
signatureBzs [][]byte,
signedBytes [][]byte,
signedBzs [][]byte,
err error,
) {
signatures, err := sigTx.GetSignaturesV2()
@@ -184,13 +184,14 @@ func (sad SmartAccountAuthDecorator) GetParamsForCustomAuthVerification(
if err != nil {
return nil, nil, nil, err
}
signedBytes, err = GetSignBytesArr(signature.PubKey, signerData, signature.Data, sad.signModeHandler, sigTx)
signedBytes, err := GetSignBytesArr(signature.PubKey, signerData, signature.Data, sad.signModeHandler, sigTx)
signedBzs = append(signedBzs, signedBytes...)
if err != nil {
return nil, nil, nil, err
}
signatureBzs = append(signatureBzs, signatureBz...)
}
return senderAddrs, signatureBzs, signedBytes, nil
return senderAddrs, signatureBzs, signedBzs, nil
}

func (sad SmartAccountAuthDecorator) CustomAuthVerify(
@@ -201,13 +202,13 @@ func (sad SmartAccountAuthDecorator) CustomAuthVerify(
signatures,
signedBytes [][]byte,
data []byte,
) (success bool, err error) {
success = false
) (bool, error) {
success := false
var errs []error
for _, auth := range authMsgs {
authMsg := types.Authorization{
Senders: sender,
Account: account,
// TODO: add in future when needed
Senders: sender,
Account: account,
Signatures: signatures,
SignedBytes: signedBytes,
Data: data,
@@ -226,9 +227,15 @@ func (sad SmartAccountAuthDecorator) CustomAuthVerify(
if err == nil {
success = true
break
} else {
errs = append(errs, err)
}
}
return success, nil
if success {
return success, nil
} else {
return success, fmt.Errorf("%v", errs)
}
}

// signatureDataToBz converts a SignatureData into raw bytes signature.
144 changes: 144 additions & 0 deletions x/smartaccount/ante/tests/auth_test.go
Original file line number Diff line number Diff line change
@@ -95,6 +95,79 @@ func (s *AnteTestSuite) TestAuthAnteHandler() {
require.NoError(s.T(), err)
}

func (s *AnteTestSuite) TestAuthAnteHandlerWithMultisig() {
s.Setup()

type MultiSigSetting struct {
Signers []string `json:"signers"`
PublicKeys []string `json:"public_keys"`
Threshold uint8 `json:"threshold"`
}

acc1 := s.TestAccs[1]
acc2 := s.TestAccs[2]
pubKey1 := s.TestAccPrivs[1].PubKey()
pubKey2 := s.TestAccPrivs[2].PubKey()
pkEncoded1 := []byte(base64.StdEncoding.EncodeToString(pubKey1.Bytes()))
pkEncoded2 := []byte(base64.StdEncoding.EncodeToString(pubKey2.Bytes()))

codeId, _, err := s.WasmKeeper.Create(s.Ctx, acc1, test_helpers.SmartMultiSigWasm, nil)
require.NoError(s.T(), err)
contractAddr, _, err := s.WasmKeeper.Instantiate(s.Ctx, codeId, acc1, acc1, []byte("{}"), "auth", sdk.NewCoins())
require.NoError(s.T(), err)

setting := MultiSigSetting{
Signers: []string{acc1.String(), acc2.String()},
PublicKeys: []string{string(pkEncoded1), string(pkEncoded2)},
Threshold: 2,
}
settingBs, err := json.Marshal(setting)
require.NoError(s.T(), err)

// create initMsg
initMsg := smartaccounttypes.Initialization{
Account: acc1.String(),
Msg: settingBs,
}
sudoInitMsg := smartaccounttypes.SudoMsg{Initialization: &initMsg}
sudoInitMsgBs, err := json.Marshal(sudoInitMsg)
require.NoError(s.T(), err)

_, err = s.WasmKeeper.Sudo(s.Ctx, contractAddr, sudoInitMsgBs)
require.NoError(s.T(), err)

// set settings
authMsg := &smartaccounttypes.AuthorizationMsg{
ContractAddress: contractAddr.String(),
InitMsg: sudoInitMsg.Initialization,
}
err = s.SmartAccountKeeper.SetSetting(s.Ctx, smartaccounttypes.Setting{
Owner: acc1.String(),
Fallback: false,
Authorization: []*smartaccounttypes.AuthorizationMsg{authMsg},
})
require.NoError(s.T(), err)

// signing with multisig should pass
txBuilder := s.BuildDefaultMultiSigMsgTx([]int{1, 2}, &types.MsgSend{
FromAddress: acc1.String(),
ToAddress: acc1.String(),
Amount: sdk.NewCoins(sdk.NewInt64Coin("uluna", 1)),
})
_, err = s.AuthDecorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{}))
require.NoError(s.T(), err)

// signing with multisig with only 1 signer should fail
txBuilder = s.BuildDefaultMultiSigMsgTx([]int{1}, &types.MsgSend{
FromAddress: acc1.String(),
ToAddress: acc1.String(),
Amount: sdk.NewCoins(sdk.NewInt64Coin("uluna", 1)),
})
_, err = s.AuthDecorator.AnteHandle(s.Ctx, txBuilder.GetTx(), false, sdk.ChainAnteDecorators(sdk.Terminator{}))
require.Error(s.T(), err)
require.ErrorContainsf(s.T(), err, "required: 2, found: 1", "")
}

func (s *AnteTestSuite) BuildDefaultMsgTx(accountIndex int, msgs ...sdk.Msg) client.TxBuilder {
pk := s.TestAccPrivs[accountIndex]
sender := s.TestAccs[accountIndex]
@@ -141,3 +214,74 @@ func (s *AnteTestSuite) BuildDefaultMsgTx(accountIndex int, msgs ...sdk.Msg) cli

return txBuilder
}

func (s *AnteTestSuite) BuildDefaultMultiSigMsgTx(accountIndices []int, msgs ...sdk.Msg) client.TxBuilder {

txBuilder := s.EncodingConfig.TxConfig.NewTxBuilder()
err := txBuilder.SetMsgs(
msgs...,
)
require.NoError(s.T(), err)

var emptySigs []signing.SignatureV2

for _, accountIndex := range accountIndices {
sender := s.TestAccs[accountIndex]
senderAcc := s.App.Keepers.AccountKeeper.GetAccount(s.Ctx, sender)
senderSeq := senderAcc.GetSequence()
pk := s.TestAccPrivs[accountIndex]

signer := authsigning.SignerData{
Address: sender.String(),
ChainID: "test",
AccountNumber: senderAcc.GetAccountNumber(),
Sequence: senderSeq,
PubKey: pk.PubKey(),
}

emptySig := signing.SignatureV2{
PubKey: signer.PubKey,
Data: &signing.SingleSignatureData{
SignMode: s.EncodingConfig.TxConfig.SignModeHandler().DefaultMode(),
Signature: nil,
},
Sequence: signer.Sequence,
}

emptySigs = append(emptySigs, emptySig)
}
err = txBuilder.SetSignatures(emptySigs...)

require.NoError(s.T(), err)

var signed []signing.SignatureV2
for _, accountIndex := range accountIndices {
sender := s.TestAccs[accountIndex]
senderAcc := s.App.Keepers.AccountKeeper.GetAccount(s.Ctx, sender)
senderSeq := senderAcc.GetSequence()
pk := s.TestAccPrivs[accountIndex]

signer := authsigning.SignerData{
Address: sender.String(),
ChainID: "test",
AccountNumber: senderAcc.GetAccountNumber(),
Sequence: senderSeq,
PubKey: pk.PubKey(),
}
sigV2, err := tx.SignWithPrivKey(
s.EncodingConfig.TxConfig.SignModeHandler().DefaultMode(),
signer,
txBuilder,
pk,
s.EncodingConfig.TxConfig,
senderSeq,
)
require.NoError(s.T(), err)
signed = append(signed, sigV2)
}

err = txBuilder.SetSignatures(signed...)
require.NoError(s.T(), err)

return txBuilder
}
3 changes: 3 additions & 0 deletions x/smartaccount/test_helpers/test_data.go
Original file line number Diff line number Diff line change
@@ -7,3 +7,6 @@ var LimitSendOnlyHookWasm []byte

//go:embed test_data/smart_auth_contract.wasm
var SmartAuthContractWasm []byte

//go:embed test_data/smart_auth_multisig.wasm
var SmartMultiSigWasm []byte
Binary file not shown.
Loading