From 9afb088bb8c512ce955a2e4d87a980cecfaf92ae Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 5 Oct 2024 10:17:46 +0200 Subject: [PATCH 01/33] chore: make tm2/telemetry less aware of gno.land Signed-off-by: moul <94029+moul@users.noreply.github.com> --- tm2/pkg/telemetry/config/config.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tm2/pkg/telemetry/config/config.go b/tm2/pkg/telemetry/config/config.go index a9aa24d7848..47fc5666342 100644 --- a/tm2/pkg/telemetry/config/config.go +++ b/tm2/pkg/telemetry/config/config.go @@ -19,9 +19,9 @@ type Config struct { func DefaultTelemetryConfig() *Config { return &Config{ MetricsEnabled: false, - MeterName: "gno.land", - ServiceName: "gno.land", - ServiceInstanceID: "gno-node-1", + MeterName: "tm2", + ServiceName: "tm2", + ServiceInstanceID: "tm2-node-1", ExporterEndpoint: "", } } From f5d6d84802df4106a482ad902b739aed339a30ac Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 5 Oct 2024 13:43:42 +0200 Subject: [PATCH 02/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gnovm/pkg/gnolang/helpers.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/gnovm/pkg/gnolang/helpers.go b/gnovm/pkg/gnolang/helpers.go index c6f7e696ea4..3a640fe75a5 100644 --- a/gnovm/pkg/gnolang/helpers.go +++ b/gnovm/pkg/gnolang/helpers.go @@ -28,11 +28,14 @@ func IsRealmPath(pkgPath string) bool { // IsStdlib determines whether s is a pkgpath for a standard library. func IsStdlib(s string) bool { - // NOTE(morgan): this is likely to change in the future as we add support for - // IBC/ICS and we allow import paths to other chains. It might be good to - // (eventually) follow the same rule as Go, which is: does the first - // element of the import path contain a dot? - return !strings.HasPrefix(s, "gno.land/") + parts := strings.Split(s, "/") + if len(parts) > 0 { + // Check if the first part contains a dot + if strings.Contains(parts[0], ".") { + return false // It's a domain, so it's not part of the standard library + } + } + return true } // ---------------------------------------- From ec39ada2e6808d939c791f053869ed4f150f0d45 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 5 Oct 2024 13:55:11 +0200 Subject: [PATCH 03/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gnovm/pkg/gnolang/helpers.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gnovm/pkg/gnolang/helpers.go b/gnovm/pkg/gnolang/helpers.go index 3a640fe75a5..eee06737ef4 100644 --- a/gnovm/pkg/gnolang/helpers.go +++ b/gnovm/pkg/gnolang/helpers.go @@ -10,19 +10,18 @@ import ( // ---------------------------------------- // Functions centralizing definitions -// RealmPathPrefix is the prefix used to identify pkgpaths which are meant to +// RealmPathPrefix is the regex used to identify pkgpaths which are meant to // be realms and as such to have their state persisted. This is used by [IsRealmPath]. -const RealmPathPrefix = "gno.land/r/" +var RealmPathPrefix = regexp.MustCompile(`^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.[a-zA-Z]{2,}/r/`) // ReGnoRunPath is the path used for realms executed in maketx run. // These are not considered realms, as an exception to the RealmPathPrefix rule. -var ReGnoRunPath = regexp.MustCompile(`^gno\.land/r/g[a-z0-9]+/run$`) +var ReGnoRunPath = regexp.MustCompile(`^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.[a-zA-Z]{2,}/r/g[a-z0-9]+/run$`) // IsRealmPath determines whether the given pkgpath is for a realm, and as such // should persist the global state. func IsRealmPath(pkgPath string) bool { - return strings.HasPrefix(pkgPath, RealmPathPrefix) && - // MsgRun pkgPath aren't realms + return RealmPathPrefix.MatchString(pkgPath) && !ReGnoRunPath.MatchString(pkgPath) } From 75a1f88587893e6f28be0ae040aee366c107f9c4 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 5 Oct 2024 13:56:40 +0200 Subject: [PATCH 04/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gnovm/cmd/gno/test.go | 2 +- gnovm/pkg/gnolang/helpers.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index 5884463a552..6047ddadda7 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -258,7 +258,7 @@ func gnoTestPkg( if gnoPkgPath == "" { // unable to read pkgPath from gno.mod, generate a random realm path io.ErrPrintfln("--- WARNING: unable to read package path from gno.mod or gno root directory; try creating a gno.mod file") - gnoPkgPath = gno.RealmPathPrefix + random.RandStr(8) + gnoPkgPath = "gno.land/r/" + random.RandStr(8) } } memPkg := gno.ReadMemPackage(pkgPath, gnoPkgPath) diff --git a/gnovm/pkg/gnolang/helpers.go b/gnovm/pkg/gnolang/helpers.go index eee06737ef4..dea9f120d02 100644 --- a/gnovm/pkg/gnolang/helpers.go +++ b/gnovm/pkg/gnolang/helpers.go @@ -10,18 +10,18 @@ import ( // ---------------------------------------- // Functions centralizing definitions -// RealmPathPrefix is the regex used to identify pkgpaths which are meant to +// ReGnoRealmPath is the regex used to identify pkgpaths which are meant to // be realms and as such to have their state persisted. This is used by [IsRealmPath]. -var RealmPathPrefix = regexp.MustCompile(`^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.[a-zA-Z]{2,}/r/`) +var ReGnoRealmPath = regexp.MustCompile(`^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.[a-zA-Z]{2,}/r/`) // ReGnoRunPath is the path used for realms executed in maketx run. -// These are not considered realms, as an exception to the RealmPathPrefix rule. +// These are not considered realms, as an exception to the ReGnoRealmPath rule. var ReGnoRunPath = regexp.MustCompile(`^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.[a-zA-Z]{2,}/r/g[a-z0-9]+/run$`) // IsRealmPath determines whether the given pkgpath is for a realm, and as such // should persist the global state. func IsRealmPath(pkgPath string) bool { - return RealmPathPrefix.MatchString(pkgPath) && + return ReGnoRealmPath.MatchString(pkgPath) && !ReGnoRunPath.MatchString(pkgPath) } From e982dc1b45a9a492ffe85f258a49168727643541 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 5 Oct 2024 14:14:08 +0200 Subject: [PATCH 05/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gnovm/cmd/gno/test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index 6047ddadda7..d8d569b3337 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -258,7 +258,7 @@ func gnoTestPkg( if gnoPkgPath == "" { // unable to read pkgPath from gno.mod, generate a random realm path io.ErrPrintfln("--- WARNING: unable to read package path from gno.mod or gno root directory; try creating a gno.mod file") - gnoPkgPath = "gno.land/r/" + random.RandStr(8) + gnoPkgPath = "gno.land/r/" + random.RandStr(8) // XXX: "gno.land" hardcoded for convenience } } memPkg := gno.ReadMemPackage(pkgPath, gnoPkgPath) From 46530c9a745030ebe99889507cee7d207707361c Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 5 Oct 2024 14:17:53 +0200 Subject: [PATCH 06/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gno.land/pkg/sdk/vm/common_test.go | 4 +++- gno.land/pkg/sdk/vm/keeper.go | 6 +++++- gnovm/stdlibs/std/context.go | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/gno.land/pkg/sdk/vm/common_test.go b/gno.land/pkg/sdk/vm/common_test.go index 43a8fe1fbec..366ad4b5d04 100644 --- a/gno.land/pkg/sdk/vm/common_test.go +++ b/gno.land/pkg/sdk/vm/common_test.go @@ -17,6 +17,8 @@ import ( "github.com/gnolang/gno/tm2/pkg/store/iavl" ) +const testChainDomain = "gno.land" + type testEnv struct { ctx sdk.Context vmk *VMKeeper @@ -47,7 +49,7 @@ func _setupTestEnv(cacheStdlibs bool) testEnv { ctx := sdk.NewContext(sdk.RunTxModeDeliver, ms, &bft.Header{ChainID: "test-chain-id"}, log.NewNoopLogger()) acck := authm.NewAccountKeeper(iavlCapKey, std.ProtoBaseAccount) bank := bankm.NewBankKeeper(acck) - vmk := NewVMKeeper(baseCapKey, iavlCapKey, acck, bank, 100_000_000) + vmk := NewVMKeeper(baseCapKey, iavlCapKey, acck, bank, testChainDomain, 100_000_000) mcw := ms.MultiCacheWrap() vmk.Initialize(log.NewNoopLogger(), mcw) diff --git a/gno.land/pkg/sdk/vm/keeper.go b/gno.land/pkg/sdk/vm/keeper.go index 365473b3e7a..89614a30917 100644 --- a/gno.land/pkg/sdk/vm/keeper.go +++ b/gno.land/pkg/sdk/vm/keeper.go @@ -63,7 +63,8 @@ type VMKeeper struct { // cached, the DeliverTx persistent state. gnoStore gno.Store - maxCycles int64 // max allowed cylces on VM executions + domain string // chain domain + maxCycles int64 // max allowed cylces on VM executions } // NewVMKeeper returns a new VMKeeper. @@ -72,6 +73,7 @@ func NewVMKeeper( iavlKey store.StoreKey, acck auth.AccountKeeper, bank bank.BankKeeper, + domain string, maxCycles int64, ) *VMKeeper { // TODO: create an Options struct to avoid too many constructor parameters @@ -80,6 +82,7 @@ func NewVMKeeper( iavlKey: iavlKey, acck: acck, bank: bank, + domain: domain, maxCycles: maxCycles, } return vmk @@ -255,6 +258,7 @@ func (vm *VMKeeper) checkNamespacePermission(ctx sdk.Context, creator crypto.Add pkgAddr := gno.DerivePkgAddr(pkgPath) msgCtx := stdlibs.ExecContext{ ChainID: ctx.ChainID(), + ChainDomain: vm.domain, Height: ctx.BlockHeight(), Timestamp: ctx.BlockTime().Unix(), OrigCaller: creator.Bech32(), diff --git a/gnovm/stdlibs/std/context.go b/gnovm/stdlibs/std/context.go index ff5c91a14eb..77c3e047fc4 100644 --- a/gnovm/stdlibs/std/context.go +++ b/gnovm/stdlibs/std/context.go @@ -9,6 +9,7 @@ import ( type ExecContext struct { ChainID string + ChainDomain string Height int64 Timestamp int64 // seconds TimestampNano int64 // nanoseconds, only used for testing. From 588b219e112b4f5ad2a3c0babd777e89b09cd622 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 5 Oct 2024 16:27:16 +0200 Subject: [PATCH 07/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gno.land/pkg/gnoland/app.go | 6 +++++- gno.land/pkg/sdk/vm/keeper.go | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/gno.land/pkg/gnoland/app.go b/gno.land/pkg/gnoland/app.go index 2380658c6e9..6d2fb0b2aee 100644 --- a/gno.land/pkg/gnoland/app.go +++ b/gno.land/pkg/gnoland/app.go @@ -49,6 +49,7 @@ func TestAppOptions(db dbm.DB) *AppOptions { GenesisTxResultHandler: PanicOnFailingTxResultHandler, StdlibDir: filepath.Join(gnoenv.RootDir(), "gnovm", "stdlibs"), CacheStdlibLoad: true, + ChainDomain: "gno.land", }, } } @@ -88,7 +89,7 @@ func NewAppWithOptions(cfg *AppOptions) (abci.Application, error) { // Construct keepers. acctKpr := auth.NewAccountKeeper(mainKey, ProtoGnoAccount) bankKpr := bank.NewBankKeeper(acctKpr) - vmk := vm.NewVMKeeper(baseKey, mainKey, acctKpr, bankKpr, cfg.MaxCycles) + vmk := vm.NewVMKeeper(baseKey, mainKey, acctKpr, bankKpr, cfg.ChainDomain, cfg.MaxCycles) // Set InitChainer icc := cfg.InitChainerConfig @@ -223,6 +224,9 @@ type InitChainerConfig struct { // called several times. CacheStdlibLoad bool + // ChainDomain is the primary domain name for the chain and its packages. + ChainDomain string + // These fields are passed directly by NewAppWithOptions, and should not be // configurable by end-users. baseApp *sdk.BaseApp diff --git a/gno.land/pkg/sdk/vm/keeper.go b/gno.land/pkg/sdk/vm/keeper.go index 89614a30917..30654bcfaf3 100644 --- a/gno.land/pkg/sdk/vm/keeper.go +++ b/gno.land/pkg/sdk/vm/keeper.go @@ -73,7 +73,7 @@ func NewVMKeeper( iavlKey store.StoreKey, acck auth.AccountKeeper, bank bank.BankKeeper, - domain string, + chainDomain string, maxCycles int64, ) *VMKeeper { // TODO: create an Options struct to avoid too many constructor parameters @@ -82,7 +82,7 @@ func NewVMKeeper( iavlKey: iavlKey, acck: acck, bank: bank, - domain: domain, + domain: chainDomain, maxCycles: maxCycles, } return vmk From f81ced5c80c64d1d28ad57b20a9a7ed6dc04346a Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 5 Oct 2024 17:13:28 +0200 Subject: [PATCH 08/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gno.land/pkg/sdk/vm/common_test.go | 5 ++--- gno.land/pkg/sdk/vm/keeper.go | 17 +++++++++++------ gno.land/pkg/sdk/vm/msgs.go | 4 ++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/gno.land/pkg/sdk/vm/common_test.go b/gno.land/pkg/sdk/vm/common_test.go index 366ad4b5d04..c7725fd94b5 100644 --- a/gno.land/pkg/sdk/vm/common_test.go +++ b/gno.land/pkg/sdk/vm/common_test.go @@ -17,8 +17,6 @@ import ( "github.com/gnolang/gno/tm2/pkg/store/iavl" ) -const testChainDomain = "gno.land" - type testEnv struct { ctx sdk.Context vmk *VMKeeper @@ -49,7 +47,8 @@ func _setupTestEnv(cacheStdlibs bool) testEnv { ctx := sdk.NewContext(sdk.RunTxModeDeliver, ms, &bft.Header{ChainID: "test-chain-id"}, log.NewNoopLogger()) acck := authm.NewAccountKeeper(iavlCapKey, std.ProtoBaseAccount) bank := bankm.NewBankKeeper(acck) - vmk := NewVMKeeper(baseCapKey, iavlCapKey, acck, bank, testChainDomain, 100_000_000) + chainDomain := "gno.land" + vmk := NewVMKeeper(baseCapKey, iavlCapKey, acck, bank, chainDomain, 100_000_000) mcw := ms.MultiCacheWrap() vmk.Initialize(log.NewNoopLogger(), mcw) diff --git a/gno.land/pkg/sdk/vm/keeper.go b/gno.land/pkg/sdk/vm/keeper.go index 30654bcfaf3..b85fe94d240 100644 --- a/gno.land/pkg/sdk/vm/keeper.go +++ b/gno.land/pkg/sdk/vm/keeper.go @@ -65,6 +65,9 @@ type VMKeeper struct { domain string // chain domain maxCycles int64 // max allowed cylces on VM executions + + // internal + reNamespace *regexp.Regexp } // NewVMKeeper returns a new VMKeeper. @@ -85,6 +88,9 @@ func NewVMKeeper( domain: chainDomain, maxCycles: maxCycles, } + + // Namespace can be either a user or crypto address. + vmk.reNamespace = regexp.MustCompile(`^` + chainDomain + `/(?:r|p)/([\.~_a-zA-Z0-9]+)`) return vmk } @@ -192,6 +198,7 @@ func loadStdlibPackage(pkgPath, stdlibDir string, store gno.Store) { } m := gno.NewMachineWithOptions(gno.MachineOptions{ + // XXX: gno.land, vm.domain, other? PkgPath: "gno.land/r/stdlibs/" + pkgPath, // PkgPath: pkgPath, XXX why? Output: os.Stdout, @@ -226,16 +233,13 @@ func (vm *VMKeeper) getGnoTransactionStore(ctx sdk.Context) gno.TransactionStore return txStore } -// Namespace can be either a user or crypto address. -var reNamespace = regexp.MustCompile(`^gno.land/(?:r|p)/([\.~_a-zA-Z0-9]+)`) - // checkNamespacePermission check if the user as given has correct permssion to on the given pkg path func (vm *VMKeeper) checkNamespacePermission(ctx sdk.Context, creator crypto.Address, pkgPath string) error { - const sysUsersPkg = "gno.land/r/sys/users" + sysUsersPkg := vm.domain + "/r/sys/users" // configurable through sys/params store := vm.getGnoTransactionStore(ctx) - match := reNamespace.FindStringSubmatch(pkgPath) + match := vm.reNamespace.FindStringSubmatch(pkgPath) switch len(match) { case 0: return ErrInvalidPkgPath(pkgPath) // no match @@ -533,7 +537,7 @@ func (vm *VMKeeper) Run(ctx sdk.Context, msg MsgRun) (res string, err error) { // coerce path to right one. // the path in the message must be "" or the following path. // this is already checked in MsgRun.ValidateBasic - memPkg.Path = "gno.land/r/" + msg.Caller.String() + "/run" + memPkg.Path = vm.domain + "/r/" + msg.Caller.String() + "/run" // Validate arguments. callerAcc := vm.acck.GetAccount(ctx, caller) @@ -559,6 +563,7 @@ func (vm *VMKeeper) Run(ctx sdk.Context, msg MsgRun) (res string, err error) { // Parse and run the files, construct *PV. msgCtx := stdlibs.ExecContext{ ChainID: ctx.ChainID(), + ChainDomain: vm.domain, Height: ctx.BlockHeight(), Timestamp: ctx.BlockTime().Unix(), Msg: msg, diff --git a/gno.land/pkg/sdk/vm/msgs.go b/gno.land/pkg/sdk/vm/msgs.go index d650c23f382..2c7d7752427 100644 --- a/gno.land/pkg/sdk/vm/msgs.go +++ b/gno.land/pkg/sdk/vm/msgs.go @@ -185,8 +185,8 @@ func (msg MsgRun) ValidateBasic() error { } // Force memPkg path to the reserved run path. - wantPath := "gno.land/r/" + msg.Caller.String() + "/run" - if path := msg.Package.Path; path != "" && path != wantPath { + wantSuffix := "/r/" + msg.Caller.String() + "/run" + if path := msg.Package.Path; path != "" && !strings.HasSuffix(path, wantSuffix) { return ErrInvalidPkgPath(fmt.Sprintf("invalid pkgpath for MsgRun: %q", path)) } From 0b58baa933313f1d228ab6d3c994b7ad44414486 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 5 Oct 2024 17:27:01 +0200 Subject: [PATCH 09/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gno.land/pkg/sdk/vm/keeper.go | 3 +++ tm2/pkg/std/memfile.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/gno.land/pkg/sdk/vm/keeper.go b/gno.land/pkg/sdk/vm/keeper.go index b85fe94d240..75edd1e3b3a 100644 --- a/gno.land/pkg/sdk/vm/keeper.go +++ b/gno.land/pkg/sdk/vm/keeper.go @@ -332,6 +332,9 @@ func (vm *VMKeeper) AddPackage(ctx sdk.Context, msg MsgAddPackage) (err error) { if err := msg.Package.Validate(); err != nil { return ErrInvalidPkgPath(err.Error()) } + if path := msg.Package.Path; !strings.HasPrefix(path, vm.domain+"/") { + return ErrInvalidPkgPath("invalid domain") + } if pv := gnostore.GetPackage(pkgPath, false); pv != nil { return ErrPkgAlreadyExists("package already exists: " + pkgPath) } diff --git a/tm2/pkg/std/memfile.go b/tm2/pkg/std/memfile.go index 01bc18c1487..539f102a47c 100644 --- a/tm2/pkg/std/memfile.go +++ b/tm2/pkg/std/memfile.go @@ -41,7 +41,7 @@ const pathLengthLimit = 256 var ( rePkgName = regexp.MustCompile(`^[a-z][a-z0-9_]*$`) - rePkgOrRlmPath = regexp.MustCompile(`^gno\.land\/(?:p|r)(?:\/_?[a-z]+[a-z0-9_]*)+$`) + rePkgOrRlmPath = regexp.MustCompile(`^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.[a-zA-Z]{2,}\/(?:p|r)(?:\/_?[a-z]+[a-z0-9_]*)+$`) reFileName = regexp.MustCompile(`^([a-zA-Z0-9_]*\.[a-z0-9_\.]*|LICENSE|README)$`) ) From 302d73014dde747481879423608abd02e861605f Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 5 Oct 2024 17:33:37 +0200 Subject: [PATCH 10/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gno.land/pkg/sdk/vm/keeper.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gno.land/pkg/sdk/vm/keeper.go b/gno.land/pkg/sdk/vm/keeper.go index 75edd1e3b3a..8436421dc72 100644 --- a/gno.land/pkg/sdk/vm/keeper.go +++ b/gno.land/pkg/sdk/vm/keeper.go @@ -332,8 +332,8 @@ func (vm *VMKeeper) AddPackage(ctx sdk.Context, msg MsgAddPackage) (err error) { if err := msg.Package.Validate(); err != nil { return ErrInvalidPkgPath(err.Error()) } - if path := msg.Package.Path; !strings.HasPrefix(path, vm.domain+"/") { - return ErrInvalidPkgPath("invalid domain") + if !strings.HasPrefix(pkgPath, vm.domain+"/") { + return ErrInvalidPkgPath("invalid domain: " + pkgPath) } if pv := gnostore.GetPackage(pkgPath, false); pv != nil { return ErrPkgAlreadyExists("package already exists: " + pkgPath) From f6dd011c255b7d03f5f316f58592333a2fabb34f Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 5 Oct 2024 18:35:06 +0200 Subject: [PATCH 11/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- contribs/gnodev/pkg/dev/node.go | 6 ++++-- gnovm/stdlibs/std/native.gno | 5 +++-- gnovm/stdlibs/std/native.go | 4 ++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/contribs/gnodev/pkg/dev/node.go b/contribs/gnodev/pkg/dev/node.go index c3e70366fb2..0ee3ef3f7b7 100644 --- a/contribs/gnodev/pkg/dev/node.go +++ b/contribs/gnodev/pkg/dev/node.go @@ -547,7 +547,7 @@ func (n *Node) genesisTxResultHandler(ctx sdk.Context, tx std.Tx, res sdk.Result return } -func newNodeConfig(tmc *tmcfg.Config, chainid string, appstate gnoland.GnoGenesisState) *gnoland.InMemoryNodeConfig { +func newNodeConfig(tmc *tmcfg.Config, chainid, chaindomain string, appstate gnoland.GnoGenesisState) *gnoland.InMemoryNodeConfig { // Create Mocked Identity pv := gnoland.NewMockedPrivValidator() genesis := gnoland.NewDefaultGenesisConfig(chainid) @@ -564,10 +564,12 @@ func newNodeConfig(tmc *tmcfg.Config, chainid string, appstate gnoland.GnoGenesi }, } - return &gnoland.InMemoryNodeConfig{ + cfg := &gnoland.InMemoryNodeConfig{ PrivValidator: pv, TMConfig: tmc, Genesis: genesis, GenesisMaxVMCycles: 100_000_000, } + cfg.InitChainerConfig.ChainDomain = chaindomain + return cfg } diff --git a/gnovm/stdlibs/std/native.gno b/gnovm/stdlibs/std/native.gno index 22a16fc18d1..d70710b88b2 100644 --- a/gnovm/stdlibs/std/native.gno +++ b/gnovm/stdlibs/std/native.gno @@ -10,8 +10,9 @@ func AssertOriginCall() // injected // MsgRun. func IsOriginCall() bool // injected -func GetChainID() string // injected -func GetHeight() int64 // injected +func GetChainID() string // injected +func GetChainDomain() string // injected +func GetHeight() int64 // injected func GetOrigSend() Coins { den, amt := origSend() diff --git a/gnovm/stdlibs/std/native.go b/gnovm/stdlibs/std/native.go index f185a52f249..04e3195711c 100644 --- a/gnovm/stdlibs/std/native.go +++ b/gnovm/stdlibs/std/native.go @@ -27,6 +27,10 @@ func GetChainID(m *gno.Machine) string { return GetContext(m).ChainID } +func GetChainDomain(m *gno.Machine) string { + return GetContext(m).ChainDomain +} + func GetHeight(m *gno.Machine) int64 { return GetContext(m).Height } From 6a750671501493e00aa8c2a5800cf776cd31547e Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 5 Oct 2024 18:38:53 +0200 Subject: [PATCH 12/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- misc/genstd/Makefile | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 misc/genstd/Makefile diff --git a/misc/genstd/Makefile b/misc/genstd/Makefile new file mode 100644 index 00000000000..6b5015ce3f8 --- /dev/null +++ b/misc/genstd/Makefile @@ -0,0 +1,5 @@ +run: + go run . + +test: + go test -v . From b5b17d1aa3e273d6fa3afac030314bc09add2efa Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 5 Oct 2024 18:41:55 +0200 Subject: [PATCH 13/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gnovm/stdlibs/generated.go | 20 ++++++++++++++++++++ misc/genstd/Makefile | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/gnovm/stdlibs/generated.go b/gnovm/stdlibs/generated.go index 4c460e220b7..67b0ef24277 100644 --- a/gnovm/stdlibs/generated.go +++ b/gnovm/stdlibs/generated.go @@ -469,6 +469,26 @@ var nativeFuncs = [...]NativeFunc{ )) }, }, + { + "std", + "GetChainDomain", + []gno.FieldTypeExpr{}, + []gno.FieldTypeExpr{ + {Name: gno.N("r0"), Type: gno.X("string")}, + }, + true, + func(m *gno.Machine) { + r0 := libs_std.GetChainDomain( + m, + ) + + m.PushValue(gno.Go2GnoValue( + m.Alloc, + m.Store, + reflect.ValueOf(&r0).Elem(), + )) + }, + }, { "std", "GetHeight", diff --git a/misc/genstd/Makefile b/misc/genstd/Makefile index 6b5015ce3f8..2022a6cc2b4 100644 --- a/misc/genstd/Makefile +++ b/misc/genstd/Makefile @@ -1,5 +1,6 @@ run: - go run . + cd ../../gnovm/stdlibs && go run ../../misc/genstd + cd ../../gnovm/tests/stdlibs && go run ../../../misc/genstd test: go test -v . From b2f90b4582083317238b4fbb272e8d31bd02006e Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 5 Oct 2024 18:51:14 +0200 Subject: [PATCH 14/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gno.land/cmd/gnoland/start.go | 16 ++++++++-------- gno.land/pkg/integration/testing_node.go | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/gno.land/cmd/gnoland/start.go b/gno.land/cmd/gnoland/start.go index 21f0cb4b1a6..32f3dd37493 100644 --- a/gno.land/cmd/gnoland/start.go +++ b/gno.land/cmd/gnoland/start.go @@ -50,8 +50,8 @@ type startCfg struct { genesisRemote string // TODO: remove as part of https://github.com/gnolang/gno/issues/1952 genesisFile string chainID string + chainDomain string dataDir string - genesisMaxVMCycles int64 config string lazyInit bool @@ -116,6 +116,13 @@ func (c *startCfg) RegisterFlags(fs *flag.FlagSet) { "the ID of the chain", ) + fs.StringVar( + &c.chainDomain, + "chaindomain", + "gno.land", + "the domain of the chain for packages", + ) + fs.StringVar( &c.gnoRootDir, "gnoroot-dir", @@ -137,13 +144,6 @@ func (c *startCfg) RegisterFlags(fs *flag.FlagSet) { "replacement for '%%REMOTE%%' in genesis", ) - fs.Int64Var( - &c.genesisMaxVMCycles, - "genesis-max-vm-cycles", - 100_000_000, - "set maximum allowed vm cycles per operation. Zero means no limit.", - ) - fs.StringVar( &c.config, flagConfigFlag, diff --git a/gno.land/pkg/integration/testing_node.go b/gno.land/pkg/integration/testing_node.go index 5e9e2272049..2c34f62ade3 100644 --- a/gno.land/pkg/integration/testing_node.go +++ b/gno.land/pkg/integration/testing_node.go @@ -90,6 +90,7 @@ func TestingMinimalNodeConfig(t TestingTS, gnoroot string) *gnoland.InMemoryNode InitChainerConfig: gnoland.InitChainerConfig{ GenesisTxResultHandler: gnoland.PanicOnFailingTxResultHandler, CacheStdlibLoad: true, + ChainDomain: "gno.land", }, } } From 8a444b490dd4aa71b2b54981c5bde9c2f8078116 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 5 Oct 2024 19:12:03 +0200 Subject: [PATCH 15/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- contribs/gnodev/cmd/gnodev/main.go | 25 ++++++++++++++++-------- contribs/gnodev/cmd/gnodev/setup_node.go | 2 +- contribs/gnodev/pkg/dev/node.go | 6 ++++-- contribs/gnodev/pkg/dev/node_test.go | 6 +++--- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/contribs/gnodev/cmd/gnodev/main.go b/contribs/gnodev/cmd/gnodev/main.go index 2c694b608bb..c9d6487d753 100644 --- a/contribs/gnodev/cmd/gnodev/main.go +++ b/contribs/gnodev/cmd/gnodev/main.go @@ -61,18 +61,20 @@ type devCfg struct { webRemoteHelperAddr string // Node Configuration - minimal bool - verbose bool - noWatch bool - noReplay bool - maxGas int64 - chainId string - serverMode bool - unsafeAPI bool + minimal bool + verbose bool + noWatch bool + noReplay bool + maxGas int64 + chainId string + chainDomain string + serverMode bool + unsafeAPI bool } var defaultDevOptions = &devCfg{ chainId: "dev", + chainDomain: "gno.land", maxGas: 10_000_000_000, webListenerAddr: "127.0.0.1:8888", nodeRPCListenerAddr: "127.0.0.1:26657", @@ -203,6 +205,13 @@ func (c *devCfg) RegisterFlags(fs *flag.FlagSet) { "set node ChainID", ) + fs.StringVar( + &c.chainDomain, + "chain-domain", + defaultDevOptions.chainDomain, + "set node ChainDomain", + ) + fs.BoolVar( &c.noWatch, "no-watch", diff --git a/contribs/gnodev/cmd/gnodev/setup_node.go b/contribs/gnodev/cmd/gnodev/setup_node.go index 578cf525751..f671a3daa1f 100644 --- a/contribs/gnodev/cmd/gnodev/setup_node.go +++ b/contribs/gnodev/cmd/gnodev/setup_node.go @@ -51,7 +51,7 @@ func setupDevNodeConfig( balances gnoland.Balances, pkgspath []gnodev.PackagePath, ) *gnodev.NodeConfig { - config := gnodev.DefaultNodeConfig(cfg.root) + config := gnodev.DefaultNodeConfig(cfg.root, cfg.chainDomain) config.Logger = logger config.Emitter = emitter diff --git a/contribs/gnodev/pkg/dev/node.go b/contribs/gnodev/pkg/dev/node.go index 0ee3ef3f7b7..c748c56661b 100644 --- a/contribs/gnodev/pkg/dev/node.go +++ b/contribs/gnodev/pkg/dev/node.go @@ -41,9 +41,10 @@ type NodeConfig struct { NoReplay bool MaxGasPerBlock int64 ChainID string + ChainDomain string } -func DefaultNodeConfig(rootdir string) *NodeConfig { +func DefaultNodeConfig(rootdir, domain string) *NodeConfig { tmc := gnoland.NewDefaultTMConfig(rootdir) tmc.Consensus.SkipTimeoutCommit = false // avoid time drifting, see issue #1507 tmc.Consensus.WALDisabled = true @@ -63,6 +64,7 @@ func DefaultNodeConfig(rootdir string) *NodeConfig { DefaultDeployer: defaultDeployer, BalancesList: balances, ChainID: tmc.ChainID(), + ChainDomain: domain, TMConfig: tmc, SkipFailingGenesisTxs: true, MaxGasPerBlock: 10_000_000_000, @@ -468,7 +470,7 @@ func (n *Node) rebuildNode(ctx context.Context, genesis gnoland.GnoGenesisState) } // Setup node config - nodeConfig := newNodeConfig(n.config.TMConfig, n.config.ChainID, genesis) + nodeConfig := newNodeConfig(n.config.TMConfig, n.config.ChainID, n.config.ChainDomain, genesis) nodeConfig.GenesisTxResultHandler = n.genesisTxResultHandler // Speed up stdlib loading after first start (saves about 2-3 seconds on each reload). nodeConfig.CacheStdlibLoad = true diff --git a/contribs/gnodev/pkg/dev/node_test.go b/contribs/gnodev/pkg/dev/node_test.go index 11b0a2090d7..14b719319c2 100644 --- a/contribs/gnodev/pkg/dev/node_test.go +++ b/contribs/gnodev/pkg/dev/node_test.go @@ -34,7 +34,7 @@ func TestNewNode_NoPackages(t *testing.T) { logger := log.NewTestingLogger(t) // Call NewDevNode with no package should work - cfg := DefaultNodeConfig(gnoenv.RootDir()) + cfg := DefaultNodeConfig(gnoenv.RootDir(), "gno.land") cfg.Logger = logger node, err := NewDevNode(ctx, cfg) require.NoError(t, err) @@ -62,7 +62,7 @@ func Render(_ string) string { return "foo" } logger := log.NewTestingLogger(t) // Call NewDevNode with no package should work - cfg := DefaultNodeConfig(gnoenv.RootDir()) + cfg := DefaultNodeConfig(gnoenv.RootDir(), "gno.land") cfg.PackagesPathList = []PackagePath{pkgpath} cfg.Logger = logger node, err := NewDevNode(ctx, cfg) @@ -295,7 +295,7 @@ func newTestingDevNode(t *testing.T, pkgslist ...PackagePath) (*Node, *mock.Serv emitter := &mock.ServerEmitter{} // Call NewDevNode with no package should work - cfg := DefaultNodeConfig(gnoenv.RootDir()) + cfg := DefaultNodeConfig(gnoenv.RootDir(), "gno.land") cfg.PackagesPathList = pkgslist cfg.Emitter = emitter cfg.Logger = logger From 5b72ed710ae986ac65166d34bb7a1b9bd1748c4d Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 5 Oct 2024 22:56:53 +0200 Subject: [PATCH 16/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- tm2/pkg/std/memfile_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tm2/pkg/std/memfile_test.go b/tm2/pkg/std/memfile_test.go index 3e1fb49e131..71b0dad8423 100644 --- a/tm2/pkg/std/memfile_test.go +++ b/tm2/pkg/std/memfile_test.go @@ -158,13 +158,13 @@ func TestMemPackage_Validate(t *testing.T) { "invalid package/realm path", }, { - "Invalid path", + "Custom domain", &MemPackage{ Name: "hey", Path: "github.com/p/path/path", Files: []*MemFile{{Name: "a.gno"}}, }, - "invalid package/realm path", + "", }, { "Special character", From 57b2983c827d4a3888d8ddf6ca11f0961805af7a Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 5 Oct 2024 23:12:44 +0200 Subject: [PATCH 17/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gnovm/tests/files/std5_stdlibs.gno | 4 ++-- gnovm/tests/files/std8_stdlibs.gno | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gnovm/tests/files/std5_stdlibs.gno b/gnovm/tests/files/std5_stdlibs.gno index 4afa09da8d3..061df0d6ac0 100644 --- a/gnovm/tests/files/std5_stdlibs.gno +++ b/gnovm/tests/files/std5_stdlibs.gno @@ -13,10 +13,10 @@ func main() { // Stacktrace: // panic: frame not found -// callerAt(n) +// callerAt(n) // gonative:std.callerAt // std.GetCallerAt(2) -// std/native.gno:44 +// std/native.gno:45 // main() // main/files/std5_stdlibs.gno:10 diff --git a/gnovm/tests/files/std8_stdlibs.gno b/gnovm/tests/files/std8_stdlibs.gno index ab5e15bd618..b59a7a59a84 100644 --- a/gnovm/tests/files/std8_stdlibs.gno +++ b/gnovm/tests/files/std8_stdlibs.gno @@ -23,10 +23,10 @@ func main() { // Stacktrace: // panic: frame not found -// callerAt(n) +// callerAt(n) // gonative:std.callerAt // std.GetCallerAt(4) -// std/native.gno:44 +// std/native.gno:45 // fn() // main/files/std8_stdlibs.gno:16 // testutils.WrapCall(inner) From 1ff1d4c57c8a0bf95fe0521fc15891904d090b96 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sat, 5 Oct 2024 23:20:45 +0200 Subject: [PATCH 18/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gnovm/tests/file.go | 1 + gnovm/tests/files/zrealm_natbind1_stdlibs.gno | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 gnovm/tests/files/zrealm_natbind1_stdlibs.gno diff --git a/gnovm/tests/file.go b/gnovm/tests/file.go index f6bd789f1bf..15bec958bd3 100644 --- a/gnovm/tests/file.go +++ b/gnovm/tests/file.go @@ -58,6 +58,7 @@ func TestContext(pkgPath string, send std.Coins) *teststd.TestExecContext { banker := newTestBanker(pkgAddr.Bech32(), pkgCoins) ctx := stdlibs.ExecContext{ ChainID: "dev", + ChainDomain: "tests.gno.land", Height: 123, Timestamp: 1234567890, Msg: nil, diff --git a/gnovm/tests/files/zrealm_natbind1_stdlibs.gno b/gnovm/tests/files/zrealm_natbind1_stdlibs.gno new file mode 100644 index 00000000000..f44b6ab4fcf --- /dev/null +++ b/gnovm/tests/files/zrealm_natbind1_stdlibs.gno @@ -0,0 +1,16 @@ +// PKGPATH: gno.land/r/test +package test + +import ( + "std" +) + +func main() { + println(std.GetChainDomain()) +} + +// Output: +// tests.gno.land + +// Realm: +// switchrealm["gno.land/r/test"] From 448e962bc4dd0a2711510c1d4869bb83723cd3be Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sun, 6 Oct 2024 11:18:18 +0200 Subject: [PATCH 19/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gno.land/pkg/sdk/vm/keeper_test.go | 39 +++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/gno.land/pkg/sdk/vm/keeper_test.go b/gno.land/pkg/sdk/vm/keeper_test.go index 9257da2ddaf..a1c301ecc16 100644 --- a/gno.land/pkg/sdk/vm/keeper_test.go +++ b/gno.land/pkg/sdk/vm/keeper_test.go @@ -21,7 +21,7 @@ import ( "github.com/gnolang/gno/tm2/pkg/store/types" ) -var coinsString = ugnot.ValueString(10000000) +var coinsString = ugnot.ValueString(10_000_000) func TestVMKeeperAddPackage(t *testing.T) { env := setupTestEnv() @@ -67,6 +67,43 @@ func Echo() string { return "hello world" } assert.Equal(t, expected, memFile.Body) } +func TestVMKeeperAddPackage_InvalidDomain(t *testing.T) { + env := setupTestEnv() + ctx := env.vmk.MakeGnoTransactionStore(env.ctx) + + // Give "addr1" some gnots. + addr := crypto.AddressFromPreimage([]byte("addr1")) + acc := env.acck.NewAccountWithAddress(ctx, addr) + env.acck.SetAccount(ctx, acc) + env.bank.SetCoins(ctx, addr, std.MustParseCoins(coinsString)) + assert.True(t, env.bank.GetCoins(ctx, addr).IsEqual(std.MustParseCoins(coinsString))) + + // Create test package. + files := []*std.MemFile{ + { + Name: "test.gno", + Body: `package test +func Echo() string {return "hello world"}`, + }, + } + pkgPath := "anotherdomain.land/r/test" + msg1 := NewMsgAddPackage(addr, pkgPath, files) + assert.Nil(t, env.vmk.getGnoTransactionStore(ctx).GetPackage(pkgPath, false)) + + err := env.vmk.AddPackage(ctx, msg1) + + assert.Error(t, err, ErrInvalidPkgPath("invalid domain: anotherdomain.land/r/test")) + assert.Nil(t, env.vmk.getGnoTransactionStore(ctx).GetPackage(pkgPath, false)) + + err = env.vmk.AddPackage(ctx, msg1) + assert.Error(t, err, ErrInvalidPkgPath("invalid domain: anotherdomain.land/r/test")) + + // added package is formatted + store := env.vmk.getGnoTransactionStore(ctx) + memFile := store.GetMemFile("gno.land/r/test", "test.gno") + assert.Nil(t, memFile) +} + // Sending total send amount succeeds. func TestVMKeeperOrigSend1(t *testing.T) { env := setupTestEnv() From 4f031867e679eb1e1e5dcc36017395e8a80ae756 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Sun, 6 Oct 2024 11:26:51 +0200 Subject: [PATCH 20/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gno.land/cmd/gnoland/testdata/addpkg_domain.txtar | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 gno.land/cmd/gnoland/testdata/addpkg_domain.txtar diff --git a/gno.land/cmd/gnoland/testdata/addpkg_domain.txtar b/gno.land/cmd/gnoland/testdata/addpkg_domain.txtar new file mode 100644 index 00000000000..25e4fe0d3a3 --- /dev/null +++ b/gno.land/cmd/gnoland/testdata/addpkg_domain.txtar @@ -0,0 +1,15 @@ +gnoland start + +# addpkg with anotherdomain.land +! gnokey maketx addpkg -pkgdir $WORK -pkgpath anotherdomain.land/r/foobar/bar -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +stdout 'TX HASH:' +stderr 'invalid package path' +stderr 'invalid domain: anotherdomain.land/r/foobar/bar' + +# addpkg with gno.land +gnokey maketx addpkg -pkgdir $WORK -pkgpath gno.land/r/foobar/bar -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +stdout 'OK!' + +-- bar.gno -- +package bar +func Render(path string) string { return "hello" } From f0b41dfa565f4b341239b498ca21d836d827b8d9 Mon Sep 17 00:00:00 2001 From: Manfred Touron <94029+moul@users.noreply.github.com> Date: Sun, 6 Oct 2024 12:46:27 +0200 Subject: [PATCH 21/33] Update gno.land/pkg/sdk/vm/keeper.go Co-authored-by: n0izn0iz --- gno.land/pkg/sdk/vm/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gno.land/pkg/sdk/vm/keeper.go b/gno.land/pkg/sdk/vm/keeper.go index 8436421dc72..2ff162df9bf 100644 --- a/gno.land/pkg/sdk/vm/keeper.go +++ b/gno.land/pkg/sdk/vm/keeper.go @@ -90,7 +90,7 @@ func NewVMKeeper( } // Namespace can be either a user or crypto address. - vmk.reNamespace = regexp.MustCompile(`^` + chainDomain + `/(?:r|p)/([\.~_a-zA-Z0-9]+)`) + vmk.reNamespace = regexp.MustCompile(`^` + regexp.QuoteMeta(chainDomain) + `/(?:r|p)/([\.~_a-zA-Z0-9]+)`) return vmk } From 4633be42a88196c6352c780ebff12ac39e0c654b Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Wed, 13 Nov 2024 19:59:58 +0100 Subject: [PATCH 22/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gno.land/pkg/sdk/vm/keeper.go | 38 +++++++++++------------------- gno.land/pkg/sdk/vm/keeper_test.go | 2 +- gno.land/pkg/sdk/vm/params.go | 20 ++++++++++++++++ 3 files changed, 35 insertions(+), 25 deletions(-) create mode 100644 gno.land/pkg/sdk/vm/params.go diff --git a/gno.land/pkg/sdk/vm/keeper.go b/gno.land/pkg/sdk/vm/keeper.go index fc3926d2667..c6799885a9e 100644 --- a/gno.land/pkg/sdk/vm/keeper.go +++ b/gno.land/pkg/sdk/vm/keeper.go @@ -68,11 +68,6 @@ type VMKeeper struct { // cached, the DeliverTx persistent state. gnoStore gno.Store - - domain string // chain domain - - // internal - reNamespace *regexp.Regexp } // NewVMKeeper returns a new VMKeeper. @@ -91,8 +86,6 @@ func NewVMKeeper( prmk: prmk, } - // Namespace can be either a user or crypto address. - vmk.reNamespace = regexp.MustCompile(`^` + regexp.QuoteMeta(chainDomain) + `/(?:r|p)/([\.~_a-zA-Z0-9]+)`) return vmk } @@ -235,25 +228,23 @@ func (vm *VMKeeper) getGnoTransactionStore(ctx sdk.Context) gno.TransactionStore } // Namespace can be either a user or crypto address. -var reNamespace = regexp.MustCompile(`^gno.land/(?:r|p)/([\.~_a-zA-Z0-9]+)`) - -const ( - sysUsersPkgParamPath = "gno.land/r/sys/params.sys.users_pkgpath.string" - chainDomainParamPath = "gno.land/r/sys/params.chain.domain.string" -) +var reNamespace = regexp.MustCompile(`^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/(?:r|p)/([\.~_a-zA-Z0-9]+)`) // checkNamespacePermission check if the user as given has correct permssion to on the given pkg path func (vm *VMKeeper) checkNamespacePermission(ctx sdk.Context, creator crypto.Address, pkgPath string) error { - sysUsersPkg := vm.domain + "/r/sys/users" // configurable through sys/params - var sysUsersPkg string - vm.prmk.GetString(ctx, sysUsersPkgParamPath, &sysUsersPkg) + sysUsersPkg := vm.getSysUsersPkgParam(ctx) if sysUsersPkg == "" { return nil } + chainDomain := vm.getChainDomainParam(ctx) store := vm.getGnoTransactionStore(ctx) - match := vm.reNamespace.FindStringSubmatch(pkgPath) + if !strings.HasPrefix(pkgPath, chainDomain+"/") { + return ErrInvalidPkgPath(pkgPath) // no match + } + + match := reNamespace.FindStringSubmatch(pkgPath) switch len(match) { case 0: return ErrInvalidPkgPath(pkgPath) // no match @@ -261,9 +252,6 @@ func (vm *VMKeeper) checkNamespacePermission(ctx sdk.Context, creator crypto.Add default: panic("invalid pattern while matching pkgpath") } - if len(match) != 2 { - return ErrInvalidPkgPath(pkgPath) - } username := match[1] // if `sysUsersPkg` does not exist -> skip validation. @@ -276,7 +264,7 @@ func (vm *VMKeeper) checkNamespacePermission(ctx sdk.Context, creator crypto.Add pkgAddr := gno.DerivePkgAddr(pkgPath) msgCtx := stdlibs.ExecContext{ ChainID: ctx.ChainID(), - ChainDomain: vm.domain, + ChainDomain: chainDomain, Height: ctx.BlockHeight(), Timestamp: ctx.BlockTime().Unix(), OrigCaller: creator.Bech32(), @@ -334,6 +322,7 @@ func (vm *VMKeeper) AddPackage(ctx sdk.Context, msg MsgAddPackage) (err error) { memPkg := msg.Package deposit := msg.Deposit gnostore := vm.getGnoTransactionStore(ctx) + chainDomain := vm.getChainDomainParam(ctx) // Validate arguments. if creator.IsZero() { @@ -346,7 +335,7 @@ func (vm *VMKeeper) AddPackage(ctx sdk.Context, msg MsgAddPackage) (err error) { if err := msg.Package.Validate(); err != nil { return ErrInvalidPkgPath(err.Error()) } - if !strings.HasPrefix(pkgPath, vm.domain+"/") { + if !strings.HasPrefix(pkgPath, chainDomain+"/") { return ErrInvalidPkgPath("invalid domain: " + pkgPath) } if pv := gnostore.GetPackage(pkgPath, false); pv != nil { @@ -550,11 +539,12 @@ func (vm *VMKeeper) Run(ctx sdk.Context, msg MsgRun) (res string, err error) { gnostore := vm.getGnoTransactionStore(ctx) send := msg.Send memPkg := msg.Package + chainDomain := vm.getChainDomainParam(ctx) // coerce path to right one. // the path in the message must be "" or the following path. // this is already checked in MsgRun.ValidateBasic - memPkg.Path = vm.domain + "/r/" + msg.Caller.String() + "/run" + memPkg.Path = chainDomain + "/r/" + msg.Caller.String() + "/run" // Validate arguments. callerAcc := vm.acck.GetAccount(ctx, caller) @@ -580,7 +570,7 @@ func (vm *VMKeeper) Run(ctx sdk.Context, msg MsgRun) (res string, err error) { // Parse and run the files, construct *PV. msgCtx := stdlibs.ExecContext{ ChainID: ctx.ChainID(), - ChainDomain: vm.domain, + ChainDomain: chainDomain, Height: ctx.BlockHeight(), Timestamp: ctx.BlockTime().Unix(), Msg: msg, diff --git a/gno.land/pkg/sdk/vm/keeper_test.go b/gno.land/pkg/sdk/vm/keeper_test.go index 7eccb5bdf0f..f8144988c44 100644 --- a/gno.land/pkg/sdk/vm/keeper_test.go +++ b/gno.land/pkg/sdk/vm/keeper_test.go @@ -80,7 +80,7 @@ func TestVMKeeperAddPackage_InvalidDomain(t *testing.T) { assert.True(t, env.bank.GetCoins(ctx, addr).IsEqual(std.MustParseCoins(coinsString))) // Create test package. - files := []*std.MemFile{ + files := []*gnovm.MemFile{ { Name: "test.gno", Body: `package test diff --git a/gno.land/pkg/sdk/vm/params.go b/gno.land/pkg/sdk/vm/params.go new file mode 100644 index 00000000000..b3d0f43b2f5 --- /dev/null +++ b/gno.land/pkg/sdk/vm/params.go @@ -0,0 +1,20 @@ +package vm + +import "github.com/gnolang/gno/tm2/pkg/sdk" + +const ( + sysUsersPkgParamPath = "gno.land/r/sys/params.sys.users_pkgpath.string" + chainDomainParamPath = "gno.land/r/sys/params.chain.domain.string" +) + +func (vm *VMKeeper) getChainDomainParam(ctx sdk.Context) string { + chainDomain := "gno.land" // default + vm.prmk.GetString(ctx, chainDomainParamPath, &chainDomain) + return chainDomain +} + +func (vm *VMKeeper) getSysUsersPkgParam(ctx sdk.Context) string { + var sysUsersPkg string + vm.prmk.GetString(ctx, sysUsersPkgParamPath, &sysUsersPkg) + return sysUsersPkg +} From 6fcbd1ca442e8e6428cefe28ae5c4ad6b9bf089a Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Wed, 13 Nov 2024 20:26:32 +0100 Subject: [PATCH 23/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gno.land/pkg/sdk/vm/gas_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gno.land/pkg/sdk/vm/gas_test.go b/gno.land/pkg/sdk/vm/gas_test.go index 3a11d97c235..677d86a0331 100644 --- a/gno.land/pkg/sdk/vm/gas_test.go +++ b/gno.land/pkg/sdk/vm/gas_test.go @@ -75,7 +75,7 @@ func TestAddPkgDeliverTx(t *testing.T) { assert.True(t, res.IsOK()) // NOTE: let's try to keep this bellow 100_000 :) - assert.Equal(t, int64(92825), gasDeliver) + assert.Equal(t, int64(93825), gasDeliver) } // Enough gas for a failed transaction. @@ -95,7 +95,7 @@ func TestAddPkgDeliverTxFailed(t *testing.T) { gasDeliver := gctx.GasMeter().GasConsumed() assert.False(t, res.IsOK()) - assert.Equal(t, int64(2231), gasDeliver) + assert.Equal(t, int64(3231), gasDeliver) } // Not enough gas for a failed transaction. From c874441aba61b650099dd63c1368bf2c236044cd Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Thu, 14 Nov 2024 21:11:01 +0100 Subject: [PATCH 24/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- contribs/gnodev/pkg/dev/node.go | 7 ++++++- gno.land/genesis/genesis_params.toml | 2 +- gno.land/pkg/gnoland/node_inmemory.go | 1 + gno.land/pkg/integration/testing_node.go | 1 - 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/contribs/gnodev/pkg/dev/node.go b/contribs/gnodev/pkg/dev/node.go index 2204d0432fe..3fc30003c2a 100644 --- a/contribs/gnodev/pkg/dev/node.go +++ b/contribs/gnodev/pkg/dev/node.go @@ -562,6 +562,12 @@ func newNodeConfig(tmc *tmcfg.Config, chainid, chaindomain string, appstate gnol // Create Mocked Identity pv := gnoland.NewMockedPrivValidator() genesis := gnoland.NewDefaultGenesisConfig(chainid) + + // custom chain domain + var domainParam gnoland.Param + _ = domainParam.Parse("gno.land/r/sys/params.vm.chain_domain.string=" + chaindomain) + appstate.Params = append(appstate.Params, domainParam) + genesis.AppState = appstate // Add self as validator @@ -581,6 +587,5 @@ func newNodeConfig(tmc *tmcfg.Config, chainid, chaindomain string, appstate gnol Genesis: genesis, VMOutput: os.Stdout, } - cfg.InitChainerConfig.ChainDomain = chaindomain return cfg } diff --git a/gno.land/genesis/genesis_params.toml b/gno.land/genesis/genesis_params.toml index 5f4d9c5015c..fb080024624 100644 --- a/gno.land/genesis/genesis_params.toml +++ b/gno.land/genesis/genesis_params.toml @@ -8,7 +8,7 @@ ## gnovm ["gno.land/r/sys/params.vm"] - # TODO: chain_domain.string = "gno.land" + chain_domain.string = "gno.land" # TODO: max_gas.int64 = 100_000_000 # TODO: chain_tz.string = "UTC" # TODO: default_storage_allowance.string = "" diff --git a/gno.land/pkg/gnoland/node_inmemory.go b/gno.land/pkg/gnoland/node_inmemory.go index 426a8c780c7..4b6f70bf150 100644 --- a/gno.land/pkg/gnoland/node_inmemory.go +++ b/gno.land/pkg/gnoland/node_inmemory.go @@ -46,6 +46,7 @@ func NewDefaultGenesisConfig(chainid string) *bft.GenesisDoc { AppState: &GnoGenesisState{ Balances: []Balance{}, Txs: []TxWithMetadata{}, + Params: []Param{}, }, } } diff --git a/gno.land/pkg/integration/testing_node.go b/gno.land/pkg/integration/testing_node.go index 61bea86bcf7..7e34049d352 100644 --- a/gno.land/pkg/integration/testing_node.go +++ b/gno.land/pkg/integration/testing_node.go @@ -92,7 +92,6 @@ func TestingMinimalNodeConfig(t TestingTS, gnoroot string) *gnoland.InMemoryNode InitChainerConfig: gnoland.InitChainerConfig{ GenesisTxResultHandler: gnoland.PanicOnFailingTxResultHandler, CacheStdlibLoad: true, - ChainDomain: "gno.land", }, } } From f6e3a5de5bf1c14809139cb17889407d7dcb0a16 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Thu, 14 Nov 2024 21:15:46 +0100 Subject: [PATCH 25/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- contribs/gnodev/pkg/dev/node.go | 8 +------- gno.land/pkg/gnoland/node_inmemory.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/contribs/gnodev/pkg/dev/node.go b/contribs/gnodev/pkg/dev/node.go index 3fc30003c2a..6e7ce85ec1e 100644 --- a/contribs/gnodev/pkg/dev/node.go +++ b/contribs/gnodev/pkg/dev/node.go @@ -561,13 +561,7 @@ func (n *Node) genesisTxResultHandler(ctx sdk.Context, tx std.Tx, res sdk.Result func newNodeConfig(tmc *tmcfg.Config, chainid, chaindomain string, appstate gnoland.GnoGenesisState) *gnoland.InMemoryNodeConfig { // Create Mocked Identity pv := gnoland.NewMockedPrivValidator() - genesis := gnoland.NewDefaultGenesisConfig(chainid) - - // custom chain domain - var domainParam gnoland.Param - _ = domainParam.Parse("gno.land/r/sys/params.vm.chain_domain.string=" + chaindomain) - appstate.Params = append(appstate.Params, domainParam) - + genesis := gnoland.NewDefaultGenesisConfig(chainid, chaindomain) genesis.AppState = appstate // Add self as validator diff --git a/gno.land/pkg/gnoland/node_inmemory.go b/gno.land/pkg/gnoland/node_inmemory.go index 4b6f70bf150..f42166411c8 100644 --- a/gno.land/pkg/gnoland/node_inmemory.go +++ b/gno.land/pkg/gnoland/node_inmemory.go @@ -36,7 +36,11 @@ func NewMockedPrivValidator() bft.PrivValidator { } // NewDefaultGenesisConfig creates a default configuration for an in-memory node. -func NewDefaultGenesisConfig(chainid string) *bft.GenesisDoc { +func NewDefaultGenesisConfig(chainid, chaindomain string) *bft.GenesisDoc { + // custom chain domain + var domainParam Param + _ = domainParam.Parse("gno.land/r/sys/params.vm.chain_domain.string=" + chaindomain) + return &bft.GenesisDoc{ GenesisTime: time.Now(), ChainID: chainid, @@ -46,7 +50,9 @@ func NewDefaultGenesisConfig(chainid string) *bft.GenesisDoc { AppState: &GnoGenesisState{ Balances: []Balance{}, Txs: []TxWithMetadata{}, - Params: []Param{}, + Params: []Param{ + domainParam, + }, }, } } From c403e2356be73b986fa24cbc3995c61df637ccf4 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Thu, 14 Nov 2024 21:24:41 +0100 Subject: [PATCH 26/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gno.land/cmd/gnoland/start.go | 8 -------- gno.land/cmd/gnoland/testdata/genesis_params.txtar | 7 ++++++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/gno.land/cmd/gnoland/start.go b/gno.land/cmd/gnoland/start.go index f392785bd6d..77d7e20b8ef 100644 --- a/gno.land/cmd/gnoland/start.go +++ b/gno.land/cmd/gnoland/start.go @@ -58,7 +58,6 @@ type startCfg struct { genesisRemote string // TODO: remove as part of https://github.com/gnolang/gno/issues/1952 genesisFile string chainID string - chainDomain string dataDir string lazyInit bool @@ -123,13 +122,6 @@ func (c *startCfg) RegisterFlags(fs *flag.FlagSet) { "the ID of the chain", ) - fs.StringVar( - &c.chainDomain, - "chaindomain", - "gno.land", - "the domain of the chain for packages", - ) - fs.StringVar( &c.gnoRootDir, "gnoroot-dir", diff --git a/gno.land/cmd/gnoland/testdata/genesis_params.txtar b/gno.land/cmd/gnoland/testdata/genesis_params.txtar index 43ecd8ccacb..07094593b83 100644 --- a/gno.land/cmd/gnoland/testdata/genesis_params.txtar +++ b/gno.land/cmd/gnoland/testdata/genesis_params.txtar @@ -2,6 +2,11 @@ gnoland start +# official params (right now they makes sense to be tested in a txtar to validate that a default "gnoland" initialization will have default values) +gnokey query params/vm/gno.land/r/sys/params.vm.chain_domain.string +stdout 'data: "gno.land"$' + +# test params gnokey query params/vm/gno.land/r/sys/params.test.foo.string stdout 'data: "bar"$' gnokey query params/vm/gno.land/r/sys/params.test.foo.int64 @@ -10,5 +15,5 @@ gnokey query params/vm/gno.land/r/sys/params.test.foo.uint64 stdout 'data: "42"' gnokey query params/vm/gno.land/r/sys/params.test.foo.bool stdout 'data: true' -# XXX: bytes +# XXX: consider adding a test with bytes From a1c2ddb09d5ac44c9470de1a704c78568291755c Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Thu, 14 Nov 2024 21:35:43 +0100 Subject: [PATCH 27/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- .../cmd/gnoland/testdata/genesis_params.txtar | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/genesis_params.txtar b/gno.land/cmd/gnoland/testdata/genesis_params.txtar index 07094593b83..d09ededf78a 100644 --- a/gno.land/cmd/gnoland/testdata/genesis_params.txtar +++ b/gno.land/cmd/gnoland/testdata/genesis_params.txtar @@ -1,19 +1,28 @@ -# test for https://github.com/gnolang/gno/pull/3003 +# Test for #3003, #2911. gnoland start -# official params (right now they makes sense to be tested in a txtar to validate that a default "gnoland" initialization will have default values) +# Query and validate official parameters. +# These parameters should ideally be tested in a txtar format to ensure that a +# default initialization of "gnoland" provides the expected default values. + +# Verify the default chain domain parameter for Gno.land gnokey query params/vm/gno.land/r/sys/params.vm.chain_domain.string stdout 'data: "gno.land"$' -# test params +# Test custom parameters to confirm they return the expected values and types. + gnokey query params/vm/gno.land/r/sys/params.test.foo.string stdout 'data: "bar"$' + gnokey query params/vm/gno.land/r/sys/params.test.foo.int64 stdout 'data: "-1337"' + gnokey query params/vm/gno.land/r/sys/params.test.foo.uint64 stdout 'data: "42"' + gnokey query params/vm/gno.land/r/sys/params.test.foo.bool stdout 'data: true' -# XXX: consider adding a test with bytes + +# TODO: Consider adding a test case for a byte array parameter From c9f229270f8df6ba631136ae82a16be12f9475af Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Fri, 15 Nov 2024 20:59:17 +0100 Subject: [PATCH 28/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gnovm/pkg/gnolang/helpers.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/gnovm/pkg/gnolang/helpers.go b/gnovm/pkg/gnolang/helpers.go index dea9f120d02..a0eeec1088e 100644 --- a/gnovm/pkg/gnolang/helpers.go +++ b/gnovm/pkg/gnolang/helpers.go @@ -27,14 +27,7 @@ func IsRealmPath(pkgPath string) bool { // IsStdlib determines whether s is a pkgpath for a standard library. func IsStdlib(s string) bool { - parts := strings.Split(s, "/") - if len(parts) > 0 { - // Check if the first part contains a dot - if strings.Contains(parts[0], ".") { - return false // It's a domain, so it's not part of the standard library - } - } - return true + return strings.IndexByte(s[:strings.IndexByte(s, '/')+1], '.') < 0 } // ---------------------------------------- From 8445d8ca9cfbf3a351ad3aa702d149ad03c1b3ae Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:23:24 +0100 Subject: [PATCH 29/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gnovm/pkg/gnolang/helpers.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gnovm/pkg/gnolang/helpers.go b/gnovm/pkg/gnolang/helpers.go index 4998902c951..b0248918f2a 100644 --- a/gnovm/pkg/gnolang/helpers.go +++ b/gnovm/pkg/gnolang/helpers.go @@ -12,8 +12,10 @@ import ( // ReRealmPath and RePackagePath are the regexes used to identify pkgpaths which are meant to // be realms with persisted states and pure packages. -var ReRealmPath = regexp.MustCompile(`^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.[a-zA-Z]{2,}/r/[a-z0-9_/]+`) -var RePackagePath = regexp.MustCompile(`^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.[a-zA-Z]{2,}/p/[a-z0-9_/]+`) +var ( + ReRealmPath = regexp.MustCompile(`^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.[a-zA-Z]{2,}/r/[a-z0-9_/]+`) + RePackagePath = regexp.MustCompile(`^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.[a-zA-Z]{2,}/p/[a-z0-9_/]+`) +) // ReGnoRunPath is the path used for realms executed in maketx run. // These are not considered realms, as an exception to the ReRealmPathPrefix rule. From 29e0e2e99aa386cdc3cb90594390d0e42c1c1411 Mon Sep 17 00:00:00 2001 From: Manfred Touron <94029+moul@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:54:36 +0100 Subject: [PATCH 30/33] Update gno.land/pkg/sdk/vm/params.go Co-authored-by: Mikael VALLENET --- gno.land/pkg/sdk/vm/params.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gno.land/pkg/sdk/vm/params.go b/gno.land/pkg/sdk/vm/params.go index b3d0f43b2f5..248fb8a81fb 100644 --- a/gno.land/pkg/sdk/vm/params.go +++ b/gno.land/pkg/sdk/vm/params.go @@ -4,7 +4,7 @@ import "github.com/gnolang/gno/tm2/pkg/sdk" const ( sysUsersPkgParamPath = "gno.land/r/sys/params.sys.users_pkgpath.string" - chainDomainParamPath = "gno.land/r/sys/params.chain.domain.string" + chainDomainParamPath = "gno.land/r/sys/params.chain_domain.string" ) func (vm *VMKeeper) getChainDomainParam(ctx sdk.Context) string { From db2782dd4710cf748a454187cdfbbea64ff4b1b1 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:15:14 +0100 Subject: [PATCH 31/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gno.land/pkg/sdk/vm/keeper.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/gno.land/pkg/sdk/vm/keeper.go b/gno.land/pkg/sdk/vm/keeper.go index 57120536d48..b1fb9653dfb 100644 --- a/gno.land/pkg/sdk/vm/keeper.go +++ b/gno.land/pkg/sdk/vm/keeper.go @@ -369,6 +369,7 @@ func (vm *VMKeeper) AddPackage(ctx sdk.Context, msg MsgAddPackage) (err error) { // Parse and run the files, construct *PV. msgCtx := stdlibs.ExecContext{ ChainID: ctx.ChainID(), + ChainDomain: chainDomain, Height: ctx.BlockHeight(), Timestamp: ctx.BlockTime().Unix(), OrigCaller: creator.Bech32(), @@ -467,8 +468,10 @@ func (vm *VMKeeper) Call(ctx sdk.Context, msg MsgCall) (res string, err error) { // Make context. // NOTE: if this is too expensive, // could it be safely partially memoized? + chainDomain := vm.getChainDomainParam(ctx) msgCtx := stdlibs.ExecContext{ ChainID: ctx.ChainID(), + ChainDomain: chainDomain, Height: ctx.BlockHeight(), Timestamp: ctx.BlockTime().Unix(), OrigCaller: caller.Bech32(), @@ -730,10 +733,12 @@ func (vm *VMKeeper) QueryEval(ctx sdk.Context, pkgPath string, expr string) (res return "", err } // Construct new machine. + chainDomain := vm.getChainDomainParam(ctx) msgCtx := stdlibs.ExecContext{ - ChainID: ctx.ChainID(), - Height: ctx.BlockHeight(), - Timestamp: ctx.BlockTime().Unix(), + ChainID: ctx.ChainID(), + ChainDomain: chainDomain, + Height: ctx.BlockHeight(), + Timestamp: ctx.BlockTime().Unix(), // OrigCaller: caller, // OrigSend: send, // OrigSendSpent: nil, @@ -796,10 +801,12 @@ func (vm *VMKeeper) QueryEvalString(ctx sdk.Context, pkgPath string, expr string return "", err } // Construct new machine. + chainDomain := vm.getChainDomainParam(ctx) msgCtx := stdlibs.ExecContext{ - ChainID: ctx.ChainID(), - Height: ctx.BlockHeight(), - Timestamp: ctx.BlockTime().Unix(), + ChainID: ctx.ChainID(), + ChainDomain: chainDomain, + Height: ctx.BlockHeight(), + Timestamp: ctx.BlockTime().Unix(), // OrigCaller: caller, // OrigSend: jsend, // OrigSendSpent: nil, From 8580ec2d2e2fde0a37fdba8486a42ab16894a978 Mon Sep 17 00:00:00 2001 From: Manfred Touron <94029+moul@users.noreply.github.com> Date: Fri, 6 Dec 2024 20:31:52 +0100 Subject: [PATCH 32/33] Update gnovm/pkg/gnolang/helpers.go --- gnovm/pkg/gnolang/helpers.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gnovm/pkg/gnolang/helpers.go b/gnovm/pkg/gnolang/helpers.go index b0248918f2a..ddc1fd2fa55 100644 --- a/gnovm/pkg/gnolang/helpers.go +++ b/gnovm/pkg/gnolang/helpers.go @@ -37,7 +37,12 @@ func IsPurePackagePath(pkgPath string) bool { // IsStdlib determines whether s is a pkgpath for a standard library. func IsStdlib(s string) bool { - return strings.IndexByte(s[:strings.IndexByte(s, '/')+1], '.') < 0 + idx := strings.IndexByte(s, '/') + if idx < 0 { + // If no '/' is found, consider the whole string + return strings.IndexByte(s, '.') < 0 + } + return strings.IndexByte(s[:idx+1], '.') < 0 } // ---------------------------------------- From 25f6a0770b4c0de6b376fa175cc67dfa0a7544a8 Mon Sep 17 00:00:00 2001 From: moul <94029+moul@users.noreply.github.com> Date: Fri, 6 Dec 2024 21:48:00 +0100 Subject: [PATCH 33/33] chore: fixup Signed-off-by: moul <94029+moul@users.noreply.github.com> --- gno.land/cmd/gnoland/testdata/simulate_gas.txtar | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/simulate_gas.txtar b/gno.land/cmd/gnoland/testdata/simulate_gas.txtar index cd58b4ccc8f..9d3c8abe69f 100644 --- a/gno.land/cmd/gnoland/testdata/simulate_gas.txtar +++ b/gno.land/cmd/gnoland/testdata/simulate_gas.txtar @@ -6,11 +6,11 @@ gnoland start # simulate only gnokey maketx call -pkgpath gno.land/r/simulate -func Hello -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test -simulate only test1 -stdout 'GAS USED: 50299' +stdout 'GAS USED: 51299' # simulate skip gnokey maketx call -pkgpath gno.land/r/simulate -func Hello -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test -simulate skip test1 -stdout 'GAS USED: 50299' # same as simulate only +stdout 'GAS USED: 51299' # same as simulate only -- package/package.gno --