runtime

package
v0.0.0-...-dcea795 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: GPL-3.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxContractCallDataEntries     = 64
	MaxContractCallDataKeyBytes    = 128
	MaxContractCallDataValueBytes  = 16 * 1024
	MaxContractCallDataTotalBytes  = 64 * 1024
	MaxContractCallItems           = 16
	MaxContractCallItemsTotalBytes = 64 * 1024
)
View Source
const (
	GnoWriteGasLimit      = int64(5_000_000)
	GnoQueryGasLimit      = int64(1_000_000)
	GnoWriteMaxAllocBytes = int64(8 << 20)
	GnoQueryMaxAllocBytes = int64(4 << 20)
)

Query gas is a read-only resource cap, not a transaction billing budget. It is intentionally smaller than write/register/call execution gas.

View Source
const (
	GnoSnapshotCodecName = "gno-snapshot-json-v1"
	GnoSnapshotVersion   = uint64(1)
)
View Source
const (
	MaxContractSnapshotBytes      = 256 * 1024
	MaxContractSnapshotMapEntries = 256
	MaxContractSnapshotSliceItems = 256
	MaxContractSnapshotNodes      = 8 * 1024
)
View Source
const (
	ScalarOnlySupportDescription       = "current Gno typed ABI v1 supports only scalar types: string, bool, int, int64, uint64"
	FlatStructGlobalSupportDescription = "" /* 353-byte string literal not displayed */
	MapGlobalSupportDescription        = "" /* 342-byte string literal not displayed */
	SliceSupportDescription            = "" /* 310-byte string literal not displayed */
	QueryResultSupportDescription      = "" /* 308-byte string literal not displayed */
	WriteArgSupportDescription         = "current Gno write ABI v1 supports only scalar parameters: string, bool, int, int64, uint64"
	QueryArgSupportDescription         = "current Gno query ABI v1 supports only scalar parameters: string, bool, int, int64, uint64"
)
View Source
const (
	MaxContractSchemaImports           = 16
	MaxContractSchemaFunctions         = 128
	MaxContractSchemaPersistentGlobals = 128
	MaxContractSchemaStructs           = 64
	MaxContractSchemaStructFields      = 64
	MaxContractSchemaTypeNestingDepth  = 16
	MaxContractSchemaNodes             = 4096
)
View Source
const (
	// CurrentSchemaRulesetVersion names the current context-split typed Gno
	// ABI as the canonical baseline. The earlier ContractContext draft was
	// internal design-convergence work, not a durable external compatibility
	// line, so this baseline intentionally remains v1 instead of preserving a
	// legacy-style v2 name.
	CurrentSchemaRulesetVersion = "typed-gno-ruleset-v1"
	MaxTypedContractSourceBytes = 256 * 1024
)
View Source
const (
	MitumChainPackageName = "chain"
)
View Source
const MitumChainPackagePath = "mitum/chain"

Variables

View Source
var AllowedTypedContractImports = allowedTypedContractImportPaths()

AllowedTypedContractImports is a compatibility snapshot of the current policy. Validation reads the canonical import specs directly.

Functions

func AllowedTypedContractImportsDescription

func AllowedTypedContractImportsDescription() string

func BuildExpr

func BuildExpr(schema ContractSchema, typ TypeRef, sv SnapshotValue) (gno.Expr, error)

func BuildLiteral

func BuildLiteral(schema ContractSchema, typ TypeRef, sv SnapshotValue) (string, error)

func CaptureSnapshot

func CaptureSnapshot(pkg *gno.PackageValue, store gno.Store, schema ContractSchema) ([]byte, error)

func ClassifyGnoExecutionPanic

func ClassifyGnoExecutionPanic(
	scope string,
	r any,
	gasMeter gstore.GasMeter,
) base.OperationProcessReasonError

func CombineNativeResolvers

func CombineNativeResolvers(resolvers ...gno.NativeResolver) gno.NativeResolver

