Skip to content
Open
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
8 changes: 4 additions & 4 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ import (

"github.com/terpnetwork/terp-core/v5/x/smart-account/authenticator"
smartaccountkeeper "github.com/terpnetwork/terp-core/v5/x/smart-account/keeper"
smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types"
sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types"

// cwhookskeeper "github.com/terpnetwork/terp-core/v5/x/cw-hooks/keeper"
// cwhookstypes "github.com/terpnetwork/terp-core/v5/x/cw-hooks/types"
Expand Down Expand Up @@ -277,8 +277,8 @@ func NewAppKeepers(

smartAccountKeeper := smartaccountkeeper.NewKeeper(
appCodec,
appKeepers.keys[smartaccounttypes.StoreKey],
authtypes.NewModuleAddress(govtypes.ModuleName), appKeepers.GetSubspace(smartaccounttypes.ModuleName),
appKeepers.keys[sat.StoreKey],
authtypes.NewModuleAddress(govtypes.ModuleName), appKeepers.GetSubspace(sat.ModuleName),
appKeepers.AuthenticatorManager,
*appKeepers.FeeGrantKeeper,
)
Expand Down Expand Up @@ -643,7 +643,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(globalfee.ModuleName)
paramsKeeper.Subspace(ibchookstypes.ModuleName)
paramsKeeper.Subspace(feesharetypes.ModuleName).WithKeyTable(feesharetypes.ParamKeyTable())
paramsKeeper.Subspace(smartaccounttypes.ModuleName).WithKeyTable(smartaccounttypes.ParamKeyTable())
paramsKeeper.Subspace(sat.ModuleName).WithKeyTable(sat.ParamKeyTable())
paramsKeeper.Subspace(wasmtypes.ModuleName)

return paramsKeeper
Expand Down
4 changes: 2 additions & 2 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (

ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v10/types"
ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported"
smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types"
sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types"

// cwhookstypes "github.com/terpnetwork/terp-core/v5/x/cw-hooks/types"
driptypes "github.com/terpnetwork/terp-core/v5/x/drip/types"
Expand Down Expand Up @@ -68,7 +68,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
feesharetypes.StoreKey,
globalfeetypes.StoreKey,
driptypes.StoreKey,
smartaccounttypes.StoreKey,
sat.StoreKey,
tokenfactorytypes.StoreKey,
)

Expand Down
6 changes: 3 additions & 3 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import (
tokenfactorytypes "github.com/terpnetwork/terp-core/v5/x/tokenfactory/types"

smartaccount "github.com/terpnetwork/terp-core/v5/x/smart-account"
smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types"
sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types"

groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
)
Expand Down Expand Up @@ -212,7 +212,7 @@ func orderEndBlockers() []string {
globalfee.ModuleName,
ibchookstypes.ModuleName,
tokenfactorytypes.ModuleName,
smartaccounttypes.ModuleName,
sat.ModuleName,
// cwhooks.ModuleName,
wasmtypes.ModuleName,
}
Expand All @@ -236,7 +236,7 @@ func orderInitBlockers() []string {
packetforwardtypes.ModuleName,
ibchookstypes.ModuleName,
tokenfactorytypes.ModuleName,
smartaccounttypes.ModuleName,
sat.ModuleName,
// cwhooks.ModuleName,
wasmtypes.ModuleName,
}
Expand Down
4 changes: 2 additions & 2 deletions app/upgrades/v5/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
circuittypes "cosmossdk.io/x/circuit/types"
wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/v10/types"
"github.com/terpnetwork/terp-core/v5/app/upgrades"
smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types"
sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types"
)

const UpgradeName = "v5"
Expand All @@ -16,7 +16,7 @@ var Upgrade = upgrades.Upgrade{
StoreUpgrades: store.StoreUpgrades{
Added: []string{
circuittypes.ModuleName,
smartaccounttypes.ModuleName,
sat.ModuleName,
wasmlctypes.StoreKey,
},
Deleted: []string{
Expand Down
4 changes: 2 additions & 2 deletions proto/buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ deps:
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 61b203b9a9164be9a834f58c37be6f62
digest: shake256:e619113001d6e284ee8a92b1561e5d4ea89a47b28bf0410815cb2fa23914df8be9f1a6a98dcf069f5bc2d829a2cfb1ac614863be45cd4f8a5ad8606c5f200224
commit: 72c8614f3bd0466ea67931ef2c43d608
digest: shake256:b3ac4d383db09f92ab0ca85d12bff8c49eddf7031bd3a854c260b6ac4ed6a2bb85b52b3393c316d28f8038bf3b8e70cb3d16470e8cc4423007678fb6d89d36d4
23 changes: 22 additions & 1 deletion proto/terp/smartaccount/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "gogoproto/gogo.proto";

option go_package = "github.com/terpnetwork/terp-core/x/smart-account/types";


// Msg defines the Msg service.
service Msg {
option (cosmos.msg.v1.service) = true;
Expand All @@ -28,7 +29,27 @@ message MsgAddAuthenticator {

string sender = 1;
string authenticator_type = 2;
bytes data = 3;
// data is the initialization data for the authenticator.
// It must be set to exactly one of the following.
AuthenticatorConfig config = 3;
}


// AuthenticatorData represents initialization data that can be passed as raw JSON or JSON string.
message AuthenticatorConfig {
oneof data {
// value_string contains JSON as a string (e.g., "{\"threshold\":\"2\"}")
string value_string = 1;

// value_raw contains raw binary JSON (e.g., {"threshold":"2"})
bytes value_raw = 2;
}
}


message SubAuthenticatorInitData {
string type = 1;
AuthenticatorConfig config = 2;
}

// MsgAddAuthenticatorResponse defines the Msg/AddAuthenticator response type.
Expand Down
5 changes: 3 additions & 2 deletions scripts/makefiles/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ build-dev-build:
# to get a statically linked binary with CosmWasm

build-reproducible: build-reproducible-amd64 build-reproducible-arm64
sh scripts/release/prep-release.sh

build-reproducible-amd64: go.sum
mkdir -p $(BUILDDIR)
Expand All @@ -75,7 +76,7 @@ build-reproducible-amd64: go.sum
-f Dockerfile .
$(DOCKER) rm -f terpbinary || true
$(DOCKER) create -ti --name terpbinary terp-core:local-amd64
$(DOCKER) cp terpbinary:/usr/bin/terpd $(BUILDDIR)/terpd-linux-amd64
$(DOCKER) cp terpbinary:/usr/local/bin/terpd $(BUILDDIR)/terpd-linux-amd64
$(DOCKER) rm -f terpbinary

build-reproducible-arm64: go.sum
Expand All @@ -93,6 +94,6 @@ build-reproducible-arm64: go.sum
-f Dockerfile .
$(DOCKER) rm -f terpbinary || true
$(DOCKER) create -ti --name terpbinary terp-core:local-arm64
$(DOCKER) cp terpbinary:/usr/bin/terpd $(BUILDDIR)/terpd-linux-arm64
$(DOCKER) cp terpbinary:/usr/local/bin/terpd $(BUILDDIR)/terpd-linux-arm64
$(DOCKER) rm -f terpbinary

20 changes: 20 additions & 0 deletions scripts/release/prep-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

# 1. Build reproducible images
# echo "Building reproducible images..."
# make build-reproducible

# 2. Create tar.gz files of binaries
echo "Creating tar.gz files of binaries..."
tar -czvf build/terpd-linux-amd64.tar.gz build/terpd-linux-amd64
tar -czvf build/terpd-linux-arm64.tar.gz build/terpd-linux-arm64

# 3. Calculate sha256sum for all images into checksum.txt in ./build
echo "Calculating sha256sum for all images..."

sha256sum build/terpd-linux-amd64 > build/checksum.txt
sha256sum build/terpd-linux-arm64 >> build/checksum.txt
sha256sum build/terpd-linux-amd64.tar.gz >> build/checksum.txt
sha256sum build/terpd-linux-arm64.tar.gz >> build/checksum.txt

echo "SHA256 checksums have been saved to build/checksum.txt."
6 changes: 3 additions & 3 deletions tests/ibctesting/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types"
sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types"
)

const SimAppChainID = "simulation-app"
Expand Down Expand Up @@ -386,7 +386,7 @@ func SignAuthenticatorMsg(
return nil, fmt.Errorf("expected authtx.ExtensionOptionsTxBuilder, got %T", baseTxBuilder)
}
if len(selectedAuthenticators) > 0 {
value, err := types.NewAnyWithValue(&smartaccounttypes.TxExtension{
value, err := types.NewAnyWithValue(&sat.TxExtension{
SelectedAuthenticators: selectedAuthenticators,
})
if err != nil {
Expand Down Expand Up @@ -603,7 +603,7 @@ func SignAuthenticatorMsgWithCompoundSigs(
return nil, fmt.Errorf("expected authtx.ExtensionOptionsTxBuilder, got %T", baseTxBuilder)
}
if len(selectedAuthenticators) > 0 {
value, err := types.NewAnyWithValue(&smartaccounttypes.TxExtension{
value, err := types.NewAnyWithValue(&sat.TxExtension{
SelectedAuthenticators: selectedAuthenticators,
})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions x/smart-account/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

sdkante "github.com/cosmos/cosmos-sdk/x/auth/ante"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types"
sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -459,7 +459,7 @@ func GenTx(
return nil, fmt.Errorf("expected authtx.ExtensionOptionsTxBuilder, got %T", baseTxBuilder)
}
if len(selectedAuthenticators) > 0 {
value, err := types.NewAnyWithValue(&smartaccounttypes.TxExtension{
value, err := types.NewAnyWithValue(&sat.TxExtension{
SelectedAuthenticators: selectedAuthenticators,
})
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions x/smart-account/ante/circuit_breaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"

smartaccountkeeper "github.com/terpnetwork/terp-core/v5/x/smart-account/keeper"
smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types"
sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types"
)

// CircuitBreakerDecorator routes transactions through appropriate ante handlers based on
Expand Down Expand Up @@ -53,7 +53,7 @@ func IsCircuitBreakActive(
ctx sdk.Context,
tx sdk.Tx,
smartAccountKeeper *smartaccountkeeper.Keeper,
) (bool, smartaccounttypes.AuthenticatorTxOptions) {
) (bool, sat.AuthenticatorTxOptions) {
isSmartAccountActive := smartAccountKeeper.GetIsSmartAccountActive(ctx)
// If the smart accounts are not active, the circuit breaker activates (i.e. return true).
if !isSmartAccountActive {
Expand All @@ -69,7 +69,7 @@ func IsCircuitBreakActive(
func IsSelectedAuthenticatorTxExtensionMissing(
tx sdk.Tx,
smartAccountKeeper *smartaccountkeeper.Keeper,
) (bool, smartaccounttypes.AuthenticatorTxOptions) {
) (bool, sat.AuthenticatorTxOptions) {
extTx, ok := tx.(authante.HasExtensionOptionsTx)
if !ok {
return true, nil
Expand Down
6 changes: 3 additions & 3 deletions x/smart-account/ante/pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types"
sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types"
)

// EmitPubKeyDecoratorEvents emits the events that the SetPubKeyDecorator would emit. This is needed for backwards
Expand Down Expand Up @@ -51,7 +51,7 @@ func (spkd EmitPubKeyDecoratorEvents) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
for i, sig := range sigs {
events = append(events, sdk.NewEvent(sdk.EventTypeTx,
sdk.NewAttribute(sdk.AttributeKeyAccountSequence, fmt.Sprintf("%s/%d", signers[i], sig.Sequence)),
sdk.NewAttribute(smartaccounttypes.AttributeKeyAccountSequenceAuthenticator, fmt.Sprintf("%s/%d", signers[i], sig.Sequence)),
sdk.NewAttribute(sat.AttributeKeyAccountSequenceAuthenticator, fmt.Sprintf("%s/%d", signers[i], sig.Sequence)),
))

sigBzs, err := signatureDataToBz(sig.Data)
Expand All @@ -61,7 +61,7 @@ func (spkd EmitPubKeyDecoratorEvents) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim
for _, sigBz := range sigBzs {
events = append(events, sdk.NewEvent(sdk.EventTypeTx,
sdk.NewAttribute(sdk.AttributeKeySignature, base64.StdEncoding.EncodeToString(sigBz)),
sdk.NewAttribute(smartaccounttypes.AttributeKeySignatureAuthenticator, base64.StdEncoding.EncodeToString(sigBz)),
sdk.NewAttribute(sat.AttributeKeySignatureAuthenticator, base64.StdEncoding.EncodeToString(sigBz)),
))
}
}
Expand Down
37 changes: 26 additions & 11 deletions x/smart-account/authenticator/all_of.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types"
)

type AllOf struct {
Expand Down Expand Up @@ -48,26 +49,40 @@ func (aoa AllOf) StaticGas() uint64 {
}

func (aoa AllOf) Initialize(config []byte) (Authenticator, error) {
var initDatas []SubAuthenticatorInitData
if err := json.Unmarshal(config, &initDatas); err != nil {
return nil, errorsmod.Wrap(err, "failed to parse sub-authenticators initialization data")
// Decode the initialization data for each sub-authenticator
var count int
var items []subAuthDataJSON
if err := json.Unmarshal(config, &items); err != nil {
return nil, errorsmod.Wrapf(err, "failed to parse top-level JSON")
}

if len(initDatas) <= 1 {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "allOf must have at least 2 sub-authenticators")
}
for _, item := range items {
var config sat.AuthenticatorConfig
if err := UnmarshalAuthConfig(item.Config, &config); err != nil {
return nil, errorsmod.Wrap(err, "failed to unmarshal AuthenticatorConfig from JSON")
}
count++

authenticatorCode := aoa.am.GetAuthenticatorByType(item.Type)
raw := config.GetValueRaw()
// transform data into bytes dependent on its type
if len(raw) == 0 {
raw = []byte(config.GetValueString())
}

for _, initData := range initDatas {
authenticatorCode := aoa.am.GetAuthenticatorByType(initData.Type)
instance, err := authenticatorCode.Initialize(initData.Config)
instance, err := authenticatorCode.Initialize(raw)
if err != nil {
return nil, errorsmod.Wrapf(err, "failed to initialize sub-authenticator (type = %s)", initData.Type)
return nil, errorsmod.Wrapf(err, "failed to initialize sub-authenticator (type = %s)", item.Type)
}
aoa.SubAuthenticators = append(aoa.SubAuthenticators, instance)
}

if count <= 1 {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "allOf must have at least 2 sub-authenticators")
}

// If not all sub-authenticators are registered, return an error
if len(aoa.SubAuthenticators) != len(initDatas) {
if len(aoa.SubAuthenticators) != count {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "failed to initialize all sub-authenticators")
}

Expand Down
Loading
Loading