Skip to content

Commit

Permalink
Merge branch 'master' into feat/added-args
Browse files Browse the repository at this point in the history
  • Loading branch information
salihdhaifullah authored Oct 16, 2024
2 parents 41d51ef + 641d2fd commit 0b5058c
Show file tree
Hide file tree
Showing 154 changed files with 1,924 additions and 241 deletions.
4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
# GnoVM/Gnolang.
/gnovm/ @jaekwon @moul @piux2 @thehowl
/gnovm/stdlibs/ @thehowl
/gnovm/tests/ @jaekwon @deelawn @thehowl @mvertes
/gnovm/tests/ @jaekwon @thehowl @mvertes
/gnovm/cmd/gno/ @moul @thehowl
/gnovm/pkg/gnolang/ @jaekwon @moul @piux2 @deelawn
/gnovm/pkg/gnolang/ @jaekwon @moul @piux2
/gnovm/pkg/doc/ @thehowl
/gnovm/pkg/repl/ @mvertes @ajnavarro
/gnovm/pkg/gnomod/ @thehowl
Expand Down
1 change: 0 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@
- [ ] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description
- [ ] Added references to related issues and PRs
- [ ] Provided any useful hints for running manual tests
- [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md).
</details>
13 changes: 13 additions & 0 deletions docs/gno-tooling/cli/gnokey/working-with-key-pairs.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ gno.land keychain & client
SUBCOMMANDS
add adds key to the keybase
delete deletes a key from the keybase
rotate rotate the password of a key in the keybase to a new password
generate generates a bip39 mnemonic
export exports private key armor
import imports encrypted private key armor
Expand Down Expand Up @@ -161,6 +162,18 @@ you can recover it using the key's mnemonic, or by importing it if it was export
at a previous point in time.
:::


## Rotating the password of a private key to a new password
To rotate the password of a private key from the `gnokey` keystore to a new password, we need to know the name or
address of the key to remove.
After we have this information, we can run the following command:

```bash
gnokey rotate MyKey
```

After entering the current key decryption password and the new password, the password of the key will be updated in the keystore.

