-
Notifications
You must be signed in to change notification settings - Fork 120
smaller PR #659
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
base: main
Are you sure you want to change the base?
smaller PR #659
Changes from all commits
fdaf809
016154b
71b2d1e
f371399
cbde717
08ea4c4
7a812f5
65039a5
ada59f4
a06cd0d
1118f26
d6c14e6
d943802
f9e29a6
ce052d6
59fa5a4
20aaea0
19d75a5
f74e259
1aa9993
66ff709
e7e28b8
703cc45
2e9424b
71448a8
6838413
a574461
0e58174
c0d7ea2
ff1c56d
c9bc165
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,53 +4,91 @@ import ( | |
"fmt" | ||
"math" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
wasmvm "github.com/CosmWasm/wasmvm/v3" | ||
) | ||
|
||
// PrintDebug enables debug printing when true. | ||
const ( | ||
PRINT_DEBUG = true | ||
MEMORY_LIMIT = 32 // MiB | ||
CACHE_SIZE = 100 // MiB | ||
PrintDebug = true | ||
// MemoryLimit defines the memory limit in MiB. | ||
MemoryLimit = 32 | ||
// CacheSize defines the cache size in MiB. | ||
CacheSize = 100 | ||
) | ||
|
||
var SUPPORTED_CAPABILITIES = []string{"staking"} | ||
// SupportedCapabilities defines the list of supported staking capabilities. | ||
var SupportedCapabilities = []string{"staking"} | ||
|
||
// This is just a demo to ensure we can compile a static go binary | ||
// exitCode tracks the code that the program will exit with. | ||
var exitCode = 0 | ||
|
||
// main is the entry point for the demo application that tests wasmvm functionality. | ||
func main() { | ||
defer func() { | ||
os.Exit(exitCode) | ||
}() | ||
|
||
if len(os.Args) < 2 { | ||
fmt.Println("Usage: demo <file|version>") | ||
exitCode = 1 | ||
return | ||
} | ||
chipshort marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
file := os.Args[1] | ||
|
||
if file == "version" { | ||
libwasmvmVersion, err := wasmvm.LibwasmvmVersion() | ||
if err != nil { | ||
panic(err) | ||
fmt.Printf("Error getting libwasmvm version: %v\n", err) | ||
exitCode = 1 | ||
return | ||
} | ||
fmt.Printf("libwasmvm: %s\n", libwasmvmVersion) | ||
return | ||
} | ||
|
||
fmt.Printf("Running %s...\n", file) | ||
bz, err := os.ReadFile(file) | ||
|
||
// Validate file path | ||
cleanPath := filepath.Clean(file) | ||
if filepath.IsAbs(cleanPath) || strings.Contains(cleanPath, "..") { | ||
fmt.Println("Error: invalid file path") | ||
exitCode = 1 | ||
return | ||
} | ||
Comment on lines
+57
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why go out of our way to reject absolute paths and paths in the parent directory? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. slavishly satisfying the linter's high standards There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this a "high standard"? Are there possible problems with accepting absolute paths or paths inside the parent directory? Otherwise, this is needlessly restrictive. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, it's a security thing, suggest we keep it. It's basically keeping us vigilant here, I think that's okay There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove and mark as nolint. A lint like this makes sense in a webserver environment where you want people to only access relative paths inside a directory. This is a cli application where the path is supplied by the person who executes it. |
||
|
||
bz, err := os.ReadFile(cleanPath) | ||
if err != nil { | ||
panic(err) | ||
fmt.Printf("Error reading file: %v\n", err) | ||
exitCode = 1 | ||
return | ||
} | ||
fmt.Println("Loaded!") | ||
|
||
err = os.MkdirAll("tmp", 0o755) | ||
err = os.MkdirAll("tmp", 0o750) | ||
if err != nil { | ||
panic(err) | ||
fmt.Printf("Error creating tmp directory: %v\n", err) | ||
exitCode = 1 | ||
return | ||
} | ||
vm, err := wasmvm.NewVM("tmp", SUPPORTED_CAPABILITIES, MEMORY_LIMIT, PRINT_DEBUG, CACHE_SIZE) | ||
vm, err := wasmvm.NewVM("tmp", SupportedCapabilities, MemoryLimit, PrintDebug, CacheSize) | ||
if err != nil { | ||
panic(err) | ||
fmt.Printf("Error creating VM: %v\n", err) | ||
exitCode = 1 | ||
return | ||
} | ||
defer vm.Cleanup() | ||
|
||
checksum, _, err := vm.StoreCode(bz, math.MaxUint64) | ||
if err != nil { | ||
panic(err) | ||
fmt.Printf("Error storing code: %v\n", err) | ||
exitCode = 1 | ||
return | ||
} | ||
fmt.Printf("Stored code with checksum: %X\n", checksum) | ||
|
||
vm.Cleanup() | ||
fmt.Println("finished") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one seems a bit out of place. We don't handle HTTP requests here. Let's remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eh, let's keep it in case we ever do. Its there to prevent mistakes sir. Now we know we pass that linter. There are many more to pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sir, this is glue code between a blockchain sdk and a VM. It will never do any HTTP requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass the linter anyhow. The idea is to have e'm all (well realistically the right ones) working right. So I can remove it, but there's no reason to it eats like .1s or something and provides a layer of protection in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove. If I accept useless changes like this, the repo will bloat in no time.