Skip to content

Commit

Permalink
allowed-wasm-module-roots: accept paths as well
Browse files Browse the repository at this point in the history
  • Loading branch information
tsahee committed May 20, 2024
1 parent 6485758 commit 019581e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
import (
"context"
"crypto/ecdsa"
"encoding/hex"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -452,7 +453,21 @@ func mainImpl() int {
if len(allowedWasmModuleRoots) > 0 {
moduleRootMatched := false
for _, root := range allowedWasmModuleRoots {
if common.HexToHash(root) == moduleRoot {
bytes, err := hex.DecodeString(root)
if err == nil {
if common.HexToHash(root) == common.BytesToHash(bytes) {
moduleRootMatched = true
break
}
continue
}
locator, locatorErr := server_common.NewMachineLocator(root)
if err != nil {
log.Warn("allowed-wasm-module-roots: value not a hex nor valid path:", "value", root, "locatorErr", locatorErr, "decodeErr", err)
continue
}
path := locator.GetMachinePath(moduleRoot)
if _, err := os.Stat(path); err == nil {
moduleRootMatched = true
break
}
Expand Down
2 changes: 1 addition & 1 deletion validator/valnode/valnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type WasmConfig struct {
func WasmConfigAddOptions(prefix string, f *pflag.FlagSet) {
f.String(prefix+".root-path", DefaultWasmConfig.RootPath, "path to machine folders, each containing wasm files (machine.wavm.br, replay.wasm)")
f.Bool(prefix+".enable-wasmroots-check", DefaultWasmConfig.EnableWasmrootsCheck, "enable check for compatibility of on-chain WASM module root with node")
f.StringSlice(prefix+".allowed-wasm-module-roots", DefaultWasmConfig.AllowedWasmModuleRoots, "list of WASM module roots to check if the on-chain WASM module root belongs to on node startup")
f.StringSlice(prefix+".allowed-wasm-module-roots", DefaultWasmConfig.AllowedWasmModuleRoots, "list of WASM module roots or mahcine base paths to match against on-chain WasmModuleRoot")
}

var DefaultWasmConfig = WasmConfig{
Expand Down

0 comments on commit 019581e

Please sign in to comment.