## Exporting a private key
Private keys stored in the `gnokey` keystore can be exported to a desired place
on the user's filesystem.
Expand Down
2 changes: 1 addition & 1 deletion examples/gno.land/p/demo/uassert/uassert.gno
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func NotEqual(t TestingT, expected, actual interface{}, msgs ...string) bool {
if av, ok := actual.(string); ok {
notEqual = ev != av
ok_ = true
es, as = ev, as
es, as = ev, av
}
case std.Address:
if av, ok := actual.(std.Address); ok {
Expand Down
20 changes: 9 additions & 11 deletions examples/gno.land/r/leon/config/config.gno
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
var (
main std.Address // leon's main address
backup std.Address // backup address

ErrInvalidAddr = errors.New("leon's config: invalid address")
ErrUnauthorized = errors.New("leon's config: unauthorized")
)

func init() {
Expand All @@ -24,7 +27,7 @@ func Backup() std.Address {

func SetAddress(a std.Address) error {
if !a.IsValid() {
return errors.New("config: invalid address")
return ErrInvalidAddr
}

if err := checkAuthorized(); err != nil {
Expand All @@ -37,7 +40,7 @@ func SetAddress(a std.Address) error {

func SetBackup(a std.Address) error {
if !a.IsValid() {
return errors.New("config: invalid address")
return ErrInvalidAddr
}

if err := checkAuthorized(); err != nil {
Expand All @@ -50,16 +53,11 @@ func SetBackup(a std.Address) error {

func checkAuthorized() error {
caller := std.PrevRealm().Addr()
if caller != main || caller != backup {
return errors.New("config: unauthorized")
isAuthorized := caller == main || caller == backup

if !isAuthorized {
return ErrUnauthorized
}

return nil
}

func AssertAuthorized() {
caller := std.PrevRealm().Addr()
if caller != main || caller != backup {
panic("config: unauthorized")
}
}
14 changes: 12 additions & 2 deletions examples/gno.land/r/leon/home/home.gno
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ TODO import r/gh
}

func UpdatePFP(url, caption string) {
config.AssertAuthorized()
if !isAuthorized(std.PrevRealm().Addr()) {
panic(config.ErrUnauthorized)
}

pfp = url
pfpCaption = caption
}

func UpdateAboutMe(col1, col2 string) {
config.AssertAuthorized()
if !isAuthorized(std.PrevRealm().Addr()) {
panic(config.ErrUnauthorized)
}

abtMe[0] = col1
abtMe[1] = col2
}
Expand Down Expand Up @@ -119,3 +125,7 @@ func renderMillipede() string {

return out
}

func isAuthorized(addr std.Address) bool {
return addr == config.Address() || addr == config.Backup()
}
4 changes: 2 additions & 2 deletions gno.land/pkg/gnoweb/gnoweb.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ func handleNotFound(logger *slog.Logger, app gotuna.App, cfg *Config, path strin
// decode path for non-ascii characters
decodedPath, err := url.PathUnescape(path)
if err != nil {
logger.Error("failed to decode path", err)
logger.Error("failed to decode path", "error", err)
decodedPath = path
}
w.WriteHeader(http.StatusNotFound)
Expand All @@ -491,7 +491,7 @@ func writeError(logger *slog.Logger, w http.ResponseWriter, err error) {
if details := errors.Unwrap(err); details != nil {
logger.Error("handler", "error", err, "details", details)
} else {
logger.Error("handler", "error:", err)
logger.Error("handler", "error", err)
}

// XXX: writeError should return an error page template.
Expand Down
1 change: 1 addition & 0 deletions gno.land/pkg/keyscli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func NewRootCmd(io commands.IO, base client.BaseOptions) *commands.Command {
cmd.AddSubCommands(
client.NewAddCmd(cfg, io),
client.NewDeleteCmd(cfg, io),
client.NewRotateCmd(cfg, io),
client.NewGenerateCmd(cfg, io),
client.NewExportCmd(cfg, io),
client.NewImportCmd(cfg, io),
Expand Down
4 changes: 2 additions & 2 deletions gno.land/pkg/sdk/vm/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ func (bnk *SDKBanker) TotalCoin(denom string) int64 {

func (bnk *SDKBanker) IssueCoin(b32addr crypto.Bech32Address, denom string, amount int64) {
addr := crypto.MustAddressFromString(string(b32addr))
_, err := bnk.vmk.bank.AddCoins(bnk.ctx, addr, std.Coins{std.Coin{denom, amount}})
_, err := bnk.vmk.bank.AddCoins(bnk.ctx, addr, std.Coins{std.Coin{Denom: denom, Amount: amount}})
if err != nil {
panic(err)
}
}

func (bnk *SDKBanker) RemoveCoin(b32addr crypto.Bech32Address, denom string, amount int64) {
addr := crypto.MustAddressFromString(string(b32addr))
_, err := bnk.vmk.bank.SubtractCoins(bnk.ctx, addr, std.Coins{std.Coin{denom, amount}})
_, err := bnk.vmk.bank.SubtractCoins(bnk.ctx, addr, std.Coins{std.Coin{Denom: denom, Amount: amount}})
if err != nil {
panic(err)
}
Expand Down
18 changes: 9 additions & 9 deletions gno.land/pkg/sdk/vm/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestVMKeeperOrigSend1(t *testing.T) {

// Create test package.
files := []*std.MemFile{
{"init.gno", `
{Name: "init.gno", Body: `
package test
import "std"
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestVMKeeperOrigSend2(t *testing.T) {

// Create test package.
files := []*std.MemFile{
{"init.gno", `
{Name: "init.gno", Body: `
package test
import "std"
Expand Down Expand Up @@ -180,7 +180,7 @@ func TestVMKeeperOrigSend3(t *testing.T) {

// Create test package.
files := []*std.MemFile{
{"init.gno", `
{Name: "init.gno", Body: `
package test
import "std"
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestVMKeeperRealmSend1(t *testing.T) {

// Create test package.
files := []*std.MemFile{
{"init.gno", `
{Name: "init.gno", Body: `
package test
import "std"
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestVMKeeperRealmSend2(t *testing.T) {

// Create test package.
files := []*std.MemFile{
{"init.gno", `
{Name: "init.gno", Body: `
package test
import "std"
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestVMKeeperOrigCallerInit(t *testing.T) {

// Create test package.
files := []*std.MemFile{
{"init.gno", `
{Name: "init.gno", Body: `
package test
import "std"
Expand Down Expand Up @@ -363,7 +363,7 @@ func TestVMKeeperRunSimple(t *testing.T) {
env.acck.SetAccount(ctx, acc)

files := []*std.MemFile{
{"script.gno", `
{Name: "script.gno", Body: `
package main
func main() {
Expand Down Expand Up @@ -402,7 +402,7 @@ func testVMKeeperRunImportStdlibs(t *testing.T, env testEnv) {
env.acck.SetAccount(ctx, acc)

files := []*std.MemFile{
{"script.gno", `
{Name: "script.gno", Body: `
package main
import "std"
Expand Down Expand Up @@ -474,7 +474,7 @@ func TestVMKeeperReinitialize(t *testing.T) {

// Create test package.
files := []*std.MemFile{
{"init.gno", `
{Name: "init.gno", Body: `
package test
func Echo(msg string) string {
Expand Down
4 changes: 2 additions & 2 deletions gnovm/pkg/gnolang/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func TestEvalFiles(t *testing.T) {
if wantStacktrace != "" && !strings.Contains(stacktrace, wantStacktrace) {
t.Fatalf("unexpected stacktrace\nWant: %s\n Got: %s", wantStacktrace, stacktrace)
}
if wantOut != "" && out != wantOut {
t.Fatalf("unexpected output\nWant: %s\n Got: %s", wantOut, out)
if wantOut != "" && strings.TrimSpace(out) != strings.TrimSpace(wantOut) {
t.Fatalf("unexpected output\nWant: \"%s\"\n Got: \"%s\"", wantOut, out)
}
})

Expand Down
1 change: 1 addition & 0 deletions gnovm/pkg/gnolang/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2119,6 +2119,7 @@ const (
ATTR_IOTA GnoAttribute = "ATTR_IOTA"
ATTR_LOCATIONED GnoAttribute = "ATTR_LOCATIONED"
ATTR_INJECTED GnoAttribute = "ATTR_INJECTED"
ATTR_SHIFT_RHS GnoAttribute = "ATTR_SHIFT_RHS"
)

var rePkgName = regexp.MustCompile(`^[a-z][a-z0-9_]+$`)
Expand Down
2 changes: 2 additions & 0 deletions gnovm/pkg/gnolang/op_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,7 @@ func xorAssign(lv, rv *TypedValue) {

// for doOpShl and doOpShlAssign.
func shlAssign(lv, rv *TypedValue) {
rv.AssertNonNegative("runtime error: negative shift amount")
// set the result in lv.
// NOTE: baseOf(rv.T) is always UintType.
switch baseOf(lv.T) {
Expand Down Expand Up @@ -1136,6 +1137,7 @@ func shlAssign(lv, rv *TypedValue) {

// for doOpShr and doOpShrAssign.
func shrAssign(lv, rv *TypedValue) {
rv.AssertNonNegative("runtime error: negative shift amount")
// set the result in lv.
// NOTE: baseOf(rv.T) is always UintType.
switch baseOf(lv.T) {
Expand Down
5 changes: 5 additions & 0 deletions gnovm/pkg/gnolang/op_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func (m *Machine) doOpPrecall() {
case TypeValue:
// Do not pop type yet.
// No need for frames.
xv := m.PeekValue(1)
if cx.GetAttribute(ATTR_SHIFT_RHS) == true {
xv.AssertNonNegative("runtime error: negative shift amount")
}

m.PushOp(OpConvert)
if debug {
if len(cx.Args) != 1 {
Expand Down
Loading

0 comments on commit 0b5058c

Please sign in to comment.