func ContractCallDataTotalBytes

func ContractCallDataTotalBytes(callData map[string]string) int

func GetAccountStateFunc

func GetAccountStateFunc(addr string, encs encoder.Encoders, getStateFunc base.GetStateFunc) (bool, error)

func GnoStdlibMemPackages

func GnoStdlibMemPackages() ([]*gnostd.MemPackage, error)

GnoStdlibMemPackages returns the Gno source packages needed by the allowed contract stdlib imports. The Gno source is vendored under gno_stdlib and embedded into the binary, so runtime execution does not depend on GNOROOT, GOMODCACHE, or a local github.com/gnolang/gno checkout.

Internal dependencies are loaded to execute allowed packages, but are not added to the contract import allowlist.

func GnoStdlibMemPackagesForContract

func GnoStdlibMemPackagesForContract(sourceCode string) ([]*gnostd.MemPackage, error)

GnoStdlibMemPackagesForContract returns only directly imported allowed stdlib packages and their internal dependencies. This keeps contracts which import no stdlib from paying package initialization cost for unused code.

func HostABIMemPackages

func HostABIMemPackages() []*gnostd.MemPackage

func IsAllowedTypedContractImport

func IsAllowedTypedContractImport(path string) bool

func IsSupportedScalarType

func IsSupportedScalarType(typ TypeRef) bool

func MitumChainMemPackage

func MitumChainMemPackage() *gnostd.MemPackage

func MitumNativeResolver

func MitumNativeResolver(pkgPath string, name gno.Name) func(m *gno.Machine)

func NewGnoGasMeter

func NewGnoGasMeter(limit int64) gstore.GasMeter

func NewPersistedContractSchema

func NewPersistedContractSchema(
	sourceCode string,
	schema ContractSchema,
) contracttypes.PersistedContractSchema

func QueryValueToJSONCompatible

func QueryValueToJSONCompatible(schema ContractSchema, typ TypeRef, qv QueryValue) (interface{}, error)

func RestoreSnapshot

func RestoreSnapshot(m *gno.Machine, pkg *gno.PackageValue, snapshot []byte, schema ContractSchema) error

func ValidateContractCallDataLimits

func ValidateContractCallDataLimits(name string, callData map[string]string) error

func ValidateContractCallItemsLimits

func ValidateContractCallItemsLimits(name string, items []ExecuteCallItem) error

func ValidateSnapshotLimits

func ValidateSnapshotLimits(doc SnapshotDoc, snapshotBytes []byte) error

Types

type AccountReader

type AccountReader interface {
	AccountExists(addr string) (bool, error)
}

type AllowedImportKind

type AllowedImportKind string
const (
	AllowedImportHostABI AllowedImportKind = "hostabi"
	AllowedImportStdlib  AllowedImportKind = "stdlib"
)

type AllowedImportSpec

type AllowedImportSpec struct {
	Path string
	Kind AllowedImportKind
}

func AllowedTypedContractImportSpecs

func AllowedTypedContractImportSpecs() []AllowedImportSpec

AllowedTypedContractImportSpecs returns the canonical contract-facing import policy. Schema admission and runtime package registration must derive from this list so an admitted import cannot silently lose runtime support.

type BalanceReader

type BalanceReader interface {
	BalanceOf(addr string, currency string) (string, bool, error)
}

type ComplexityRules

type ComplexityRules struct {
	MaxImports           int
	MaxFunctions         int
	MaxPersistentGlobals int
	MaxStructs           int
	MaxStructFields      int
	MaxTypeNestingDepth  int
	MaxSchemaNodes       int
}

type ContextRules

type ContextRules struct {
	WriteContextType                 string
	QueryContextType                 string
	LegacyContractContextType        string
	LegacyContractContextAllowed     bool
	QueryContextSenderAllowed        bool
	QuerySenderCallDataKeyParsed     bool
	QueryContextCurrentHeightAllowed bool
	WriteContextCurrentHeightAllowed bool
	ChainCurrentHeightNativeAllowed  bool
	WriteContextBlockTimeAllowed     bool
	QueryContextBlockTimeAllowed     bool
}

