Skip to content

Commit

Permalink
move to move-stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-aptos committed Sep 26, 2024
1 parent 1d949f1 commit a2a930b
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,5 @@ crate::gas_schedule::macros::define_gas_parameters!(
[object_exists_at_per_item_loaded: InternalGas, { 7.. => "object.exists_at.per_item_loaded" }, 1470],
[string_utils_base: InternalGas, { 8.. => "string_utils.format.base" }, 1102],
[string_utils_per_byte: InternalGasPerByte, { 8.. =>"string_utils.format.per_byte" }, 3],

[cmp_compare_base: InternalGas, "cmp.base", 367],
[cmp_compare_per_abs_val_unit: InternalGasPerAbstractValueUnit, "cmp.per_abs_val_unit", 14],
]
);
10 changes: 8 additions & 2 deletions aptos-move/aptos-gas-schedule/src/gas_schedule/move_stdlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

//! This module defines the gas parameters for Move Stdlib.

use crate::{gas_feature_versions::RELEASE_V1_18, gas_schedule::NativeGasParameters};
use aptos_gas_algebra::{InternalGas, InternalGasPerByte};
use crate::{
gas_feature_versions::{RELEASE_V1_18, RELEASE_V1_21},
gas_schedule::NativeGasParameters,
};
use aptos_gas_algebra::{InternalGas, InternalGasPerAbstractValueUnit, InternalGasPerByte};

crate::gas_schedule::macros::define_gas_parameters!(
MoveStdlibGasParameters,
Expand Down Expand Up @@ -36,5 +39,8 @@ crate::gas_schedule::macros::define_gas_parameters!(
[bcs_serialized_size_base: InternalGas, { RELEASE_V1_18.. => "bcs.serialized_size.base" }, 735],
[bcs_serialized_size_per_byte_serialized: InternalGasPerByte, { RELEASE_V1_18.. => "bcs.serialized_size.per_byte_serialized" }, 36],
[bcs_serialized_size_failure: InternalGas, { RELEASE_V1_18.. => "bcs.serialized_size.failure" }, 3676],

[cmp_compare_base: InternalGas, { RELEASE_V1_21.. => "cmp.base" }, 367],
[cmp_compare_per_abs_val_unit: InternalGasPerAbstractValueUnit, { RELEASE_V1_21.. => "cmp.per_abs_val_unit"}, 14],
]
);
1 change: 0 additions & 1 deletion aptos-move/framework/aptos-stdlib/doc/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ This is the reference documentation of the Aptos standard library.
- [`0x1::bls12381_algebra`](bls12381_algebra.md#0x1_bls12381_algebra)
- [`0x1::bn254_algebra`](bn254_algebra.md#0x1_bn254_algebra)
- [`0x1::capability`](capability.md#0x1_capability)
- [`0x1::cmp`](cmp.md#0x1_cmp)
- [`0x1::comparator`](comparator.md#0x1_comparator)
- [`0x1::copyable_any`](copyable_any.md#0x1_copyable_any)
- [`0x1::crypto_algebra`](crypto_algebra.md#0x1_crypto_algebra)
Expand Down
74 changes: 62 additions & 12 deletions aptos-move/framework/move-stdlib/doc/cmp.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
- [Function `compare_impl`](#0x1_cmp_compare_impl)
- [Function `compare`](#0x1_cmp_compare)
- [Function `is_equal`](#0x1_cmp_is_equal)
- [Function `is_less_then`](#0x1_cmp_is_less_then)
- [Function `is_less_than`](#0x1_cmp_is_less_than)
- [Function `is_less_or_equal`](#0x1_cmp_is_less_or_equal)
- [Function `is_greater_than`](#0x1_cmp_is_greater_than)
- [Function `is__greater_or_equal`](#0x1_cmp_is__greater_or_equal)


<pre><code></code></pre>
Expand Down Expand Up @@ -136,7 +138,7 @@ An int value:



<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_equal">is_equal</a>(ordering: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool
<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_equal">is_equal</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool
</code></pre>


Expand All @@ -145,22 +147,22 @@ An int value:
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_equal">is_equal</a>(ordering: &<a href="cmp.md#0x1_cmp_Ordering">Ordering</a>): bool {
ordering.value == <a href="cmp.md#0x1_cmp_EQUAL">EQUAL</a>
<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_equal">is_equal</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">Ordering</a>): bool {
self.value == <a href="cmp.md#0x1_cmp_EQUAL">EQUAL</a>
}
</code></pre>



</details>

<a id="0x1_cmp_is_less_then"></a>
<a id="0x1_cmp_is_less_than"></a>

## Function `is_less_then`
## Function `is_less_than`



<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_less_then">is_less_then</a>(ordering: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool
<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_less_than">is_less_than</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool
</code></pre>


Expand All @@ -169,8 +171,8 @@ An int value:
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_less_then">is_less_then</a>(ordering: &<a href="cmp.md#0x1_cmp_Ordering">Ordering</a>): bool {
ordering.value == <a href="cmp.md#0x1_cmp_LESS_THAN">LESS_THAN</a>
<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_less_than">is_less_than</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">Ordering</a>): bool {
self.value == <a href="cmp.md#0x1_cmp_LESS_THAN">LESS_THAN</a>
}
</code></pre>

Expand All @@ -184,7 +186,7 @@ An int value:



<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_less_or_equal">is_less_or_equal</a>(ordering: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool
<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_less_or_equal">is_less_or_equal</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool
</code></pre>


Expand All @@ -193,8 +195,56 @@ An int value:
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_less_or_equal">is_less_or_equal</a>(ordering: &<a href="cmp.md#0x1_cmp_Ordering">Ordering</a>): bool {
ordering.value != <a href="cmp.md#0x1_cmp_GREATER_THAN">GREATER_THAN</a>
<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_less_or_equal">is_less_or_equal</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">Ordering</a>): bool {
self.value != <a href="cmp.md#0x1_cmp_GREATER_THAN">GREATER_THAN</a>
}
</code></pre>



</details>

<a id="0x1_cmp_is_greater_than"></a>

## Function `is_greater_than`



<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_greater_than">is_greater_than</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_greater_than">is_greater_than</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">Ordering</a>): bool {
self.value == <a href="cmp.md#0x1_cmp_GREATER_THAN">GREATER_THAN</a>
}
</code></pre>



</details>

<a id="0x1_cmp_is__greater_or_equal"></a>

## Function `is__greater_or_equal`



<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is__greater_or_equal">is__greater_or_equal</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is__greater_or_equal">is__greater_or_equal</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">Ordering</a>): bool {
self.value != <a href="cmp.md#0x1_cmp_LESS_THAN">LESS_THAN</a>
}
</code></pre>

Expand Down
1 change: 1 addition & 0 deletions aptos-move/framework/move-stdlib/doc/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ For on overview of the Move language, see the [Move Book][move-book].
- [`0x1::acl`](acl.md#0x1_acl)
- [`0x1::bcs`](bcs.md#0x1_bcs)
- [`0x1::bit_vector`](bit_vector.md#0x1_bit_vector)
- [`0x1::cmp`](cmp.md#0x1_cmp)
- [`0x1::error`](error.md#0x1_error)
- [`0x1::features`](features.md#0x1_features)
- [`0x1::fixed_point32`](fixed_point32.md#0x1_fixed_point32)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

//! Implementation of native functions for utf8 strings.

use aptos_gas_schedule::gas_params::natives::aptos_framework::{CMP_COMPARE_BASE, CMP_COMPARE_PER_ABS_VAL_UNIT};
use aptos_gas_schedule::gas_params::natives::move_stdlib::{
CMP_COMPARE_BASE, CMP_COMPARE_PER_ABS_VAL_UNIT,
};
use aptos_native_interface::{
RawSafeNative, SafeNativeBuilder, SafeNativeContext, SafeNativeError, SafeNativeResult,
};
Expand Down Expand Up @@ -46,9 +48,9 @@ fn native_compare_impl(
}

let cost = CMP_COMPARE_BASE
+ CMP_COMPARE_PER_ABS_VAL_UNIT
* (context.abs_val_size_dereferenced(&args[0])
+ context.abs_val_size_dereferenced(&args[1]));
+ CMP_COMPARE_PER_ABS_VAL_UNIT
* (context.abs_val_size_dereferenced(&args[0])
+ context.abs_val_size_dereferenced(&args[1]));
context.charge(cost)?;

let ordering = args[0].compare(&args[1])?;
Expand Down
2 changes: 2 additions & 0 deletions aptos-move/framework/move-stdlib/src/natives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// SPDX-License-Identifier: Apache-2.0

pub mod bcs;
pub mod cmp;
pub mod hash;
pub mod signer;
pub mod string;
Expand All @@ -32,6 +33,7 @@ pub fn all_natives(

builder.with_incremental_gas_charging(false, |builder| {
add_natives!("bcs", bcs::make_all(builder));
add_natives!("cmp", cmp::make_all(builder));
add_natives!("hash", hash::make_all(builder));
add_natives!("signer", signer::make_all(builder));
add_natives!("string", string::make_all(builder));
Expand Down
2 changes: 0 additions & 2 deletions aptos-move/framework/src/natives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub mod account;
pub mod aggregator_natives;
pub mod code;
pub mod consensus_config;
pub mod cmp;
pub mod create_signer;
pub mod cryptography;
pub mod debug;
Expand Down Expand Up @@ -53,7 +52,6 @@ pub fn all_natives(
}

add_natives_from_module!("account", account::make_all(builder));
add_natives_from_module!("cmp", cmp::make_all(builder));
add_natives_from_module!("create_signer", create_signer::make_all(builder));
add_natives_from_module!("ed25519", ed25519::make_all(builder));
add_natives_from_module!("crypto_algebra", cryptography::algebra::make_all(builder));
Expand Down

0 comments on commit a2a930b

Please sign in to comment.