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

Type safety bugfixes #3934

Merged
merged 8 commits into from
Dec 18, 2023
Merged

Type safety bugfixes #3934

merged 8 commits into from
Dec 18, 2023

Conversation

lehins
Copy link
Contributor

@lehins lehins commented Dec 15, 2023

Description

#3893 exported a bunch of constructors that it shouldn't have

This PR fixes that.

Besides that there are two more fixes:

  • Enum instance for Version was dangerous, since it was derived from the underlying Word64
  • decodeVMap did not enforce no duplicate. Which is safe to fix without a hard fork, because that type is not used for the on-chain data

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated
  • When applicable, versions are updated in .cabal and CHANGELOG.md files according to the
    versioning process.
  • The version bounds in .cabal files for all affected packages are updated. If you change the bounds in a cabal file, that package itself must have a version increase. (See RELEASING.md)
  • All visible changes are prepended to the latest section of a CHANGELOG.md for the affected packages. New section is never added with the code changes. (See RELEASING.md)
  • Code is formatted with fourmolu (use scripts/fourmolize.sh)
  • Cabal files are formatted (use scripts/cabal-format.sh)
  • hie.yaml has been updated (use scripts/gen-hie.sh)
  • Self-reviewed the diff

@lehins lehins force-pushed the lehins/safety-bugfixes branch 3 times, most recently from 7796d19 to 8d20337 Compare December 18, 2023 02:56
Copy link
Contributor

@teodanciu teodanciu left a comment

Choose a reason for hiding this comment

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

Looks good to me

* `decodeVMap` previously mistakenly allowed duplicates, because it used
  pre-Conway semantics for decoding Maps. It is safe to switch it
  without a protocol version bump, because `VMap` is currently not used for
  any type that is stored on-chain. We only use it for some of the
  fields in the ledger state, which is guaranteed to not have duplicates
* Switch from checking membership of elemens in the data structure,
  which can be at the very least O(log n) complexity to checking the
  size of the final data structure and comparing to the number of
  elements that was decoded. If there were duplicates the size will not
  match the number of elements that was decoded
* Improve performance of `Set` and `Map` decoding
Fix a bug introduced in #3893
Fix a bug introduced in #3893
@lehins lehins merged commit 3e0dab4 into master Dec 18, 2023
10 of 27 checks passed
-- `Map`, where keys are hashes of the values encoded on the wire. The final size of the
-- data strucutre taht isreturned will be used to enforce the invariant of a Set, that
-- the number of elements decoded matches the final size of the Set, thus ensuring no
-- duplicates were encountered.
Copy link
Contributor

Choose a reason for hiding this comment

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

That's an awesome explanation, thank you!

@neilmayhew neilmayhew deleted the lehins/safety-bugfixes branch March 8, 2024 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants