-
Notifications
You must be signed in to change notification settings - Fork 214
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-normalized Value
s can get to the ScriptContext
when in the emulator
#671
Comments
You can find a more in-depth discussion on the list of invariants ensured by the ledger and/or serialization rules here. The bottom line is that these aren't very straight-forward, and you'll likely need to be intimately familiar with the spec and CDDL to get a full understanding. Adding more documentation was discussed here.
The it is up to developers to ensure the invariants both exist and are upheld when building up values (and I mean this in the " However:
If you would like to avoid these pitfalls, utilities you may find helpful are:
On another note, if you're working with -- unsorted association list: "ddef" currency symbol comes first
ghci> unsorted
Map {unMap = [("ddef",Map {unMap = [("",1)]}),("abcd",Map {unMap = [("",1)]})]}
-- printed as a map, "abcd" comes first
ghci> Value unsorted
Value (Map [(abcd,Map [("",1)]),(ddef,Map [("",1)])])
-- round-tripping shows its still unsorted
ghci> getValue $ Value unsorted
Map {unMap = [(ddef,Map {unMap = [("",1)]}),(abcd,Map {unMap = [("",1)]})]} |
Thanks for the answer @peter-mlabs! I believe that the efforts and discussions you linked are paramount for the Plutus ecosystem! I'm no longer involved with Plutus, however. I'll tag @mmontin here, who will probably benefit from this information! |
Summary
IIUC, the
cardano
ledger usesData.Map
for values, hence, all the values in aScriptContext
are sorted and normalized by the time the validator gets them. It seems like the emulator doesn't perform this normalization/sorting and some library functions will actively generate "bad" values. One such example isadjustUnbalancedTx
, which usesadjustTxOut
, which in turn might return atxOut { txOutValue = txOutValue txOut <> Ada.toValue missingLovelace }
. Note how themissingLovelace
is added at the tail of the value, where it should have been added at the head or the values should be sorted to conform to how the ledger creates script contexts.This is related to:
plutus-apps
andcardano-ledger
on handling values. #604Steps to reproduce the behavior
Value
is sorted; that script is equivalent toconst True
in the actual chain.adjustUnbalancedTx
and submit it through the emulator, said script will now fail to validate.Actual Result
see above
Expected Result
The validator shouldn't be able to distinguish if it is running from the emulator or from the ledger.
Describe the approach you would take to fix this
At this point, it would be good to have a concrete list of assumptions on the invariants that the different datatypes defined by
plutus-apps
need to respect and how these should be enforced. Is it up to us to sort these off-chain? Which of those invariantsare actually a specification? Is the validator even supposed to assume that values are sorted?
System info
n/a
The text was updated successfully, but these errors were encountered: