Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
0705d14
feat(iota-protocol-config): bump version to 4
miker83z Feb 3, 2025
6886b6d
feat(docs/random): update docs realted to randomness (#5388)
Dkwcs Feb 13, 2025
8ac75d6
feat(iota-framework/move-stdlib): Deprecated `fixed_point32` (#5193)
Dkwcs Feb 14, 2025
b5fdf89
fix(iota-framework/packages): optimizes some calls to `is_empty` in l…
Dkwcs Feb 14, 2025
06e3774
updating manifest
Dkwcs Feb 14, 2025
c22a9eb
Merge remote-tracking branch 'origin/vm-lang/upstream-nov-dic-24' int…
Dkwcs Feb 14, 2025
04b2e13
updating manifest
Dkwcs Feb 14, 2025
8272137
Merge branch 'develop' into vm-lang/upstream-nov-dic-24
miker83z Feb 14, 2025
4a851b7
feat(iota-protocol-config): bump version to 5
miker83z Feb 14, 2025
655f062
update framework snapshot
miker83z Feb 14, 2025
1fa0ab1
Update docs
Dkwcs Feb 14, 2025
cae7c65
Merge remote-tracking branch 'origin/vm-lang/upstream-nov-dic-24' int…
Dkwcs Feb 14, 2025
c84dfe8
manifest
Dkwcs Feb 14, 2025
7555360
tests update
Dkwcs Feb 15, 2025
c56bcff
test fix
Dkwcs Feb 15, 2025
2e24f9f
update snapshots
Dkwcs Feb 15, 2025
795636c
snapshot update
Dkwcs Feb 15, 2025
29998cc
snapshot update
Dkwcs Feb 15, 2025
176882a
Update simtest
Dkwcs Feb 16, 2025
191525f
remove snapshots
Dkwcs Feb 16, 2025
11ab407
check simtests
Dkwcs Feb 16, 2025
286680a
simtest fix
Dkwcs Feb 16, 2025
9429298
Fix review commnets
Dkwcs Feb 17, 2025
addbeac
revert external crates changes
Dkwcs Feb 17, 2025
9e5b44e
docs fix
Dkwcs Feb 17, 2025
95dee15
Merge remote-tracking branch 'origin/vm-lang/upstream-nov-dic-24' int…
Dkwcs Feb 18, 2025
9cfaa61
manifest
Dkwcs Feb 18, 2025
d1eb498
fix
Dkwcs Feb 18, 2025
7cbf8e1
fix simtest
Dkwcs Feb 18, 2025
5f477ed
revert snapshot changes
Dkwcs Feb 18, 2025
06951db
Merge remote-tracking branch 'origin/vm-lang/upstream-nov-dic-24' int…
Dkwcs Feb 18, 2025
7f98c02
Merge branch 'vm-lang/upstream-nov-dic-24' into vm-lang/Update-some-c…
miker83z Feb 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ task 1, lines 10-23:
//# publish
created: object(1,0)
mutated: object(0,2)
gas summary: computation_cost: 1000000, computation_cost_burned: 1000000, storage_cost: 5684800, storage_rebate: 0, non_refundable_storage_fee: 0
gas summary: computation_cost: 1000000, computation_cost_burned: 1000000, storage_cost: 5570800, storage_rebate: 0, non_refundable_storage_fee: 0

task 2, lines 25-29:
//# programmable --sender A --inputs 100000 @A
Expand Down
3 changes: 1 addition & 2 deletions crates/iota-benchmark/tests/simtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,7 @@ mod test {
}

async fn test_protocol_upgrade_compatibility_impl() {
// TODO: Remove the `+ 1` after we have Protocol version 2
let max_ver = ProtocolVersion::MAX.as_u64() + 1;
let max_ver = ProtocolVersion::MAX.as_u64();
let manifest = iota_framework_snapshot::load_bytecode_snapshot_manifest();

let Some((&starting_version, _)) = manifest.range(..max_ver).last() else {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions crates/iota-framework-snapshot/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,15 @@
"0x000000000000000000000000000000000000000000000000000000000000000b",
"0x000000000000000000000000000000000000000000000000000000000000107a"
]
},
"5": {
"git_revision": "cae7c6561f3c",
"package_ids": [
"0x0000000000000000000000000000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000000000000000000000000000002",
"0x0000000000000000000000000000000000000000000000000000000000000003",
"0x000000000000000000000000000000000000000000000000000000000000000b",
"0x000000000000000000000000000000000000000000000000000000000000107a"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ module iota::random {
}

/// Create a generator. Can be used to derive up to MAX_U16 * 32 random bytes.
///
/// Using randomness can be error-prone if you don't observe the subtleties in its correct use, for example, randomness
/// dependent code might be exploitable to attacks that carefully set the gas budget
/// in a way that breaks security. For more information, see:
/// https://docs.iota.org/developer/advanced/onchain-randomness
public fun new_generator(r: &Random, ctx: &mut TxContext): RandomGenerator {
let inner = load_inner(r);
let seed = hmac_sha3_256(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module iota::vec_map {

/// Pop the most recently inserted entry from the map. Aborts if the map is empty.
public fun pop<K: copy, V>(self: &mut VecMap<K,V>): (K, V) {
assert!(!self.contents.is_empty(), EMapEmpty);
assert!(self.contents.length() != 0, EMapEmpty);
let Entry { key, value } = self.contents.pop_back();
(key, value)
}
Expand Down Expand Up @@ -148,7 +148,7 @@ module iota::vec_map {
keys.reverse();
values.reverse();
let mut map = empty();
while (!keys.is_empty()) map.insert(keys.pop_back(), values.pop_back());
while (keys.length() != 0) map.insert(keys.pop_back(), values.pop_back());
keys.destroy_empty();
values.destroy_empty();
map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module iota::vec_set {
public fun from_keys<K: copy + drop>(mut keys: vector<K>): VecSet<K> {
keys.reverse();
let mut set = empty();
while (!keys.is_empty()) set.insert(keys.pop_back());
while (keys.length() != 0) set.insert(keys.pop_back());
set
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ module iota_system::voting_power {

/// Update validators with the decided voting power.
fun update_voting_power(validators: &mut vector<ValidatorV1>, mut info_list: vector<VotingPowerInfoV1>) {
while (!info_list.is_empty()) {
while (info_list.length() != 0) {
let VotingPowerInfoV1 {
validator_index,
voting_power,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/// Defines a fixed-point numeric type with a 32-bit integer part and
/// a 32-bit fractional part.

#[deprecated(note = b"Use `std::uq32_32` instead. If you need to convert from a `FixedPoint32` to a `UQ32_32`, you can use the `std::fixed_point32::get_raw_value` with `std::uq32_32::from_raw_value`.")]
module std::fixed_point32 {

/// Define a fixed-point numeric type with 32 fractional bits.
Expand Down
5 changes: 5 additions & 0 deletions crates/iota-framework/packages/move-stdlib/sources/u32.move
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,9 @@ module std::u32 {
public macro fun do_eq($stop: u32, $f: |u32|) {
std::macros::do_eq!($stop, $f)
}

/// Maximum value for a `u32`
public macro fun max_value(): u32 {
0xFFFF_FFFF
}
}
5 changes: 5 additions & 0 deletions crates/iota-framework/packages/move-stdlib/sources/u64.move
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,9 @@ module std::u64 {
public macro fun do_eq($stop: u64, $f: |u64|) {
std::macros::do_eq!($stop, $f)
}

/// Maximum value for a `u64`
public macro fun max_value(): u64 {
0xFFFF_FFFF_FFFF_FFFF
}
}
158 changes: 158 additions & 0 deletions crates/iota-framework/packages/move-stdlib/sources/uq32_32.move
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module std::vector {
/// Pushes all of the elements of the `other` vector into the `lhs` vector.
public fun append<Element>(lhs: &mut vector<Element>, mut other: vector<Element>) {
other.reverse();
while (!other.is_empty()) lhs.push_back(other.pop_back());
while (other.length() != 0) lhs.push_back(other.pop_back());
other.destroy_empty();
}

Expand Down Expand Up @@ -153,7 +153,7 @@ module std::vector {
/// This is O(1), but does not preserve ordering of elements in the vector.
/// Aborts if `i` is out of bounds.
public fun swap_remove<Element>(v: &mut vector<Element>, i: u64): Element {
assert!(!v.is_empty(), EINDEX_OUT_OF_BOUNDS);
assert!(v.length() != 0, EINDEX_OUT_OF_BOUNDS);
let last_idx = v.length() - 1;
v.swap(i, last_idx);
v.pop_back()
Expand All @@ -173,7 +173,7 @@ module std::vector {
/// Does not preserve the order of elements in the vector (starts from the end of the vector).
public macro fun destroy<$T>($v: vector<$T>, $f: |$T|) {
let mut v = $v;
while (!v.is_empty()) $f(v.pop_back());
while (v.length() != 0) $f(v.pop_back());
v.destroy_empty();
}

Expand All @@ -182,7 +182,7 @@ module std::vector {
public macro fun do<$T>($v: vector<$T>, $f: |$T|) {
let mut v = $v;
v.reverse();
while (!v.is_empty()) $f(v.pop_back());
while (v.length() != 0) $f(v.pop_back());
v.destroy_empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#[test_only]
#[test_only, allow(deprecated_usage)]
module std::fixed_point32_tests {
use std::fixed_point32;

Expand Down
Loading
Loading