app

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 78 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ModuleConfig is the module configuration for the Shielded-Vote chain.
	// Only the minimal modules needed for block production are included:
	// auth, bank, staking, distribution, consensus, genutil, tx.
	ModuleConfig = []*appv1alpha1.ModuleConfig{
		{
			Name: runtime.ModuleName,
			Config: appconfig.WrapAny(&runtimev1alpha1.Module{
				AppName: "Shielded-Vote",
				PreBlockers: []string{
					authtypes.ModuleName,
				},

				BeginBlockers: []string{
					distrtypes.ModuleName,
					slashingtypes.ModuleName,
					stakingtypes.ModuleName,
				},
				EndBlockers: []string{
					stakingtypes.ModuleName,
					votetypes.ModuleName,
				},
				OverrideStoreKeys: []*runtimev1alpha1.StoreKeyConfig{
					{
						ModuleName: authtypes.ModuleName,
						KvStoreKey: "acc",
					},
				},
				SkipStoreKeys: []string{
					"tx",
				},

				InitGenesis: []string{
					authtypes.ModuleName,
					banktypes.ModuleName,
					distrtypes.ModuleName,
					stakingtypes.ModuleName,
					slashingtypes.ModuleName,
					genutiltypes.ModuleName,
					votetypes.ModuleName,
				},
				ExportGenesis: []string{
					consensustypes.ModuleName,
					authtypes.ModuleName,
					banktypes.ModuleName,
					distrtypes.ModuleName,
					stakingtypes.ModuleName,
					slashingtypes.ModuleName,
					genutiltypes.ModuleName,
					votetypes.ModuleName,
				},
			}),
		},
		{
			Name: authtypes.ModuleName,
			Config: appconfig.WrapAny(&authmodulev1.Module{
				Bech32Prefix:             "sv",
				ModuleAccountPermissions: moduleAccPerms,
			}),
		},
		{
			Name: banktypes.ModuleName,
			Config: appconfig.WrapAny(&bankmodulev1.Module{
				BlockedModuleAccountsOverride: blockAccAddrs,
			}),
		},
		{
			Name: stakingtypes.ModuleName,
			Config: appconfig.WrapAny(&stakingmodulev1.Module{
				Bech32PrefixValidator: "svvaloper",
				Bech32PrefixConsensus: "svvalcons",
			}),
		},
		{
			Name:   distrtypes.ModuleName,
			Config: appconfig.WrapAny(&distrmodulev1.Module{}),
		},
		{
			Name:   slashingtypes.ModuleName,
			Config: appconfig.WrapAny(&slashingmodulev1.Module{}),
		},
		{
			Name:   consensustypes.ModuleName,
			Config: appconfig.WrapAny(&consensusmodulev1.Module{}),
		},
		{
			Name:   genutiltypes.ModuleName,
			Config: appconfig.WrapAny(&genutilmodulev1.Module{}),
		},
		{
			Name:   votetypes.ModuleName,
			Config: appconfig.WrapAny(&votemodulelv1.Module{}),
		},
		{

			Name: "tx",
			Config: appconfig.WrapAny(&txconfigv1.Config{
				SkipAnteHandler: true,
			}),
		},
	}

	// AppConfig is the application configuration used by depinject.
	AppConfig = depinject.Configs(appconfig.Compose(&appv1alpha1.Config{
		Modules: ModuleConfig,
	}),
		depinject.Supply(

			map[string]module.AppModuleBasic{
				genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
			},
		),
	)
)
View Source
var DefaultNodeHome string

DefaultNodeHome is the default home directory for the svoted daemon.

Functions

func AllowedMessagesSummary added in v0.3.0

func AllowedMessagesSummary() string

AllowedMessagesSummary returns a human-readable list of allowed message types for error messages and logging.

func ComposedPrepareProposalHandler

func ComposedPrepareProposalHandler(
	dealInjector PrepareProposalInjector,
	ackInjector PrepareProposalInjector,
	partialDecryptInjector PrepareProposalInjector,
	tallyHandler sdk.PrepareProposalHandler,
) sdk.PrepareProposalHandler

ComposedPrepareProposalHandler composes DKG contribution, ceremony ack, threshold partial decryption, and tally injection into a single sdk.PrepareProposalHandler. Injectors run sequentially:

dkg-contribute → ack → partialDecrypt → tally

func CustomTxDecoder

func CustomTxDecoder(standardDecoder sdk.TxDecoder) sdk.TxDecoder

CustomTxDecoder returns a TxDecoder that handles vote wire format, ceremony wire format, and standard Cosmos SDK Tx encoding.

Custom transactions use a simple tagged binary format:

[1 byte: msg_type_tag] [N bytes: protobuf message]

Tags 0x01–0x05 are vote-round messages, 0x06+ are ceremony messages. These tag bytes do not collide with valid Cosmos Tx protobuf encodings, which start with a field tag byte (typically 0x0a for field 1, length-delimited).

If the first byte is a custom tag, the tx is decoded into a VoteTxWrapper that implements sdk.Tx. Otherwise, the standard Cosmos TxDecoder is used.

func DefaultAllowedMessages added in v0.3.0

func DefaultAllowedMessages() []string

DefaultAllowedMessages returns the canonical set of message type URLs permitted on the standard Cosmos tx path. Update this list when adding new message types to the chain.

func NewDualAnteHandler

func NewDualAnteHandler(opts DualAnteHandlerOptions) (sdk.AnteHandler, error)

NewDualAnteHandler returns an AnteHandler that detects the tx type and routes to the appropriate validation pipeline:

  • VoteTxWrapper → custom validation via ValidateVoteTx (ZKP + RedPallas)
  • Standard sdk.Tx → standard Cosmos ante chain (sig verify, fees, etc.)

This allows the chain to process both vote transactions (which bypass the Cosmos Tx envelope) and standard Cosmos transactions (for staking, etc.) through the same BaseApp instance.

func ProcessProposalHandler

func ProcessProposalHandler(
	voteKeeper *votekeeper.Keeper,
	logger log.Logger,
) sdk.ProcessProposalHandler

ProcessProposalHandler returns a handler that validates injected txs proposed by the block proposer. For DKG contribution messages: verifies the round is PENDING with ceremony REGISTERING, creator is a ceremony validator, no duplicate contribution, and creator matches the block proposer. For ack messages: verifies the round is PENDING with ceremony DEALT, creator is a ceremony validator, no duplicate ack, and creator matches the block proposer. For partial decrypt messages: verifies the round is TALLYING in threshold mode, creator is a ceremony validator with matching ShamirIndex, no duplicate submission, and creator matches the block proposer. For tally messages: verifies the round is TALLYING and creator matches the block proposer. All other txs pass through (ACCEPT).

func ProductionOpts

func ProductionOpts() voteante.ValidateOpts

ProductionOpts returns ValidateOpts wired with real cryptographic verifiers (RedPallas via FFI, Halo2 via FFI). Only use in production binaries built with `make install-ffi` (-tags halo2,redpallas). Tests should use voteante.MockOpts() instead.

func TallyPrepareProposalHandler

func TallyPrepareProposalHandler(
	voteKeeper *votekeeper.Keeper,
	stakingKeeper *stakingkeeper.Keeper,
	ceremonyDir string,
	logger log.Logger,
) sdk.PrepareProposalHandler

TallyPrepareProposalHandler returns a PrepareProposalHandler that injects MsgSubmitTally for any round in TALLYING state.

Reads stored partial decryptions from KV, waits until at least round.Threshold validators have submitted, then performs Lagrange interpolation in the exponent and BSGS.

Types

type CeremonyFeeExemptDecorator

type CeremonyFeeExemptDecorator struct{}

CeremonyFeeExemptDecorator grants an infinite gas meter to all standard Cosmos transactions. This chain is fee-free — no DeductFeeDecorator is present and MinGasPrices is 0. The infinite gas meter prevents "out of gas" failures for any message type (bank sends, slashing unjails, etc.) without requiring callers to estimate gas.

func NewCeremonyFeeExemptDecorator

func NewCeremonyFeeExemptDecorator() CeremonyFeeExemptDecorator

func (CeremonyFeeExemptDecorator) AnteHandle

func (d CeremonyFeeExemptDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error)

type CeremonyValidatorDecorator

type CeremonyValidatorDecorator struct {
	// contains filtered or unexported fields
}

CeremonyValidatorDecorator rejects ceremony messages from non-validators. It inspects each message in the transaction; if any is a ceremony type that requires validator authorization, the first signer must be a bonded validator. MsgCreateValidatorWithPallasKey is exempt because the sender is becoming a validator. MsgSetVoteManager is also exempt because its handler already implements its own authorization check (vote manager only).

func NewCeremonyValidatorDecorator

func NewCeremonyValidatorDecorator(k *votekeeper.Keeper) CeremonyValidatorDecorator

func (CeremonyValidatorDecorator) AnteHandle

func (d CeremonyValidatorDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error)

type DualAnteHandlerOptions

type DualAnteHandlerOptions struct {
	// Standard SDK ante handler options (for Cosmos txs: staking, etc.)
	ante.HandlerOptions

	// Vote module keeper for stateful validation.
	VoteKeeper *votekeeper.Keeper

	// RedPallas signature verifier. Use ProductionOpts().SigVerifier in production,
	// redpallas.NewMockVerifier() in tests.
	SigVerifier redpallas.Verifier

	// ZKP verifier. Use ProductionOpts().ZKPVerifier in production,
	// zkp.NewMockVerifier() in tests.
	ZKPVerifier zkp.Verifier
}

DualAnteHandlerOptions configures the dual-mode ante handler that supports both vote transactions (ZKP/RedPallas authenticated) and standard Cosmos transactions (secp256k1/ed25519 signatures, fees, etc.).

type GenesisState

type GenesisState map[string]json.RawMessage

GenesisState of the blockchain is represented here as a map of raw json messages key'd by an identifier string. The identifier is used to determine which module genesis information belongs to so it may be appropriately routed during init chain.

type MessageWhitelistDecorator added in v0.3.0

type MessageWhitelistDecorator struct {
	// contains filtered or unexported fields
}

MessageWhitelistDecorator rejects any transaction that contains a message whose proto type URL is not in the allowed set. This enforces the chain's restricted permission model at the ante handler level — before signature verification or state access.

The whitelist is a positive-security model: only explicitly enumerated message types are permitted. Any new message type must be added here before it can be processed on the standard Cosmos tx path.

func NewMessageWhitelistDecorator added in v0.3.0

func NewMessageWhitelistDecorator(allowedTypeURLs []string) MessageWhitelistDecorator

NewMessageWhitelistDecorator creates a decorator that only allows the given proto type URLs. Type URLs must include the leading slash, e.g. "/cosmos.staking.v1beta1.MsgDelegate".

func (MessageWhitelistDecorator) AnteHandle added in v0.3.0

func (d MessageWhitelistDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error)

type PrepareProposalInjector

type PrepareProposalInjector = func(ctx sdk.Context, req *abci.RequestPrepareProposal, txs [][]byte) [][]byte

PrepareProposalInjector is a function that may inject txs into the block proposal. It receives the current tx list and returns the (possibly modified) tx list. Injectors should prepend their txs before the existing ones.

func CeremonyAckPrepareProposalHandler

func CeremonyAckPrepareProposalHandler(
	voteKeeper *votekeeper.Keeper,
	stakingKeeper *stakingkeeper.Keeper,
	pallasSkPath string,
	ceremonyDir string,
	logger log.Logger,
) PrepareProposalInjector

CeremonyAckPrepareProposalHandler returns a PrepareProposalInjector that checks whether a PENDING round's ceremony is in DEALT state and, if so, injects a MsgAckExecutiveAuthorityKey on behalf of the block proposer.

The proposer loads their persisted polynomial coefficients, computes their own partial share, decrypts and verifies shares from every other contributor against that contributor's individual Feldman commitments, sums everything into a combined share, and verifies the result against the round's combined commitments. The coefficients file is deleted after success.

The final share is written to <ceremonyDir>/share.<hex(round_id)> and a MsgAckExecutiveAuthorityKey is injected.

func CeremonyDKGContributionPrepareProposalHandler added in v0.4.0

func CeremonyDKGContributionPrepareProposalHandler(
	voteKeeper *votekeeper.Keeper,
	stakingKeeper *stakingkeeper.Keeper,
	pallasSkPath string,
	ceremonyDir string,
	logger log.Logger,
) PrepareProposalInjector

CeremonyDKGContributionPrepareProposalHandler returns a PrepareProposalInjector that generates and injects a MsgContributeDKG when the proposer is a ceremony validator in a REGISTERING round that has not yet received their contribution.

Each validator independently:

  1. Generates a random secret s_i and splits it into (t, n) Shamir shares
  2. Computes Feldman commitments C_{i,j} = a_{i,j} * G for the polynomial
  3. ECIES-encrypts share_{i,k} to validator k's Pallas public key (for k ≠ i)
  4. Persists polynomial coefficients to disk for the ack handler
  5. Injects MsgContributeDKG containing commitments and n-1 encrypted payloads

The proposer's own share is not included in the payloads — the ack handler recomputes it from the persisted coefficients as f_i(shamirIndex).

func PartialDecryptPrepareProposalInjector

func PartialDecryptPrepareProposalInjector(
	voteKeeper *votekeeper.Keeper,
	stakingKeeper *stakingkeeper.Keeper,
	ceremonyDir string,
	logger log.Logger,
) PrepareProposalInjector

PartialDecryptPrepareProposalInjector returns a PrepareProposalInjector that handles the partial decryption phase of tally.

When a round is in TALLYING state and the block proposer has not yet submitted a partial decryption for that round, it:

  1. Loads the proposer's Shamir share from <ceremonyDir>/share.<hex(round_id)>
  2. Finds the proposer's 1-based validator_index in ceremony_validators
  3. Computes D_i = share_i * C1 for every non-empty tally accumulator
  4. Injects MsgSubmitPartialDecryption (tag 0x0D)

If ceremonyDir is empty, the share file is absent, or the proposer is not a ceremony validator, injection is skipped gracefully.

type SvoteApp

type SvoteApp struct {
	*runtime.App

	// Keepers for the minimal module set.
	AccountKeeper         authkeeper.AccountKeeper
	BankKeeper            bankkeeper.BaseKeeper
	StakingKeeper         *stakingkeeper.Keeper
	DistrKeeper           distrkeeper.Keeper
	SlashingKeeper        slashingkeeper.Keeper
	ConsensusParamsKeeper consensuskeeper.Keeper

	// Vote module keeper.
	VoteKeeper *votekeeper.Keeper
	// contains filtered or unexported fields
}

SvoteApp extends an ABCI application for the Shielded-Vote chain. Built from a stripped-down Cosmos SDK simapp with only the minimal modules needed for block production (auth, bank, staking, distribution, consensus, genutil).

func NewSvoteApp

func NewSvoteApp(
	logger log.Logger,
	db dbm.DB,
	traceStore io.Writer,
	loadLatest bool,
	appOpts servertypes.AppOptions,
	baseAppOptions ...func(*baseapp.BaseApp),
) *SvoteApp

NewSvoteApp returns a reference to an initialized SvoteApp.

func (*SvoteApp) AppCodec

func (app *SvoteApp) AppCodec() codec.Codec

AppCodec returns the app's codec.

func (*SvoteApp) ExportAppStateAndValidators

func (app *SvoteApp) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs, modulesToExport []string) (servertypes.ExportedApp, error)

ExportAppStateAndValidators exports the state of the application for a genesis file.

func (*SvoteApp) GetHelper

func (app *SvoteApp) GetHelper() *helper.Helper

GetHelper returns the currently published helper instance.

func (*SvoteApp) GetKey

func (app *SvoteApp) GetKey(storeKey string) *storetypes.KVStoreKey

GetKey returns the KVStoreKey for the provided store key.

func (*SvoteApp) InterfaceRegistry

func (app *SvoteApp) InterfaceRegistry() codectypes.InterfaceRegistry

InterfaceRegistry returns the app's InterfaceRegistry.

func (*SvoteApp) LegacyAmino

func (app *SvoteApp) LegacyAmino() *codec.LegacyAmino

LegacyAmino returns the app's amino codec.

func (*SvoteApp) LoadHeight

func (app *SvoteApp) LoadHeight(height int64) error

LoadHeight loads a particular height.

func (*SvoteApp) RegisterAPIRoutes

func (app *SvoteApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig)

RegisterAPIRoutes registers all application module routes with the provided API server.

func (*SvoteApp) SetHelper

func (app *SvoteApp) SetHelper(h *helper.Helper)

SetHelper publishes the helper instance for concurrent readers.

func (*SvoteApp) SimulationManager

func (app *SvoteApp) SimulationManager() *module.SimulationManager

SimulationManager implements the SimulationApp interface (required by runtime.AppI). We don't use simulation, so this returns nil.

func (*SvoteApp) TxConfig

func (app *SvoteApp) TxConfig() client.TxConfig

TxConfig returns the app's TxConfig.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL