- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Non-deterministic behavior in two different scenarios #282
Comments
Thanks for this detailed report! Could you please share the output of |
Sure thing!
|
Okay did some internal tests as well. The nondeterminism vanishes when pattern optimization (added in pluthon 0.4.0) is disabled. The reason is likely a topological sort being performed nondeterministically (depending on the currently employed hash function which detemrines the order of iteration through sets. Therefore differences only pop up between invocations of the python executable and not within a single call.). Thank you for your input! |
hi @nielstron I appreciate the speedy fix but it looks like you may have missed a case in the library, I'm not sure, but trying it today, I get the same results. In fact, simplifying the script component: #!opshin
from opshin.prelude import *
def validator(datum: int, redeemer: int, context: ScriptContext) -> None:
purpose = context.purpose
assert isinstance(purpose, Spending), f"Wrong script purpose: {purpose}"
assert (
datum + redeemer == 42
), f"Expected datum and redeemer to sum to 42, but they sum to {datum + redeemer}" loop: #! /usr/bin/bash
for i in `seq 1 100`;
do
echo "run: $i"
echo $(opshin build spending assert_sum.py)
echo $(cat build/assert_sum/testnet.addr)
done output:
for completeness, the deactivation and removal of the environment and then reinstall log:
|
You are right, it seems I missed the isinstance issue. Investigating... Update: It appears that printing of Union type objects is the culprit - I can imagine that there is some unordered-set stuff going on that is invalid |
Keeping this open and delaying another patch version until @ross-spencer had time to look at the latest dev branch version :) |
a bit late with other tasks this morning but I will have a look now @nielstron |
@nielstron nice work! the fix looks great to me, I only ran through the examples above, and a few of the local contracts we've been working on where we first saw the issue, but seeing the same each time. |
Describe the bug
I am seeing non-deterministic behavior in two separate cases with OpShin going back to
0.16.0
.e.g. looping a build on
0.18.0
:To Reproduce
Steps to reproduce the behavior:
In both cases I am using the sample contract here (I accidentally mislabelled it first trying to use a simpler contract):
Helper files and script:
marketplace_fstrings.zip
marketplace_no_fstring.zip
with f-strings
assert_sum.py
, use the contents frommarketplace.py
.Example looping script:
results
without f-strings
I noticed removing f-strings had an impact based on a local contract. Remove them from the
asset_sum.py
, e.g. replacef"{string}"
with"removed"
.Repeat the steps above.
results
Expected behavior
OpShin script output is deterministic.
Desktop (please complete the following information):
Additional context
Two factors that seem to make a difference:
The removal of both, results in deterministic output in
0.18.0
.The text was updated successfully, but these errors were encountered: