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

chore: add more validation to MsgRun & MsgAddPackage #1646

Closed
wants to merge 7 commits into from

Conversation

leohhhn
Copy link
Contributor

@leohhhn leohhhn commented Feb 8, 2024

Description

This PR adds more validation to MsgRun & MsgAddPkg. It does this by adding a few checks to MemPackage's Validate(), and then incorporating checks on MemPackage within MsgRun & MsgAddPkg.

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • 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, if any. More info here.

@leohhhn leohhhn self-assigned this Feb 8, 2024
@github-actions github-actions bot added the 📦 ⛰️ gno.land Issues or PRs gno.land package related label Feb 8, 2024
@leohhhn leohhhn marked this pull request as ready for review February 8, 2024 18:39
@leohhhn leohhhn requested a review from moul as a code owner February 8, 2024 18:39
Copy link

codecov bot commented Feb 8, 2024

Codecov Report

Attention: 15 lines in your changes are missing coverage. Please review.

Comparison is base (9734695) 56.25% compared to head (3276888) 56.11%.

Files Patch % Lines
gno.land/pkg/sdk/vm/msgs.go 0.00% 6 Missing ⚠️
tm2/pkg/std/memfile.go 0.00% 4 Missing and 2 partials ⚠️
gno.land/pkg/sdk/vm/errors.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1646      +/-   ##
==========================================
- Coverage   56.25%   56.11%   -0.15%     
==========================================
  Files         425      439      +14     
  Lines       64408    66194    +1786     
==========================================
+ Hits        36235    37147     +912     
- Misses      25351    26155     +804     
- Partials     2822     2892      +70     
Flag Coverage Δ
go-1.21.x ∅ <ø> (∅)
misc ∅ <ø> (∅)
misc-_test.genstd ∅ <ø> (∅)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@leohhhn leohhhn requested a review from thehowl February 8, 2024 18:40
@github-actions github-actions bot added the 📦 🌐 tendermint v2 Issues or PRs tm2 related label Feb 8, 2024
@leohhhn leohhhn changed the title chore: add more validation to MsgRun chore: add more validation to MsgRun & MsgAddPackage Feb 8, 2024
tm2/pkg/std/memfile.go Outdated Show resolved Hide resolved
@zivkovicmilos
Copy link
Member

Please give me a minute to review this, I'm sensing it's a touchy PR 🙏

@thehowl
Copy link
Member

thehowl commented Feb 29, 2024

cc/ @jaekwon, from review meeting:

Is there any reason why ValidateBasic is called basic? Should the checks perform within it be very fast, "basic" or whatever? Can we add the mempkg check in there, or would it create problems?

Copy link
Member

@zivkovicmilos zivkovicmilos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you move the Package validation outside the keeper methods, that validate it upon execution, and into ValidateBasic, which should be a quick sanity check for validity?

We use Package.Validate and ValidateBasic in the same sense how we use CheckTx and DeliverTx - one is a quick sanity check, and the other is detailed validation (VM processing).

We execute ValidateBasic for top-level validations (ex. when the node receives a tx message from gossip), and do additional validations (execution validations) when the node actually commits it to the VM.

I am not convinced this change is valid

@@ -50,12 +50,19 @@ var (
// file names must contain dots.
// NOTE: this is to prevent conflicts with nested paths.
func (mempkg *MemPackage) Validate() error {
if mempkg == nil {
return errors.New(fmt.Sprintf("package is nil"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should format errors with fmt.Errorf.

Looking at this again, you don't even format an error here, this entire call is useless - define it as a package-level error

if !rePkgName.MatchString(mempkg.Name) {
return errors.New(fmt.Sprintf("invalid package name %q, failed to match %q", mempkg.Name, rePkgName))
}
if !rePkgOrRlmPath.MatchString(mempkg.Path) {
return errors.New(fmt.Sprintf("invalid package/realm path %q, failed to match %q", mempkg.Path, rePkgOrRlmPath))
}
if mempkg.IsEmpty() {
return errors.New(fmt.Sprintf("package %q contains no files", mempkg.Name))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should format errors with fmt.Errorf

@@ -50,12 +50,19 @@ var (
// file names must contain dots.
// NOTE: this is to prevent conflicts with nested paths.
func (mempkg *MemPackage) Validate() error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add unit tests for MemPackage validation

Comment on lines +62 to +64
if err := msg.Package.Validate(); err != nil {
return ErrInvalidPackage(err.Error())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this covered?

Comment on lines +194 to +196
if err := msg.Package.Validate(); err != nil {
return ErrInvalidPackage(err.Error())
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this covered?

)

func (e InvalidPkgPathError) Error() string { return "invalid package path" }
func (e InvalidPackageError) Error() string { return "package validation failed" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a documentation reference in this PR as to what is a "valid package" 🙏

@zivkovicmilos
Copy link
Member

@leohhhn what's the status on this PR?

cc @Kouteki

@leohhhn
Copy link
Contributor Author

leohhhn commented Apr 29, 2024

@zivkovicmilos

This has been hanging mainly because I assume I will spend too much time due to my lack of knowledge on how the keeper works - I will give it a shot this week and try to incorporate the change you requested. Will ping you when I'm done 👍

EDIT: I asked for your opinion on this privately but received no reply. I'm focusing on other priorities so I will not work on this now.

@leohhhn leohhhn closed this Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related 📦 ⛰️ gno.land Issues or PRs gno.land package related
Projects
Status: Done
Status: Done
Status: No status
Development

Successfully merging this pull request may close these issues.

5 participants