From 7ea90e51ecfaf85e9246f3394203939fa44da4ce Mon Sep 17 00:00:00 2001 From: ThinhNX Date: Thu, 30 May 2024 23:05:27 +0700 Subject: [PATCH 1/8] restrict maketx call to realm only --- gno.land/pkg/sdk/vm/keeper.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gno.land/pkg/sdk/vm/keeper.go b/gno.land/pkg/sdk/vm/keeper.go index a77ddac3e28..2372a89125c 100644 --- a/gno.land/pkg/sdk/vm/keeper.go +++ b/gno.land/pkg/sdk/vm/keeper.go @@ -237,6 +237,9 @@ func (vm *VMKeeper) AddPackage(ctx sdk.Context, msg MsgAddPackage) (err error) { // Call calls a public Gno function (for delivertx). func (vm *VMKeeper) Call(ctx sdk.Context, msg MsgCall) (res string, err error) { pkgPath := msg.PkgPath // to import + if !gno.IsRealmPath(pkgPath) { + return "", errors.New("pkgpath must be a realm") + } fnc := msg.Func gnostore := vm.getGnoStore(ctx) // Get the package and function type. From bafc19e10570f60b949ae59cf1d43928c54158fd Mon Sep 17 00:00:00 2001 From: ThinhNX Date: Fri, 31 May 2024 11:40:42 +0700 Subject: [PATCH 2/8] add test, remove old maketx call tests --- .../gnoland/testdata/assertorigincall.txtar | 13 ++++---- .../testdata/maketx_call_forbidden.txtar | 32 +++++++++++++++++++ gno.land/cmd/gnoland/testdata/prevrealm.txtar | 9 +++--- 3 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar diff --git a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar index fdbfebeef4a..50e22ba869f 100644 --- a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar +++ b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar @@ -56,17 +56,18 @@ stdout 'OK!' ! gnokey maketx call -pkgpath gno.land/r/foo -func C -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 stderr 'invalid non-origin call' +## remove due to update to maketx call can only call realm (case 7,8,9) ## 7. MsgCall -> p/demo/bar.A -> myrlm.A: PANIC -! gnokey maketx call -pkgpath gno.land/p/demo/bar -func A -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 -stderr 'invalid non-origin call' +## ! gnokey maketx call -pkgpath gno.land/p/demo/bar -func A -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 +## stderr 'invalid non-origin call' ## 8. MsgCall -> p/demo/bar.B -> myrlm.B: PASS -gnokey maketx call -pkgpath gno.land/p/demo/bar -func B -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 -stdout 'OK!' +## gnokey maketx call -pkgpath gno.land/p/demo/bar -func B -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 +## stdout 'OK!' ## 9. MsgCall -> p/demo/bar.C -> myrlm.C: PANIC -! gnokey maketx call -pkgpath gno.land/p/demo/bar -func C -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 -stderr 'invalid non-origin call' +## ! gnokey maketx call -pkgpath gno.land/p/demo/bar -func C -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 +## stderr 'invalid non-origin call' ## 10. MsgRun -> run.main -> myrlm.A: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmA.gno diff --git a/gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar b/gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar new file mode 100644 index 00000000000..5e3c0a132a4 --- /dev/null +++ b/gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar @@ -0,0 +1,32 @@ +# load the package +loadpkg gno.land/p/demo/call_forbidden $WORK +loadpkg gno.land/r/demo/call_normal $WORK + +# start a new node +gnoland start + +# 1. call to package ERROR +! gnokey maketx call -pkgpath gno.land/p/demo/call_forbidden -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +stderr `forbidden/bad package called` + +# 2. call to stdlibs ERROR +! gnokey maketx call -pkgpath strconv -func Itoa -args 11 -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +stderr `forbidden/bad package called` + +# 3. normal call to realm PASS +gnokey maketx call -pkgpath gno.land/r/demo/call_normal -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +stdout `OK!` + +-- call_forbidden.gno -- +package call_forbidden + +func Render() string { + return "notok" +} + +-- call_normal.gno -- +package call_normal + +func Render() string { + return "ok" +} diff --git a/gno.land/cmd/gnoland/testdata/prevrealm.txtar b/gno.land/cmd/gnoland/testdata/prevrealm.txtar index ac7988616a4..65295a3bdf8 100644 --- a/gno.land/cmd/gnoland/testdata/prevrealm.txtar +++ b/gno.land/cmd/gnoland/testdata/prevrealm.txtar @@ -49,13 +49,14 @@ stdout ${RFOO_ADDR} gnokey maketx call -pkgpath gno.land/r/foo -func B -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 stdout ${RFOO_ADDR} +## remove due to update to maketx call can only call realm (case 5,6) ## 5. MsgCall -> p/demo/bar.A -> myrlm.A: user address -gnokey maketx call -pkgpath gno.land/p/demo/bar -func A -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 -stdout ${USER_ADDR_test1} +## gnokey maketx call -pkgpath gno.land/p/demo/bar -func A -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 +## stdout ${USER_ADDR_test1} ## 6. MsgCall -> p/demo/bar.B -> myrlm.B -> r/foo.A: user address -gnokey maketx call -pkgpath gno.land/p/demo/bar -func B -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 -stdout ${USER_ADDR_test1} +## gnokey maketx call -pkgpath gno.land/p/demo/bar -func B -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 +## stdout ${USER_ADDR_test1} ## 7. MsgRun -> myrlm.A: user address gnokey maketx run -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 $WORK/run/myrlmA.gno From 4bf6b4619aafca3b6716fdce902dc8668bd41ed8 Mon Sep 17 00:00:00 2001 From: ThinhNX Date: Fri, 31 May 2024 11:41:36 +0700 Subject: [PATCH 3/8] move check maketx call forbidden to Validate step --- gno.land/pkg/sdk/vm/errors.go | 6 ++++++ gno.land/pkg/sdk/vm/keeper.go | 3 --- gno.land/pkg/sdk/vm/msgs.go | 3 +++ gno.land/pkg/sdk/vm/package.go | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/gno.land/pkg/sdk/vm/errors.go b/gno.land/pkg/sdk/vm/errors.go index 132d98b7ecd..e9d6c5a6925 100644 --- a/gno.land/pkg/sdk/vm/errors.go +++ b/gno.land/pkg/sdk/vm/errors.go @@ -22,6 +22,7 @@ type ( abciError Errors []string } + ForbiddenPkgCall struct{ abciError } ) func (e InvalidPkgPathError) Error() string { return "invalid package path" } @@ -33,6 +34,7 @@ func (e TypeCheckError) Error() string { bld.WriteString(strings.Join(e.Errors, "\n")) return bld.String() } +func (e ForbiddenPkgCall) Error() string { return "forbidden/bad package called" } func ErrInvalidPkgPath(msg string) error { return errors.Wrap(InvalidPkgPathError{}, msg) @@ -54,3 +56,7 @@ func ErrTypeCheck(err error) error { } return errors.NewWithData(tce).Stacktrace() } + +func ErrForbiddenPkgCall(msg string) error { + return errors.Wrap(ForbiddenPkgCall{}, msg) +} diff --git a/gno.land/pkg/sdk/vm/keeper.go b/gno.land/pkg/sdk/vm/keeper.go index 2372a89125c..a77ddac3e28 100644 --- a/gno.land/pkg/sdk/vm/keeper.go +++ b/gno.land/pkg/sdk/vm/keeper.go @@ -237,9 +237,6 @@ func (vm *VMKeeper) AddPackage(ctx sdk.Context, msg MsgAddPackage) (err error) { // Call calls a public Gno function (for delivertx). func (vm *VMKeeper) Call(ctx sdk.Context, msg MsgCall) (res string, err error) { pkgPath := msg.PkgPath // to import - if !gno.IsRealmPath(pkgPath) { - return "", errors.New("pkgpath must be a realm") - } fnc := msg.Func gnostore := vm.getGnoStore(ctx) // Get the package and function type. diff --git a/gno.land/pkg/sdk/vm/msgs.go b/gno.land/pkg/sdk/vm/msgs.go index e42babe1510..9d75a1c7783 100644 --- a/gno.land/pkg/sdk/vm/msgs.go +++ b/gno.land/pkg/sdk/vm/msgs.go @@ -116,6 +116,9 @@ func (msg MsgCall) ValidateBasic() error { if msg.PkgPath == "" { // XXX return ErrInvalidPkgPath("missing package path") } + if !gno.IsRealmPath(msg.PkgPath) { + return ErrForbiddenPkgCall("pkgpath must be a realm") + } if msg.Func == "" { // XXX return ErrInvalidExpr("missing function to call") } diff --git a/gno.land/pkg/sdk/vm/package.go b/gno.land/pkg/sdk/vm/package.go index b2e7fbecfc4..6f6b8553ea6 100644 --- a/gno.land/pkg/sdk/vm/package.go +++ b/gno.land/pkg/sdk/vm/package.go @@ -21,4 +21,5 @@ var Package = amino.RegisterPackage(amino.NewPackage( InvalidStmtError{}, "InvalidStmtError", InvalidExprError{}, "InvalidExprError", TypeCheckError{}, "TypeCheckError", + ForbiddenPkgCall{}, "ForbiddenPkgCall", )) From 1dc0e6f1086252b0008baca073f615ef9efd7d1c Mon Sep 17 00:00:00 2001 From: ThinhNX Date: Fri, 31 May 2024 11:50:13 +0700 Subject: [PATCH 4/8] fix lint --- gno.land/pkg/sdk/vm/errors.go | 6 +++--- gno.land/pkg/sdk/vm/package.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gno.land/pkg/sdk/vm/errors.go b/gno.land/pkg/sdk/vm/errors.go index e9d6c5a6925..23d8b801969 100644 --- a/gno.land/pkg/sdk/vm/errors.go +++ b/gno.land/pkg/sdk/vm/errors.go @@ -22,7 +22,7 @@ type ( abciError Errors []string } - ForbiddenPkgCall struct{ abciError } + ForbiddenPkgCallError struct{ abciError } ) func (e InvalidPkgPathError) Error() string { return "invalid package path" } @@ -34,7 +34,7 @@ func (e TypeCheckError) Error() string { bld.WriteString(strings.Join(e.Errors, "\n")) return bld.String() } -func (e ForbiddenPkgCall) Error() string { return "forbidden/bad package called" } +func (e ForbiddenPkgCallError) Error() string { return "forbidden/bad package called" } func ErrInvalidPkgPath(msg string) error { return errors.Wrap(InvalidPkgPathError{}, msg) @@ -58,5 +58,5 @@ func ErrTypeCheck(err error) error { } func ErrForbiddenPkgCall(msg string) error { - return errors.Wrap(ForbiddenPkgCall{}, msg) + return errors.Wrap(ForbiddenPkgCallError{}, msg) } diff --git a/gno.land/pkg/sdk/vm/package.go b/gno.land/pkg/sdk/vm/package.go index 6f6b8553ea6..94c226b5f8f 100644 --- a/gno.land/pkg/sdk/vm/package.go +++ b/gno.land/pkg/sdk/vm/package.go @@ -21,5 +21,5 @@ var Package = amino.RegisterPackage(amino.NewPackage( InvalidStmtError{}, "InvalidStmtError", InvalidExprError{}, "InvalidExprError", TypeCheckError{}, "TypeCheckError", - ForbiddenPkgCall{}, "ForbiddenPkgCall", + ForbiddenPkgCallError{}, "ForbiddenPkgCallError", )) From 7ef9d2a03b88a3aa7b7a65d3a5f9d9269bf11f63 Mon Sep 17 00:00:00 2001 From: ThinhNX Date: Fri, 31 May 2024 14:12:13 +0700 Subject: [PATCH 5/8] update txtar files --- gno.land/cmd/gnoland/testdata/assertorigincall.txtar | 5 +++-- gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar index 50e22ba869f..e3cd1be744a 100644 --- a/gno.land/cmd/gnoland/testdata/assertorigincall.txtar +++ b/gno.land/cmd/gnoland/testdata/assertorigincall.txtar @@ -105,9 +105,10 @@ stdout 'OK!' ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 $WORK/run/barC.gno stderr 'invalid non-origin call' +## remove testcase 19 due to maketx call forced to call a realm ## 19. MsgCall -> std.AssertOriginCall: pass -gnokey maketx call -pkgpath std -func AssertOriginCall -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 -stdout 'OK!' +## gnokey maketx call -pkgpath std -func AssertOriginCall -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 +## stdout 'OK!' ## 20. MsgRun -> std.AssertOriginCall: PANIC ! gnokey maketx run -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno diff --git a/gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar b/gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar index 5e3c0a132a4..074703b0421 100644 --- a/gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar +++ b/gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar @@ -1,6 +1,6 @@ # load the package -loadpkg gno.land/p/demo/call_forbidden $WORK -loadpkg gno.land/r/demo/call_normal $WORK +loadpkg gno.land/p/call_forbidden $WORK/forbidden +loadpkg gno.land/r/call_normal $WORK/normal_rlm_call # start a new node gnoland start @@ -17,14 +17,14 @@ stderr `forbidden/bad package called` gnokey maketx call -pkgpath gno.land/r/demo/call_normal -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 stdout `OK!` --- call_forbidden.gno -- +-- forbidden/forbidden.gno -- package call_forbidden func Render() string { return "notok" } --- call_normal.gno -- +-- normal_rlm_call/normal_call.gno -- package call_normal func Render() string { From e7766ec50b4483afb97300b8a83ef01cefda83a5 Mon Sep 17 00:00:00 2001 From: ThinhNX Date: Fri, 31 May 2024 16:27:33 +0700 Subject: [PATCH 6/8] update txtar and failed tests --- gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar | 6 +++--- gno.land/cmd/gnoland/testdata/prevrealm.txtar | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar b/gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar index 074703b0421..476e677c5a1 100644 --- a/gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar +++ b/gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar @@ -7,15 +7,15 @@ gnoland start # 1. call to package ERROR ! gnokey maketx call -pkgpath gno.land/p/demo/call_forbidden -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 -stderr `forbidden/bad package called` +stderr '"gnokey" error: --= Error =--\nData: forbidden/bad package called' # 2. call to stdlibs ERROR ! gnokey maketx call -pkgpath strconv -func Itoa -args 11 -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 -stderr `forbidden/bad package called` +stderr '"gnokey" error: --= Error =--\nData: forbidden/bad package called' # 3. normal call to realm PASS gnokey maketx call -pkgpath gno.land/r/demo/call_normal -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 -stdout `OK!` +stdout OK! -- forbidden/forbidden.gno -- package call_forbidden diff --git a/gno.land/cmd/gnoland/testdata/prevrealm.txtar b/gno.land/cmd/gnoland/testdata/prevrealm.txtar index 65295a3bdf8..72a207fae22 100644 --- a/gno.land/cmd/gnoland/testdata/prevrealm.txtar +++ b/gno.land/cmd/gnoland/testdata/prevrealm.txtar @@ -49,7 +49,7 @@ stdout ${RFOO_ADDR} gnokey maketx call -pkgpath gno.land/r/foo -func B -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 stdout ${RFOO_ADDR} -## remove due to update to maketx call can only call realm (case 5,6) +## remove due to update to maketx call can only call realm (case 5, 6, 13) ## 5. MsgCall -> p/demo/bar.A -> myrlm.A: user address ## gnokey maketx call -pkgpath gno.land/p/demo/bar -func A -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 ## stdout ${USER_ADDR_test1} @@ -83,8 +83,8 @@ gnokey maketx run -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid t stdout ${USER_ADDR_test1} ## 13. MsgCall -> std.PrevRealm(): user address -gnokey maketx call -pkgpath std -func PrevRealm -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 -stdout ${USER_ADDR_test1} +## gnokey maketx call -pkgpath std -func PrevRealm -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 +## stdout ${USER_ADDR_test1} ## 14. MsgRun -> std.PrevRealm(): user address gnokey maketx run -gas-fee 100000ugnot -gas-wanted 2000000 -broadcast -chainid tendermint_test test1 $WORK/run/baz.gno From babd3d029487246fbf4be698fe3137c2fc1f298c Mon Sep 17 00:00:00 2001 From: ThinhNX Date: Fri, 31 May 2024 16:40:42 +0700 Subject: [PATCH 7/8] update txtar --- gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar b/gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar index 476e677c5a1..b02d8bf73c4 100644 --- a/gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar +++ b/gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar @@ -1,12 +1,12 @@ # load the package -loadpkg gno.land/p/call_forbidden $WORK/forbidden -loadpkg gno.land/r/call_normal $WORK/normal_rlm_call +loadpkg gno.land/p/foo/call_forbidden $WORK/forbidden +loadpkg gno.land/r/foo/call_normal $WORK/normal_rlm_call # start a new node gnoland start # 1. call to package ERROR -! gnokey maketx call -pkgpath gno.land/p/demo/call_forbidden -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +! gnokey maketx call -pkgpath gno.land/p/foo/call_forbidden -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 stderr '"gnokey" error: --= Error =--\nData: forbidden/bad package called' # 2. call to stdlibs ERROR @@ -14,7 +14,7 @@ stderr '"gnokey" error: --= Error =--\nData: forbidden/bad package called' stderr '"gnokey" error: --= Error =--\nData: forbidden/bad package called' # 3. normal call to realm PASS -gnokey maketx call -pkgpath gno.land/r/demo/call_normal -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +gnokey maketx call -pkgpath gno.land/r/foo/call_normal -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 stdout OK! -- forbidden/forbidden.gno -- From 2fbae1ffac0ec79b0a85ac48dfb28588321f8aa9 Mon Sep 17 00:00:00 2001 From: Morgan Bazalgette Date: Fri, 31 May 2024 16:57:59 +0200 Subject: [PATCH 8/8] renames, remove error --- .../testdata/maketx_call_forbidden.txtar | 32 ------------------- .../gnoland/testdata/maketx_call_pure.txtar | 32 +++++++++++++++++++ gno.land/pkg/sdk/vm/errors.go | 6 ---- gno.land/pkg/sdk/vm/msgs.go | 4 +-- gno.land/pkg/sdk/vm/package.go | 1 - gnovm/pkg/gnolang/realm.go | 2 +- 6 files changed, 35 insertions(+), 42 deletions(-) delete mode 100644 gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar create mode 100644 gno.land/cmd/gnoland/testdata/maketx_call_pure.txtar diff --git a/gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar b/gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar deleted file mode 100644 index b02d8bf73c4..00000000000 --- a/gno.land/cmd/gnoland/testdata/maketx_call_forbidden.txtar +++ /dev/null @@ -1,32 +0,0 @@ -# load the package -loadpkg gno.land/p/foo/call_forbidden $WORK/forbidden -loadpkg gno.land/r/foo/call_normal $WORK/normal_rlm_call - -# start a new node -gnoland start - -# 1. call to package ERROR -! gnokey maketx call -pkgpath gno.land/p/foo/call_forbidden -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 -stderr '"gnokey" error: --= Error =--\nData: forbidden/bad package called' - -# 2. call to stdlibs ERROR -! gnokey maketx call -pkgpath strconv -func Itoa -args 11 -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 -stderr '"gnokey" error: --= Error =--\nData: forbidden/bad package called' - -# 3. normal call to realm PASS -gnokey maketx call -pkgpath gno.land/r/foo/call_normal -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 -stdout OK! - --- forbidden/forbidden.gno -- -package call_forbidden - -func Render() string { - return "notok" -} - --- normal_rlm_call/normal_call.gno -- -package call_normal - -func Render() string { - return "ok" -} diff --git a/gno.land/cmd/gnoland/testdata/maketx_call_pure.txtar b/gno.land/cmd/gnoland/testdata/maketx_call_pure.txtar new file mode 100644 index 00000000000..e3231eccc01 --- /dev/null +++ b/gno.land/cmd/gnoland/testdata/maketx_call_pure.txtar @@ -0,0 +1,32 @@ +# load the package +loadpkg gno.land/p/foo/call_package $WORK/package +loadpkg gno.land/r/foo/call_realm $WORK/realm + +# start a new node +gnoland start + +# 1. call to package ERROR +! gnokey maketx call -pkgpath gno.land/p/foo/call_package -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +stderr '"gnokey" error: --= Error =--\nData: invalid package path' + +# 2. call to stdlibs ERROR +! gnokey maketx call -pkgpath strconv -func Itoa -args 11 -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +stderr '"gnokey" error: --= Error =--\nData: invalid package path' + +# 3. normal call to realm PASS +gnokey maketx call -pkgpath gno.land/r/foo/call_realm -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 +stdout OK! + +-- package/package.gno -- +package call_package + +func Render() string { + return "notok" +} + +-- realm/realm.gno -- +package call_realm + +func Render() string { + return "ok" +} diff --git a/gno.land/pkg/sdk/vm/errors.go b/gno.land/pkg/sdk/vm/errors.go index 23d8b801969..132d98b7ecd 100644 --- a/gno.land/pkg/sdk/vm/errors.go +++ b/gno.land/pkg/sdk/vm/errors.go @@ -22,7 +22,6 @@ type ( abciError Errors []string } - ForbiddenPkgCallError struct{ abciError } ) func (e InvalidPkgPathError) Error() string { return "invalid package path" } @@ -34,7 +33,6 @@ func (e TypeCheckError) Error() string { bld.WriteString(strings.Join(e.Errors, "\n")) return bld.String() } -func (e ForbiddenPkgCallError) Error() string { return "forbidden/bad package called" } func ErrInvalidPkgPath(msg string) error { return errors.Wrap(InvalidPkgPathError{}, msg) @@ -56,7 +54,3 @@ func ErrTypeCheck(err error) error { } return errors.NewWithData(tce).Stacktrace() } - -func ErrForbiddenPkgCall(msg string) error { - return errors.Wrap(ForbiddenPkgCallError{}, msg) -} diff --git a/gno.land/pkg/sdk/vm/msgs.go b/gno.land/pkg/sdk/vm/msgs.go index 9d75a1c7783..e5616fa2395 100644 --- a/gno.land/pkg/sdk/vm/msgs.go +++ b/gno.land/pkg/sdk/vm/msgs.go @@ -113,11 +113,11 @@ func (msg MsgCall) ValidateBasic() error { if msg.Caller.IsZero() { return std.ErrInvalidAddress("missing caller address") } - if msg.PkgPath == "" { // XXX + if msg.PkgPath == "" { return ErrInvalidPkgPath("missing package path") } if !gno.IsRealmPath(msg.PkgPath) { - return ErrForbiddenPkgCall("pkgpath must be a realm") + return ErrInvalidPkgPath("pkgpath must be of a realm") } if msg.Func == "" { // XXX return ErrInvalidExpr("missing function to call") diff --git a/gno.land/pkg/sdk/vm/package.go b/gno.land/pkg/sdk/vm/package.go index 94c226b5f8f..b2e7fbecfc4 100644 --- a/gno.land/pkg/sdk/vm/package.go +++ b/gno.land/pkg/sdk/vm/package.go @@ -21,5 +21,4 @@ var Package = amino.RegisterPackage(amino.NewPackage( InvalidStmtError{}, "InvalidStmtError", InvalidExprError{}, "InvalidExprError", TypeCheckError{}, "TypeCheckError", - ForbiddenPkgCallError{}, "ForbiddenPkgCallError", )) diff --git a/gnovm/pkg/gnolang/realm.go b/gnovm/pkg/gnolang/realm.go index 17b655e6352..85f94d4fcbe 100644 --- a/gnovm/pkg/gnolang/realm.go +++ b/gnovm/pkg/gnolang/realm.go @@ -1518,7 +1518,7 @@ func isUnsaved(oo Object) bool { // be realms and as such to have their state persisted. This is used by [IsRealmPath]. const realmPathPrefix = "gno.land/r/" -var ReGnoRunPath = regexp.MustCompile(`gno\.land/r/g[a-z0-9]+/run`) +var ReGnoRunPath = regexp.MustCompile(`^gno\.land/r/g[a-z0-9]+/run$`) // IsRealmPath determines whether the given pkgpath is for a realm, and as such // should persist the global state.