type ContractEngine

type ContractEngine interface {
	ValidateContract(sourceCode string) (ContractSchema, base.OperationProcessReasonError)
	ExecuteContract(
		encs encoder.Encoders,
		getStateFunc base.GetStateFunc,
		req ExecuteRequest,
	) (ExecuteResult, base.OperationProcessReasonError)
	QueryContract(
		encs encoder.Encoders,
		getStateFunc base.GetStateFunc,
		req QueryRequest,
	) (QueryResult, base.OperationProcessReasonError)
}

func NewGnoEngine

func NewGnoEngine() ContractEngine

type ContractReader

type ContractReader interface {
	IsContractAccount(addr string) (bool, error)
}

type ContractSchema

type ContractSchema struct {
	PackageName       string
	Mode              SchemaMode
	Types             TypeRegistry
	PersistentGlobals []PersistentBindingSchema
	Functions         []FunctionSchema
}

func AnalyzeContractSchema

func AnalyzeContractSchema(sourceCode string) (ContractSchema, error)

func RuntimeSchemaFromPersisted

func RuntimeSchemaFromPersisted(
	sourceCode string,
	persisted *contracttypes.PersistedContractSchema,
) (ContractSchema, bool)

func (ContractSchema) FindFunction

func (s ContractSchema) FindFunction(name string) (FunctionSchema, bool)

func (ContractSchema) ResolveType

func (s ContractSchema) ResolveType(t TypeRef) TypeRef

func (ContractSchema) SupportsScalarOnlyType

func (s ContractSchema) SupportsScalarOnlyType(t TypeRef) bool

func (ContractSchema) ValidatePersistentGlobalType

func (s ContractSchema) ValidatePersistentGlobalType(binding PersistentBindingSchema) error

func (ContractSchema) ValidateQueryArgType

func (s ContractSchema) ValidateQueryArgType(typ TypeRef, subject string) error

func (ContractSchema) ValidateQueryResultType

func (s ContractSchema) ValidateQueryResultType(typ TypeRef, subject string) error

func (ContractSchema) ValidateWriteArgType

func (s ContractSchema) ValidateWriteArgType(typ TypeRef, subject string) error

type ExecuteCallItem

type ExecuteCallItem struct {
	Function string
	CallData map[string]string
}

type ExecuteRequest

type ExecuteRequest struct {
	Mode         InvocationMode
	Contract     base.Address
	Sender       base.Address
	Height       base.Height
	BlockTime    int64
	ContractCode string
	Schema       *ContractSchema

	// Function and CallData are kept as a legacy single-call bridge. New call
	// execution should normalize through CallItems; register should use InitData.
	Function  string
	CallData  map[string]string
	CallItems []ExecuteCallItem
	InitData  map[string]string
}

type ExecuteResult

type ExecuteResult struct {
	Engine      state.RuntimeEngine
	StateMerges []base.StateMergeValue
}

type ExecutionContext

type ExecutionContext struct {
	Sender         base.Address
	Contract       base.Address
	Height         base.Height
	CurrentHeight  base.Height
	ReadOnly       bool
	AccountReader  AccountReader
	ContractReader ContractReader
	BalanceReader  BalanceReader
}

func NewExecutionContext

func NewExecutionContext(
	encs encoder.Encoders,
	getStateFunc base.GetStateFunc,
	contract base.Address,
	sender base.Address,
	height base.Height,
	readOnly bool,
) (*ExecutionContext, error)

func NewExecutionContextWithCurrentHeight

func NewExecutionContextWithCurrentHeight(
	encs encoder.Encoders,
	getStateFunc base.GetStateFunc,
	contract base.Address,
	sender base.Address,
	height base.Height,
	currentHeight base.Height,
	readOnly bool,
) (*ExecutionContext, error)

func (*ExecutionContext) Validate

func (ctx *ExecutionContext) Validate() error

type FunctionSchema

type FunctionSchema struct {
	Name     string
	Exported bool
	Params   []ParamSchema
	Results  []ResultSchema
}

func (FunctionSchema) IsContextCallable

func (fn FunctionSchema) IsContextCallable() bool

func (FunctionSchema) IsQueryContextCallable

func (fn FunctionSchema) IsQueryContextCallable() bool

func (FunctionSchema) IsSingleErrorResult

func (fn FunctionSchema) IsSingleErrorResult() bool

func (FunctionSchema) IsTypedABIShape

func (fn FunctionSchema) IsTypedABIShape() bool

func (FunctionSchema) IsTypedInitializeShape

func (fn FunctionSchema) IsTypedInitializeShape() bool

func (FunctionSchema) IsTypedQueryShape

func (fn FunctionSchema) IsTypedQueryShape() bool

func (FunctionSchema) IsTypedWriteShape

func (fn FunctionSchema) IsTypedWriteShape() bool

func (FunctionSchema) IsWriteContextCallable

func (fn FunctionSchema) IsWriteContextCallable() bool

func (FunctionSchema) UsesLegacyContractContext

func (fn FunctionSchema) UsesLegacyContractContext() bool

type GnoExecutionLimits

type GnoExecutionLimits struct {
	GasLimit      int64
	MaxAllocBytes int64
}

func QueryGnoExecutionLimits

func QueryGnoExecutionLimits() GnoExecutionLimits

func WriteGnoExecutionLimits

func WriteGnoExecutionLimits() GnoExecutionLimits

type ImportRules

type ImportRules struct {
	AllowedImports []string
}

type InputRules

type InputRules struct {
	CompositeInputAllowed bool
}

type InvocationMode

type InvocationMode string
const (
	InvocationModeRegister InvocationMode = "register"
	InvocationModeCall     InvocationMode = "call"
)

type LifecycleRules

type LifecycleRules struct {
	InitializeRegisterOnly bool
	InitializeCallable     bool
}

type ParamSchema

type ParamSchema struct {
	Name string
	Type TypeRef
}

type PersistentBindingSchema

type PersistentBindingSchema struct {
	Name            string
	Type            TypeRef
	HasExplicitType bool
}

type QueryField

type QueryField struct {
	Name  string     `json:"name"`
	Value QueryValue `json:"value"`
}

type QueryMapEntry

type QueryMapEntry struct {
	Key   string     `json:"key"`
	Value QueryValue `json:"value"`
}

type QueryRequest

type QueryRequest struct {
	Contract      base.Address
	Sender        base.Address
	Height        base.Height
	CurrentHeight base.Height
	ContractCode  string
	Schema        *ContractSchema
	Function      string
	CallData      map[string]string
}

type QueryResult

type QueryResult struct {
	Engine state.RuntimeEngine
	Result interface{}
	Ok     *bool
}

type QueryRules

type QueryRules struct {
	TopLevelResultKinds                 []SchemaShapeKind
	NestedStructFieldKinds              []SchemaShapeKind
	SliceElementKinds                   []SchemaShapeKind
	MapKeyScalarKinds                   []string
	MapValueKinds                       []SchemaShapeKind
	SingleResultAllowed                 bool
	BoolPresenceResultAllowed           bool
	BoolPresenceResultValueKinds        []SchemaShapeKind
	BoolPresenceSecondResultScalarKind  string
	EmbeddedFieldsAllowed               bool
	NamedStructAllowed                  bool
	NestedNamedStructAllowed            bool
	AnonymousResultStructAllowed        bool
	AnonymousNestedStructFieldsAllowed  bool
	RecursiveNamedStructsAllowed        bool
	TopLevelMapAllowed                  bool
	NestedMapAllowed                    bool
	MapStringScalarAllowed              bool
	MapStringNamedStructAllowed         bool
	AnonymousStructMapValuesAllowed     bool
	MapValueSlicesAllowed               bool
	MapValueMapsAllowed                 bool
	TopLevelSliceAllowed                bool
	NestedSliceAllowed                  bool
	SliceScalarAllowed                  bool
	SliceNamedStructAllowed             bool
	AnonymousStructSliceElementsAllowed bool
	SliceElementSlicesAllowed           bool
	SliceElementMapsAllowed             bool
}

type QueryValue

type QueryValue struct {
	Kind    string          `json:"kind"`
	Scalar  string          `json:"scalar,omitempty"`
	Fields  []QueryField    `json:"fields,omitempty"`
	Entries []QueryMapEntry `json:"entries,omitempty"`
	Items   []QueryValue    `json:"items,omitempty"`
	IsNil   bool            `json:"is_nil,omitempty"`
}

func ExtractQueryValue

func ExtractQueryValue(schema ContractSchema, typ TypeRef, tv gno.TypedValue, store gno.Store) (QueryValue, error)

type ResultSchema

type ResultSchema struct {
	Type TypeRef
}

type ScalarRules

type ScalarRules struct {
	AllowedKinds []string
}

type SchemaMode

type SchemaMode string
const (
	SchemaModeTypedArgs SchemaMode = "typed-snapshot-v1"
)

type SchemaRuleset

type SchemaRuleset struct {
	// Version tracks the semantic contract-schema policy bundle.
	// It is distinct from the snapshot codec version and any future
	// serialized schema metadata format version.
	//
	// Bump this version when accepted/rejected schema meaning changes:
	// package/source rules, import allowlist, scalar kinds, input/state/query
	// shapes, lifecycle semantics, complexity limits, or struct/map/slice
	// constraints. Do not bump for support text wording, error wording,
	// test-only hooks, or implementation refactors that preserve the same
	// schema acceptance policy. During pre-external design convergence, prefer
	// redefining the canonical baseline over carrying legacy-preserving version
	// increments without a concrete compatibility reason.
	Version         string
	SourceRules     SourceRules
	ImportRules     ImportRules
	ScalarRules     ScalarRules
	ContextRules    ContextRules
	InputRules      InputRules
	StateRules      StateRules
	QueryRules      QueryRules
	LifecycleRules  LifecycleRules
	ComplexityRules ComplexityRules
}

func CurrentSchemaRuleset

func CurrentSchemaRuleset() SchemaRuleset

type SchemaShapeKind

type SchemaShapeKind string
const (
	SchemaShapeScalar          SchemaShapeKind = "scalar"
	SchemaShapeNamedStruct     SchemaShapeKind = "named-struct"
	SchemaShapeMap             SchemaShapeKind = "map"
	SchemaShapeSlice           SchemaShapeKind = "slice"
	SchemaShapeAnonymousStruct SchemaShapeKind = "anonymous-struct"
)

type SnapshotBinding

type SnapshotBinding struct {
	Name  string        `json:"name"`
	Value SnapshotValue `json:"value"`
}

type SnapshotDoc

type SnapshotDoc struct {
	Version  uint64            `json:"version"`
	Bindings []SnapshotBinding `json:"bindings"`
}

type SnapshotField

type SnapshotField struct {
	Name  string        `json:"name"`
	Value SnapshotValue `json:"value"`
}

type SnapshotMapEntry

type SnapshotMapEntry struct {
	Key   string        `json:"key"`
	Value SnapshotValue `json:"value"`
}

type SnapshotStats

type SnapshotStats struct {
	Bytes       int
	Bindings    int
	MapEntries  int
	SliceItems  int
	StructNodes int
	Nodes       int
}

func SnapshotStatsForDoc

func SnapshotStatsForDoc(doc SnapshotDoc, snapshotBytes []byte) SnapshotStats

type SnapshotValue

type SnapshotValue struct {
	Kind    string             `json:"kind"`
	Scalar  string             `json:"scalar,omitempty"`
	Fields  []SnapshotField    `json:"fields,omitempty"`
	Entries []SnapshotMapEntry `json:"entries,omitempty"`
	Items   []SnapshotValue    `json:"items,omitempty"`
	IsNil   bool               `json:"is_nil,omitempty"`
}

func ExtractSnapshotValue

func ExtractSnapshotValue(schema ContractSchema, typ TypeRef, tv gno.TypedValue) (SnapshotValue, error)

type SourceRules

type SourceRules struct {
	RequiredPackageName    string
	MaxContractSourceBytes int
}

type StateAccountReader

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

func NewStateAccountReader

func NewStateAccountReader(
	encs encoder.Encoders,
	getStateFunc base.GetStateFunc,
) StateAccountReader

func (StateAccountReader) AccountExists

func (r StateAccountReader) AccountExists(addr string) (bool, error)

type StateBalanceReader

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

func NewStateBalanceReader

func NewStateBalanceReader(
	encs encoder.Encoders,
	getStateFunc base.GetStateFunc,
) StateBalanceReader

func (StateBalanceReader) BalanceOf

func (r StateBalanceReader) BalanceOf(addr string, currencyID string) (string, bool, error)

type StateContractReader

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

func NewStateContractReader

func NewStateContractReader(
	encs encoder.Encoders,
	getStateFunc base.GetStateFunc,
) StateContractReader

func (StateContractReader) IsContractAccount

func (r StateContractReader) IsContractAccount(addr string) (bool, error)

type StateRules

type StateRules struct {
	TopLevelPersistentGlobalKinds        []SchemaShapeKind
	NestedStructFieldKinds               []SchemaShapeKind
	SliceElementKinds                    []SchemaShapeKind
	MapKeyScalarKinds                    []string
	MapValueKinds                        []SchemaShapeKind
	ExplicitPersistentGlobalTypeRequired bool
	EmbeddedFieldsAllowed                bool
	NamedStructAllowed                   bool
	NestedNamedStructAllowed             bool
	AnonymousNestedStructFieldsAllowed   bool
	RecursiveNamedStructsAllowed         bool
	TopLevelMapAllowed                   bool
	NestedMapAllowed                     bool
	MapStringScalarAllowed               bool
	MapStringNamedStructAllowed          bool
	AnonymousStructMapValuesAllowed      bool
	MapValueSlicesAllowed                bool
	MapValueMapsAllowed                  bool
	TopLevelSliceAllowed                 bool
	NestedSliceAllowed                   bool
	SliceScalarAllowed                   bool
	SliceNamedStructAllowed              bool
	AnonymousStructSliceElementsAllowed  bool
	SliceElementSlicesAllowed            bool
	SliceElementMapsAllowed              bool
}

type StructField

type StructField struct {
	Name string
	Type TypeRef
}

type TypeKind

type TypeKind string
const (
	TypeScalar TypeKind = "scalar"
	TypeStruct TypeKind = "struct"
	TypeMap    TypeKind = "map"
	TypeSlice  TypeKind = "slice"
	TypeNamed  TypeKind = "named"
	TypeOpaque TypeKind = "opaque"
)

type TypeRef

type TypeRef struct {
	Kind   TypeKind
	Raw    string
	Scalar string
	Name   string
	Key    *TypeRef
	Elem   *TypeRef
	Fields []StructField
}

func (TypeRef) IsScalar

func (t TypeRef) IsScalar() bool

func (TypeRef) NormalizedString

func (t TypeRef) NormalizedString() string

func (TypeRef) String

func (t TypeRef) String() string

type TypeRegistry

type TypeRegistry struct {
	Structs map[string]TypeRef
}

func NewTypeRegistry

func NewTypeRegistry() TypeRegistry

func (TypeRegistry) Resolve

func (r TypeRegistry) Resolve(t TypeRef) (TypeRef, bool)

Jump to

Keyboard shortcuts

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