-
Notifications
You must be signed in to change notification settings - Fork 58
fix(iota-framework/move-stdlib,crypto): Assertions for groth16 public inputs parser, snapshot regenerating #5432
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
Merged
Dkwcs
merged 19 commits into
vm-lang/upstream-nov-dic-24
from
vm-lang/Assertions-for-groth16-public-inputs-parser
Feb 20, 2025
Merged
Changes from 10 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0705d14
feat(iota-protocol-config): bump version to 4
miker83z 6886b6d
feat(docs/random): update docs realted to randomness (#5388)
Dkwcs 8ac75d6
feat(iota-framework/move-stdlib): Deprecated `fixed_point32` (#5193)
Dkwcs 8272137
Merge branch 'develop' into vm-lang/upstream-nov-dic-24
miker83z 4a851b7
feat(iota-protocol-config): bump version to 5
miker83z 655f062
update framework snapshot
miker83z 9aa26f0
fix(iota-framework/move-stdlib,crypto): Assertions for groth16 public…
Dkwcs b01cdc2
manifest
Dkwcs 6ce0260
Fix review comment
Dkwcs fab483a
review comment fix
Dkwcs 758030b
Update docs/content/developer/advanced/onchain-randomness.mdx
Dkwcs cd93425
Update docs/content/developer/advanced/onchain-randomness.mdx
Dkwcs e90ce75
Update docs/content/developer/advanced/onchain-randomness.mdx
Dkwcs 4d1815d
Merge branch 'vm-lang/upstream-nov-dic-24' into vm-lang/Assertions-fo…
miker83z 4d66f81
revert snapshot v4 changes
miker83z 6670516
revert max allowed protocol version change
miker83z 51d9741
fix review comment
Dkwcs 6bc79ba
Merge remote-tracking branch 'origin/vm-lang/upstream-nov-dic-24' int…
Dkwcs c2a31a2
manifest update
Dkwcs 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
Binary file modified
BIN
+1.22 KB
(110%)
...ot/bytecode_snapshot/4/0x0000000000000000000000000000000000000000000000000000000000000001
Binary file not shown.
Binary file modified
BIN
+5 Bytes
(100%)
...ot/bytecode_snapshot/4/0x0000000000000000000000000000000000000000000000000000000000000002
Binary file not shown.
Binary file modified
BIN
-6 Bytes
(100%)
...ot/bytecode_snapshot/4/0x0000000000000000000000000000000000000000000000000000000000000003
Binary file not shown.
Binary file modified
BIN
+22 Bytes
(100%)
...ot/bytecode_snapshot/4/0x000000000000000000000000000000000000000000000000000000000000000b
Binary file not shown.
Binary file added
BIN
+12.2 KB
...ot/bytecode_snapshot/5/0x0000000000000000000000000000000000000000000000000000000000000001
Binary file not shown.
Binary file added
BIN
+68.7 KB
...ot/bytecode_snapshot/5/0x0000000000000000000000000000000000000000000000000000000000000002
Binary file not shown.
Binary file added
BIN
+41.3 KB
...ot/bytecode_snapshot/5/0x0000000000000000000000000000000000000000000000000000000000000003
Binary file not shown.
Binary file added
BIN
+19.4 KB
...ot/bytecode_snapshot/5/0x000000000000000000000000000000000000000000000000000000000000000b
Binary file not shown.
Binary file added
BIN
+8.64 KB
...ot/bytecode_snapshot/5/0x000000000000000000000000000000000000000000000000000000000000107a
Binary file not shown.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
158 changes: 158 additions & 0 deletions
158
crates/iota-framework/packages/move-stdlib/sources/uq32_32.move
This file contains hidden or 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,158 @@ | ||
| // Copyright (c) Mysten Labs, Inc. | ||
| // Modifications Copyright (c) 2024 IOTA Stiftung | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| /// Defines an unsigned, fixed-point numeric type with a 32-bit integer part and a 32-bit fractional | ||
| /// part. The notation `uq32_32` and `UQ32_32` is based on | ||
| /// [Q notation](https://en.wikipedia.org/wiki/Q_(number_format)). `q` indicates it a fixed-point | ||
| /// number. The `u` prefix indicates it is unsigned. The `32_32` suffix indicates the number of | ||
| /// bits, where the first number indicates the number of bits in the integer part, and the second | ||
| /// the number of bits in the fractional part--in this case 32 bits for each. | ||
| module std::uq32_32; | ||
|
|
||
| #[error] | ||
| const EDenominator: vector<u8> = b"Quotient specified with a zero denominator"; | ||
|
|
||
| #[error] | ||
| const EQuotientTooSmall: vector<u8> = | ||
| b"Quotient specified is too small, and is outside of the supported range"; | ||
|
|
||
| #[error] | ||
| const EQuotientTooLarge: vector<u8> = | ||
| b"Quotient specified is too large, and is outside of the supported range"; | ||
|
|
||
| #[error] | ||
| const EOverflow: vector<u8> = b"Overflow from an arithmetic operation"; | ||
|
|
||
| #[error] | ||
| const EDivisionByZero: vector<u8> = b"Division by zero"; | ||
|
|
||
| /// A fixed-point numeric type with 32 integer bits and 32 fractional bits, represented by an | ||
| /// underlying 64 bit value. This is a binary representation, so decimal values may not be exactly | ||
| /// representable, but it provides more than 9 decimal digits of precision both before and after the | ||
| /// decimal point (18 digits total). | ||
| public struct UQ32_32(u64) has copy, drop, store; | ||
|
|
||
| /// Create a fixed-point value from a quotient specified by its numerator and denominator. | ||
| /// `from_quotient` and `from_int` should be preferred over using `from_raw`. | ||
| /// Unless the denominator is a power of two, fractions can not be represented accurately, | ||
| /// so be careful about rounding errors. | ||
| /// Aborts if the denominator is zero. | ||
| /// Aborts if the input is non-zero but so small that it will be represented as zero, e.g. smaller | ||
| /// than 2^{-32}. | ||
| /// Aborts if the input is too large, e.g. larger than or equal to 2^32. | ||
| public fun from_quotient(numerator: u64, denominator: u64): UQ32_32 { | ||
| assert!(denominator != 0, EDenominator); | ||
| // Scale the numerator to have 64 fractional bits and the denominator to have 32 fractional | ||
| // bits, so that the quotient will have 32 fractional bits. | ||
| let scaled_numerator = numerator as u128 << 64; | ||
| let scaled_denominator = denominator as u128 << 32; | ||
| let quotient = scaled_numerator / scaled_denominator; | ||
| // The quotient can only be zero if the numerator is also zero. | ||
| assert!(quotient != 0 || numerator == 0, EQuotientTooSmall); | ||
| // Return the quotient as a fixed-point number. We first need to check whether the cast | ||
| // can succeed. | ||
| assert!(quotient <= std::u64::max_value!() as u128, EQuotientTooLarge); | ||
| UQ32_32(quotient as u64) | ||
| } | ||
|
|
||
| /// Create a fixed-point value from an integer. | ||
| /// `from_int` and `from_quotient` should be preferred over using `from_raw`. | ||
| public fun from_int(integer: u32): UQ32_32 { | ||
| UQ32_32((integer as u64) << 32) | ||
| } | ||
|
|
||
| /// Add two fixed-point numbers, `a + b`. | ||
| /// Aborts if the sum overflows. | ||
| public fun add(a: UQ32_32, b: UQ32_32): UQ32_32 { | ||
| let sum = a.0 as u128 + (b.0 as u128); | ||
| assert!(sum <= std::u64::max_value!() as u128, EOverflow); | ||
| UQ32_32(sum as u64) | ||
| } | ||
|
|
||
| /// Subtract two fixed-point numbers, `a - b`. | ||
| /// Aborts if `a < b`. | ||
| public fun sub(a: UQ32_32, b: UQ32_32): UQ32_32 { | ||
| assert!(a.0 >= b.0, EOverflow); | ||
| UQ32_32(a.0 - b.0) | ||
| } | ||
|
|
||
| /// Multiply two fixed-point numbers, truncating any fractional part of the product. | ||
| /// Aborts if the product overflows. | ||
| public fun mul(a: UQ32_32, b: UQ32_32): UQ32_32 { | ||
| UQ32_32(int_mul(a.0, b)) | ||
| } | ||
|
|
||
| /// Divide two fixed-point numbers, truncating any fractional part of the quotient. | ||
| /// Aborts if the divisor is zero. | ||
| /// Aborts if the quotient overflows. | ||
| public fun div(a: UQ32_32, b: UQ32_32): UQ32_32 { | ||
| UQ32_32(int_div(a.0, b)) | ||
| } | ||
|
|
||
| /// Convert a fixed-point number to an integer, truncating any fractional part. | ||
| public fun to_int(a: UQ32_32): u32 { | ||
| (a.0 >> 32) as u32 | ||
| } | ||
|
|
||
| /// Multiply a `u64` integer by a fixed-point number, truncating any fractional part of the product. | ||
| /// Aborts if the product overflows. | ||
| public fun int_mul(val: u64, multiplier: UQ32_32): u64 { | ||
| // The product of two 64 bit values has 128 bits, so perform the | ||
| // multiplication with u128 types and keep the full 128 bit product | ||
| // to avoid losing accuracy. | ||
| let unscaled_product = val as u128 * (multiplier.0 as u128); | ||
| // The unscaled product has 32 fractional bits (from the multiplier) | ||
| // so rescale it by shifting away the low bits. | ||
| let product = unscaled_product >> 32; | ||
| // Check whether the value is too large. | ||
| assert!(product <= std::u64::max_value!() as u128, EOverflow); | ||
| product as u64 | ||
| } | ||
|
|
||
| /// Divide a `u64` integer by a fixed-point number, truncating any fractional part of the quotient. | ||
| /// Aborts if the divisor is zero. | ||
| /// Aborts if the quotient overflows. | ||
| public fun int_div(val: u64, divisor: UQ32_32): u64 { | ||
| // Check for division by zero. | ||
| assert!(divisor.0 != 0, EDivisionByZero); | ||
| // First convert to 128 bits and then shift left to | ||
| // add 32 fractional zero bits to the dividend. | ||
| let scaled_value = val as u128 << 32; | ||
| let quotient = scaled_value / (divisor.0 as u128); | ||
| // Check whether the value is too large. | ||
| assert!(quotient <= std::u64::max_value!() as u128, EOverflow); | ||
| quotient as u64 | ||
| } | ||
|
|
||
| /// Less than or equal to. Returns `true` if and only if `a <= a`. | ||
| public fun le(a: UQ32_32, b: UQ32_32): bool { | ||
| a.0 <= b.0 | ||
| } | ||
|
|
||
| /// Less than. Returns `true` if and only if `a < b`. | ||
| public fun lt(a: UQ32_32, b: UQ32_32): bool { | ||
| a.0 < b.0 | ||
| } | ||
|
|
||
| /// Greater than or equal to. Returns `true` if and only if `a >= b`. | ||
| public fun ge(a: UQ32_32, b: UQ32_32): bool { | ||
| a.0 >= b.0 | ||
| } | ||
|
|
||
| /// Greater than. Returns `true` if and only if `a > b`. | ||
| public fun gt(a: UQ32_32, b: UQ32_32): bool { | ||
| a.0 > b.0 | ||
| } | ||
|
|
||
| /// Accessor for the raw u64 value. Can be paired with `from_raw` to perform less common operations | ||
| /// on the raw values directly. | ||
| public fun to_raw(a: UQ32_32): u64 { | ||
| a.0 | ||
| } | ||
|
|
||
| /// Accessor for the raw u64 value. Can be paired with `to_raw` to perform less common operations | ||
| /// on the raw values directly. | ||
| public fun from_raw(raw_value: u64): UQ32_32 { | ||
| UQ32_32(raw_value) | ||
| } |
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.