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

feat: avoid Instantiation of banker on pure packages #2248

Merged
merged 13 commits into from
Oct 23, 2024

Conversation

Villaquiranm
Copy link
Contributor

Related to #2192

  • Trigger a panic if a p/ attempts to create a banker, but allow interaction with an already instantiated banker from r/.

Don't really know if this is the right approach. If you have another idea of how to implement this security check please let me know :)

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.

Copy link

codecov bot commented May 30, 2024

Codecov Report

Attention: Patch coverage is 28.57143% with 5 lines in your changes missing coverage. Please review.

Project coverage is 63.40%. Comparing base (a2e5c3d) to head (53369df).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
gnovm/stdlibs/std/native.go 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2248      +/-   ##
==========================================
- Coverage   63.40%   63.40%   -0.01%     
==========================================
  Files         565      565              
  Lines       79454    79461       +7     
==========================================
+ Hits        50375    50379       +4     
- Misses      25688    25690       +2     
- Partials     3391     3392       +1     
Flag Coverage Δ
contribs/gnodev 60.57% <ø> (+0.62%) ⬆️
contribs/gnofaucet 15.77% <ø> (+0.94%) ⬆️
gno.land 67.37% <ø> (ø)
gnovm 67.87% <28.57%> (-0.01%) ⬇️
misc/genstd 79.72% <ø> (ø)
tm2 62.47% <ø> (+0.13%) ⬆️

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.

Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

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

This will not work in a real life scenario, as CurrentRealm() skips frames of pure packages. (If you want a good side-task, change NewCodeRealm to work only with PkgPath's that match the rules of gnolang.IsRealmPath)

I suggest:

  • Having a function like assertCallerIsRealm.
  • This should get the frame of the function where this is called (I think m.Frames[m.NumFrames()-2]).
  • Then call LastPackage and make sure its PkgPath matches that of gnolang.IsRealmPath.

Thanks!

@Villaquiranm Villaquiranm force-pushed the 2192-banker-instance branch 2 times, most recently from 4fc990d to e7ade2c Compare May 31, 2024 19:17
@Villaquiranm
Copy link
Contributor Author

This will not work in a real life scenario, as CurrentRealm() skips frames of pure packages. (If you want a good side-task, change NewCodeRealm to work only with PkgPath's that match the rules of gnolang.IsRealmPath)

I suggest:

  • Having a function like assertCallerIsRealm.
  • This should get the frame of the function where this is called (I think m.Frames[m.NumFrames()-2]).
  • Then call LastPackage and make sure its PkgPath matches that of gnolang.IsRealmPath.

Thanks!

Hello thanks a lot for your review and for the great guidance :)
I hope I got the general idea of what you wanted me to do, I got a few questions though

  • I put this code on assertCallerIsRealm function should I make some extra verifications ? I don't really know why m.NumFrames()-2.
frame := m.Frames[m.NumFrames()-2]
if !frame.LastPackage.IsRealm() {
	m.Panic(typedString("caller is not a realm"))
}
  • When you said a side task for NewCodeRealm this is what you meant ? It is okay to add another function on sdt tests ?
    e7ade2c

@Villaquiranm Villaquiranm force-pushed the 2192-banker-instance branch 3 times, most recently from 746e3ba to fb3e1f8 Compare July 1, 2024 20:17
@Kouteki Kouteki added review/triage-pending PRs opened by external contributors that are waiting for the 1st review and removed review/triage-pending PRs opened by external contributors that are waiting for the 1st review labels Oct 3, 2024
Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

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

Okay, generally looks good.

To justify why len(m.Frames)-2, I suggest you dump the machine in the point you use it (in the native function), just for your own reference. len(frames)-1 will be the frame of assertCallerIsRealm, len(frames)-2 is the frame of its caller, ie. GetBanker. We can then use LastPackage to determine which package called it.

gnovm/stdlibs/std/native.go Outdated Show resolved Hide resolved
@Villaquiranm Villaquiranm requested review from a team as code owners October 23, 2024 19:13
@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Oct 23, 2024
@thehowl
Copy link
Member

thehowl commented Oct 23, 2024

Apologies, revert the changes in tests/files/extern and remove that dir from the fmt rule.

gno fmt doesn't understand the imports in that dir and it shouldn't, so let's just skip it.

@Villaquiranm
Copy link
Contributor Author

Apologies, revert the changes in tests/files/extern and remove that dir from the fmt rule.

gno fmt doesn't understand the imports in that dir and it shouldn't, so let's just skip it.

No worries :)
fixed on 53369df

@thehowl thehowl merged commit 520195e into gnolang:master Oct 23, 2024
117 of 118 checks passed
@omarsy omarsy deleted the 2192-banker-instance branch October 25, 2024 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related 🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants