-
Notifications
You must be signed in to change notification settings - Fork 391
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
fix(gnovm): change initialization order so realm objects are persisted before referenced by other realms #1861
Closed
Closed
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
e34a322
don't allow max cycle configuration
deelawn 2866d97
Revert "don't allow max cycle configuration"
deelawn 7136f30
Merge remote-tracking branch 'upstream/master'
deelawn e5308d6
save mempkg before running init functions
deelawn 061057f
add new panic message for a particular type of cross realm pointer pe…
deelawn 195b716
update effective gno to define shared pointer behavior
deelawn 8aae41e
added txtar test
deelawn 04b1c86
use exising ownership error message in favor of new one
deelawn e1a974c
added clarifying pointer ownership behavior tests
deelawn 50134dc
Expanded effective gno doc update
deelawn 77032fc
save package mempackage after init
deelawn 5342c67
just check not realm path, not a new const for package path
deelawn 355b8e8
Merge remote-tracking branch 'upstream/master'
deelawn eca217b
Merge remote-tracking branch 'upstream/master'
deelawn 5daacd6
Merge branch 'master' into fix/shared-realm-pointers
deelawn 6085897
reworked solution
deelawn 32f3212
Merge branch 'master' into fix/shared-realm-pointers
deelawn 4e32ad7
save package values again after init
deelawn 1761393
Merge branch 'fix/shared-realm-pointers' of github.com:deelawn/gno in…
deelawn 9f2d744
make sure init functions are run in all contexts
deelawn 5d92536
remove println
deelawn 3609b59
removed duplicate init run
deelawn 4e21d02
correct mempkg execution ordering
deelawn 4c59eb3
fix package creation ordering
deelawn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# This test is meant to exhibit how pointers to unpersisted values cannot be | ||
# persisted as realm variables in other realms. | ||
|
||
loadpkg gno.land/r/steal_ownership $WORK/steal | ||
loadpkg gno.land/r/mis_ownership $WORK/mis | ||
|
||
gnoland start | ||
|
||
! gnokey maketx call -pkgpath gno.land/r/mis_ownership -func SharePtr1 -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stderr 'cannot modify external-realm or non-realm object' | ||
|
||
gnokey maketx call -pkgpath gno.land/r/mis_ownership -func SharePtr2 -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stdout OK! | ||
|
||
! gnokey maketx call -pkgpath gno.land/r/mis_ownership -func Update -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stderr 'cannot modify external-realm or non-realm object' | ||
|
||
gnokey maketx call -pkgpath gno.land/r/mis_ownership -func SharePtr3 -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stdout OK! | ||
|
||
gnokey maketx call -pkgpath gno.land/r/steal_ownership -func Update -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stdout OK! | ||
|
||
gnokey maketx call -pkgpath gno.land/r/steal_ownership -func PtrValue -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stdout '(43 uint32)' | ||
stdout OK! | ||
|
||
-- steal/steal.gno -- | ||
package steal_ownership | ||
|
||
var Ptr *uint32 | ||
|
||
func Steal(xptr *uint32) { | ||
Ptr = xptr | ||
} | ||
|
||
func Update() { | ||
*Ptr = 43 | ||
} | ||
|
||
func PtrValue() uint32 { | ||
return *Ptr | ||
} | ||
|
||
-- mis/mis.gno -- | ||
package mis_ownership | ||
|
||
import "gno.land/r/steal_ownership" | ||
|
||
var y *uint32 | ||
|
||
func SharePtr1() { | ||
x := uint32(42) | ||
y = &x | ||
|
||
// This is not okay because the x value is owned by this realm by way of y, and is | ||
// currently planned to be persisted. | ||
steal_ownership.Steal(&x) | ||
} | ||
|
||
|
||
func SharePtr2() { | ||
x := uint32(42) | ||
steal_ownership.Steal(&x) | ||
|
||
// This is okay because the x value was already persisted and is now owned by the | ||
// steal realm because it was unowned with no plan to persist it at the time. | ||
// However, it is not owned by this realm now so any attempt to modify it will fail. | ||
y = &x | ||
} | ||
|
||
func SharePtr3() { | ||
x := uint32(42) | ||
|
||
// This is okay because the x value is unowned and will not be persisted by this realm. | ||
steal_ownership.Steal(&x) | ||
} | ||
|
||
func Update() { | ||
*y = 43 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Reproducible Test for https://github.com/gnolang/gno/issues/974 | ||
|
||
loadpkg gno.land/r/steal_ownership $WORK/steal | ||
loadpkg gno.land/r/mis_ownership $WORK/mis | ||
|
||
gnoland start | ||
|
||
gnokey maketx call -pkgpath gno.land/r/mis_ownership -func PtrValues -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stdout '(42 uint32)' | ||
stdout '(42 uint32)' | ||
stdout OK! | ||
|
||
gnokey maketx call -pkgpath gno.land/r/mis_ownership -func MutateDeref -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stdout OK! | ||
|
||
gnokey maketx call -pkgpath gno.land/r/mis_ownership -func PtrValues -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stdout '(21 uint32)' | ||
stdout '(21 uint32)' | ||
stdout OK! | ||
|
||
gnokey maketx call -pkgpath gno.land/r/mis_ownership -func MutateValue -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stdout OK! | ||
|
||
gnokey maketx call -pkgpath gno.land/r/mis_ownership -func PtrValues -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stdout '(15 uint32)' | ||
stdout '(15 uint32)' | ||
stdout OK! | ||
|
||
gnokey maketx call -pkgpath gno.land/r/mis_ownership -func MutatePtr -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stdout OK! | ||
|
||
gnokey maketx call -pkgpath gno.land/r/mis_ownership -func PtrValues -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 | ||
stdout '(5 uint32)' | ||
stdout '(15 uint32)' | ||
stdout OK! | ||
|
||
-- steal/steal.gno -- | ||
package steal_ownership | ||
|
||
var Ptr *uint32 | ||
|
||
func Steal(xptr *uint32) { | ||
Ptr = xptr | ||
} | ||
|
||
-- mis/mis.gno -- | ||
package mis_ownership | ||
|
||
import "gno.land/r/steal_ownership" | ||
|
||
var ( | ||
x = uint32(42) | ||
ptr = &x | ||
) | ||
|
||
func init() { | ||
steal_ownership.Steal(ptr) | ||
} | ||
|
||
func MutateDeref() { | ||
*ptr = 21 | ||
} | ||
|
||
func MutatePtr() { | ||
y := uint32(5) | ||
ptr = &y | ||
} | ||
|
||
func MutateValue() { | ||
x = 15 | ||
} | ||
|
||
func PtrValues() (uint32, uint32) { | ||
return *ptr, *steal_ownership.Ptr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
the name is inconsistent with its behavior though...
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.
gut tells me not to add saving logic into runFiles logic, but instead runFiles could return new init functions as []Name, and the caller can save before or after as needed.
I'mstill trying to wrap my head around why it's needed. thinking..