Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sdk/vm): coerce MsgRun pkgpath to gno.land/r/$addr/run #1645

Merged
merged 4 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gno.land/pkg/gnoclient/client_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
return nil, errors.Wrap(err, "precompile and check")
}
memPkg.Name = "main"
memPkg.Path = "gno.land/r/" + caller.String() + "/run"
memPkg.Path = ""

Check warning on line 147 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L147

Added line #L147 was not covered by tests

// Construct message & transaction and marshal.
msg := vm.MsgRun{
Expand Down
3 changes: 2 additions & 1 deletion gno.land/pkg/keyscli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ func execMakeRun(cfg *MakeRunCfg, args []string, cmdio commands.IO) error {
panic(err)
}
memPkg.Name = "main"
memPkg.Path = "gno.land/r/" + caller.String() + "/run"
// Set to empty; this will be automatically set by the VM keeper.
memPkg.Path = ""

// construct msg & tx and marshal.
msg := vm.MsgRun{
Expand Down
9 changes: 7 additions & 2 deletions gno.land/pkg/sdk/vm/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (vm *VMKeeper) getGnoStore(ctx sdk.Context) gno.Store {
}
}

var reReservedPath = regexp.MustCompile(`gno\.land/r/g[a-z0-9]+/run`)
var reRunPath = regexp.MustCompile(`gno\.land/r/g[a-z0-9]+/run`)

// AddPackage adds a package with given fileset.
func (vm *VMKeeper) AddPackage(ctx sdk.Context, msg MsgAddPackage) error {
Expand All @@ -156,7 +156,7 @@ func (vm *VMKeeper) AddPackage(ctx sdk.Context, msg MsgAddPackage) error {
return ErrInvalidPkgPath("package already exists: " + pkgPath)
}

if reReservedPath.MatchString(pkgPath) {
if reRunPath.MatchString(pkgPath) {
return ErrInvalidPkgPath("reserved package name: " + pkgPath)
}

Expand Down Expand Up @@ -303,6 +303,11 @@ func (vm *VMKeeper) Run(ctx sdk.Context, msg MsgRun) (res string, err error) {
send := msg.Send
memPkg := msg.Package

// 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"

// Validate arguments.
callerAcc := vm.acck.GetAccount(ctx, caller)
if callerAcc == nil {
Expand Down
11 changes: 8 additions & 3 deletions gno.land/pkg/sdk/vm/msgs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vm

import (
"fmt"
"strings"

gno "github.com/gnolang/gno/gnovm/pkg/gnolang"
Expand Down Expand Up @@ -162,7 +163,7 @@
Send: send,
Package: &std.MemPackage{
Name: "main",
Path: "gno.land/r/" + caller.String() + "/run",
Path: "", // auto set by the handler
Files: files,
},
}
Expand All @@ -179,9 +180,13 @@
if msg.Caller.IsZero() {
return std.ErrInvalidAddress("missing caller address")
}
if msg.Package.Path == "" { // XXX
return ErrInvalidPkgPath("missing package path")

// Force memPkg path to the reserved run path.
wantPath := "gno.land/r/" + msg.Caller.String() + "/run"
if path := msg.Package.Path; path != "" && path != wantPath {
return ErrInvalidPkgPath(fmt.Sprintf("invalid pkgpath for MsgRun: %q", path))

Check warning on line 187 in gno.land/pkg/sdk/vm/msgs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/sdk/vm/msgs.go#L185-L187

Added lines #L185 - L187 were not covered by tests
}

return nil
}

Expand Down
Loading