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

Unable to access embedded variables in different files of imported package #3103

Open
jinoosss opened this issue Nov 10, 2024 · 1 comment
Open

Comments

@jinoosss
Copy link
Member

Error Accessing Internal Pointer Objects Across Different Files in Imported Package

Description

An error occurs while deploying the GRC721 package using the grc721.NewNFTWithMetadata(name string, symbol string) function.
When attempting to deploy the package, an access denied message appears alongside an error indicating issues with accessing internal pointer objects.

This problem seems to arise when importing the package and attempting to access pointer objects from different files within the imported package.

Your environment

  • Go version: go1.22.4
  • Gno commit hash causing the issue: 4f27a57

Steps to reproduce

  1. Deploy the Package Using NewNFTWithMetadata:
    • Import the gno.land/p/demo/grc/grc721 package.
    • Create a GRC721 instance through the grc721.NewNFTWithMetadata(name string, symbol string) function.
    • Write code to call the instance's function.

[Example]

package meta_nft

import (
	"std"

	"gno.land/p/demo/grc/grc721"
)

var (
	admin std.Address = "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5"
	meta              = grc721.NewNFTWithMetadata("Meta", "META")
)

// Render

func Render(path string) string {
	switch {
	case path == "":
		return meta.RenderHome()
	default:
		return "404\n"
	}
}
  1. Observe the Access Error:
    An error message indicating inability to access internal pointer objects appears during deployment.

Expected behaviour

The GRC721 package should deploy successfully without any access-related errors, allowing seamless interaction with internal objects and pointer references within the package.

Actual behaviour

During the deployment process, an access error occurs, preventing the use of the metadataNFT within the meta_nft package. This error suggests that the package cannot access certain internal pointer objects after being imported.

Logs

msg:0,success:false,log:--= Error =--
Data: &errors.errorString{s:"gno.land/r/test1/meta_nft/package.gno:17:0: cannot access *gno.land/p/demo/grc/grc721.metadataNFT.basicNFT from gno.land/r/test1/meta_nft:\n--- preprocess stack ---\nstack 0: case (const-type bool)(path<VPBlock(2,0)> == (const (\"\" string))): return meta<VPBlock(4,1)>.RenderHome()\n------------------------:\n--- preprocess stack ---\nstack 4: case (const-type bool)(path<VPBlock(2,0)> == (const (\"\" string))): return meta<VPBlock(4,1)>.RenderHome()\nstack 3: switch (const (true bool)) { case (const-type bool)(path<VPBlock(2,0)> == (const (\"\" string))): return meta<VPBlock(4,1)>.RenderHome(); default: return \"404\\n\" }\nstack 2: func Render(path (const-type string))  (const-type string) { switch (const (true bool)) { case (const-type bool)(path<VPBlock(2,0)> == (const (\"\" string))): return meta<VPBlock(4,1)>.RenderHome(); default: return \"404\\n\" } }\nstack 1: file{ package meta_nft; import std std; import grc721 gno.land/p/demo/grc/grc721; var admin<!VPBlock(2,0)> std<VPBlock(1,0)>.Address = (const (\"g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5\" std.Address)); var meta<!VPBlock(2,1)> = grc721<VPBlock(1,1)>.NewNFTWithMetadata((const (\"Meta\" string)), (const (\"META\" string))); func Render(path (const-type string))  (const-type string) { switch (const (true bool)) { case (const-type bool)(path<VPBlock(2,0)> == (const (\"\" string))): return meta<VPBlock(4,1)>.RenderHome(); default: return \"404\\n\" } } }\nstack 0: package(meta_nft)\n------------------------"}
Msg Traces:
    0  /Users/user/Workspace/gno/gno/gno.land/pkg/sdk/vm/keeper.go:394 - VM addpkg panic: gno.land/r/test1/meta_nft/package.gno:17:0: cannot access *gno.land/p/demo/grc/grc721.metadataNFT.basicNFT from gno.land/r/test1/meta_nft:
--- preprocess stack ---
stack 0: case (const-type bool)(path<VPBlock(2,0)> == (const ("" string))): return meta<VPBlock(4,1)>.RenderHome()
------------------------:
--- preprocess stack ---
stack 4: case (const-type bool)(path<VPBlock(2,0)> == (const ("" string))): return meta<VPBlock(4,1)>.RenderHome()
stack 3: switch (const (true bool)) { case (const-type bool)(path<VPBlock(2,0)> == (const ("" string))): return meta<VPBlock(4,1)>.RenderHome(); default: return "404\n" }
stack 2: func Render(path (const-type string))  (const-type string) { switch (const (true bool)) { case (const-type bool)(path<VPBlock(2,0)> == (const ("" string))): return meta<VPBlock(4,1)>.RenderHome(); default: return "404\n" } }
stack 1: file{ package meta_nft; import std std; import grc721 gno.land/p/demo/grc/grc721; var admin<!VPBlock(2,0)> std<VPBlock(1,0)>.Address = (const ("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5" std.Address)); var meta<!VPBlock(2,1)> = grc721<VPBlock(1,1)>.NewNFTWithMetadata((const ("Meta" string)), (const ("META" string))); func Render(path (const-type string))  (const-type string) { switch (const (true bool)) { case (const-type bool)(path<VPBlock(2,0)> == (const ("" string))): return meta<VPBlock(4,1)>.RenderHome(); default: return "404\n" } } }
stack 0: package(meta_nft)
------------------------
Machine:
    CheckTypes: false
    Op: []
    Values: (len: 0)
    Exprs:
    Stmts:
    Blocks:
    Blocks (other):
    Frames:
    Realm:
      gno.land/r/test1/meta_nft
    Exceptions:


Stack Trace:
    0  /Users/user/Workspace/gno/gno/tm2/pkg/errors/errors.go:20
    1  /Users/user/Workspace/gno/gno/gno.land/pkg/sdk/vm/keeper.go:394
    2  /Users/user/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:770
    3  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/preprocess.go:375
    4  /Users/user/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:770
    5  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/preprocess.go:375
    6  /Users/user/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:770
    7  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/preprocess.go:1778
    8  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/transcribe.go:752
    9  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/transcribe.go:136
   10  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/preprocess.go:452
   11  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/preprocess.go:412
   12  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/preprocess.go:1801
   13  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/transcribe.go:752
   14  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/transcribe.go:165
   15  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/transcribe.go:555
   16  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/transcribe.go:663
   17  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/transcribe.go:634
   18  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/transcribe.go:690
   19  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/transcribe.go:732
   20  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/transcribe.go:136
   21  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/preprocess.go:452
   22  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/preprocess.go:412
   23  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/machine.go:651
   24  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/machine.go:606
   25  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/machine.go:302
   26  /Users/user/Workspace/gno/gno/gnovm/pkg/gnolang/machine.go:268
   27  /Users/user/Workspace/gno/gno/gno.land/pkg/sdk/vm/keeper.go:400
   28  /Users/user/Workspace/gno/gno/gno.land/pkg/sdk/vm/handler.go:44
   29  /Users/user/Workspace/gno/gno/gno.land/pkg/sdk/vm/handler.go:31
   30  /Users/user/Workspace/gno/gno/tm2/pkg/sdk/baseapp.go:651
   31  /Users/user/Workspace/gno/gno/tm2/pkg/sdk/baseapp.go:840
--= /Error =--
,events:[]

Proposed solution

It might be beneficial to modify the FindEmbeddedFieldType function within gnovm to ensure that the callerPath accurately reflects the immediate caller’s package path rather than defaulting to the top-level package path.
Currently, during recursive function calls, callerPath is maintained as the top-level package path, which seems to cause a loss of context regarding the immediate caller’s package.
callerPath is the path to the calling package's path when executing the recursive function.

Rationale:

By updating the callerPath to the immediate caller’s package path, the function can correctly identify package boundaries and enforce access permissions accurately.

In this condition of the FindEmbeddedFieldType function, you can check if they are called from the same package. [Check Pacakge Path] (

gno/gnovm/pkg/gnolang/types.go

Lines 1626 to 1628 in 4f27a57

if !isUpper(string(n)) && dt.PkgPath != callerPath {
return nil, false, nil, nil, true
}
)

This change will prevent the access errors encountered during the deployment of the GRC721 package.

Additional Information

The existing implementation of the FindEmbeddedFieldType function passes the callerPath as the top-level package path during recursive calls.
This approach appears to cause the function to lose the context of the immediate caller’s package path, leading to incorrect access permissions and preventing interaction with internal pointer objects.

Relevant Links:

@dongwon8247
Copy link
Member

WIP to try to address this by Jinwoo jinoosss@531d73a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Triage
Development

No branches or pull requests

2 participants