-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Type-check Simplicity values
Values have two bit encodings: 1) Compact: witness encoding, IMR computation 2) Padded: values on the Bit Machine The code so far used the compact encoding exclusively, which is incorrect for sum values on the Bit Machine. As a fix, this commit introduces the padded encoding. However, a value can only be encoded with padding if its type is known. To this end, this commit refactors the Value struct so it knows its Simplicity type. Adding types to all values instead of "upgrading" a typeless value to a typed value has several benefits: 1) Bit words, products and options get their type for free when they are constructed. The caller doesn't have to supply additional type info. This covers almost all values that we are using in the code. 2) Values cannot be decoded without type info. Type checking happens implicitly during decoding. The decoded value gets its type for free. 3) Values are used as word constants and as witness data. In both cases, we want to check if the supplied value is of the correct type. There is (almost?) no use case for untyped values. The new API exposes two Boolean iterators (iter_compact / iter_padded) instead of do_each_bit. The iterators are more flexible and can be used in conjunction with BitCollector. Most changes in this commit happen inside value.rs. The rest is renamings of Arc<Value> to Value, etc.
- Loading branch information
1 parent
bfca4af
commit c100ca1
Showing
25 changed files
with
396 additions
and
349 deletions.
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
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
Oops, something went wrong.