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

Runtime Panic in gno when Built with -trimpath build flag due to Amino Package Path Resolution #1236

Open
gfanton opened this issue Oct 11, 2023 · 0 comments
Labels
🐞 bug Something isn't working

Comments

@gfanton
Copy link
Member

gfanton commented Oct 11, 2023

Runtime Panic in gno when Built with -trimpath build Flag due to Amino Package Path Resolution

Description

Using the -trimpath build flag with gno results in a runtime panic.

Environment

  • OS: macOS Sonoma 14.0
  • gno Version: master
  • commit: tested on b34816b

Steps to Reproduce

# Navigate to gnovm directory within the gno repository
$ cd gnovm

# Manually build the gno binary using the `-trimpath` flag
$ go build -trimpath -o build/gno ./cmd/gno

# Run the gno binary
$ ./build/gno

Expected Behaviour

All gno commands should run as intended without any errors.

Actual Behaviour

gno encounters a panic.

Logs

panic: dirName, if present, should be absolute, but received: github.com/gnolang/gno/tm2/pkg/crypto/multisig

goroutine 1 [running]:
github.com/gnolang/gno/tm2/pkg/amino/pkg.assertValidDirName({0x1057c2a99?, 0x2?})
	github.com/gnolang/gno/tm2/pkg/amino/pkg/pkg.go:356 +0x174
github.com/gnolang/gno/tm2/pkg/amino/pkg.NewPackage({0x105309e57, 0x2e}, {0x1052e3b13, 0x2}, {0x1057c2a99, 0x2e})
	github.com/gnolang/gno/tm2/pkg/amino/pkg/pkg.go:73 +0x90
github.com/gnolang/gno/tm2/pkg/amino.NewPackage(...)
	github.com/gnolang/gno/tm2/pkg/amino/amino.go:883
github.com/gnolang/gno/tm2/pkg/crypto/multisig.init()

Possible Cause & Solution

The underlying issue appears to be a side effect of the amino package using the call stack to obtain an absolute path of the current directory. As this behavior is triggered implicitly without a direct call (siimply by importing the package) it might be challenging to fix.

A code snippet showcasing the implicit behavior:

// gnolang/gno/tm2/pkg/bitarray
package bitarray

import "github.com/gnolang/gno/tm2/pkg/amino"

var Package = amino.RegisterPackage(amino.NewPackage(
	"github.com/gnolang/gno/tm2/pkg/bitarray",
	"tm",
	amino.GetCallersDirname(), // <<<< HERE
).WithDependencies().WithTypes(
	BitArray{}, "BitArray",
))

We cannot pass variables, except perhaps through environment variables like GNOROOT. However, it's undesirable for tm2 to be dependent on such a variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
Status: Triage
Development

No branches or pull requests

3 participants