Skip to content

Commit

Permalink
[crypto+move] added support for SHA2-512, SHA3-512 and RIPEMD-160 in …
Browse files Browse the repository at this point in the history
…Move (#4181)

* [crypto+move] added support for SHA2-512, SHA3-512 and RIPEMD-160 in Move
  • Loading branch information
alinush authored Nov 1, 2022
1 parent 7117d12 commit ba0d5dc
Show file tree
Hide file tree
Showing 13 changed files with 642 additions and 10 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/aptos-move/framework/aptos-framework/sources/account.move @alinush
/aptos-move/framework/aptos-stdlib/sources/cryptography/ @alinush
/aptos-move/framework/**/*.spec.move @junkil-park
/aptos-move/framework/aptos-stdlib/sources/hash.move @alinush

# Owner for aptos-token, cryptography natives, parallel-executor and vm-genesis.
/aptos-move/framework/aptos-token @areshand
Expand Down
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions aptos-move/aptos-gas/src/aptos_framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ crate::natives::define_gas_parameters_for_natives!(GasParameters, "aptos_framewo
// TODO(Gas): the on-chain name is wrong...
[.type_info.type_name.per_byte_in_str, "type_info.type_name.per_abstract_memory_unit", 5 * MUL],

// Reusing SHA2-512's cost from Ristretto
[.hash.sha2_512.base, optional "hash.sha2_512.base", 3_240],
[.hash.sha2_512.per_byte, optional "hash.sha2_512.per_byte", 60],
// Back-of-the-envelop approximation from SHA3-256's (4000 base, 45 per-byte) costs
[.hash.sha3_512.base, optional "hash.sha3_512.base", 4_500],
[.hash.sha3_512.per_byte, optional "hash.sha3_512.per_byte", 50],
// Using SHA2-256's cost
[.hash.ripemd160.base, optional "hash.ripemd160.base", 3000],
[.hash.ripemd160.per_byte, optional "hash.ripemd160.per_byte", 50],

[.util.from_bytes.base, "util.from_bytes.base", 300 * MUL],
[.util.from_bytes.per_byte, "util.from_bytes.per_byte", 5 * MUL],

Expand Down
2 changes: 1 addition & 1 deletion aptos-move/aptos-gas/src/gas_meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use std::collections::BTreeMap;
// global operations.
// - V1
// - TBA
pub const LATEST_GAS_FEATURE_VERSION: u64 = 3;
pub const LATEST_GAS_FEATURE_VERSION: u64 = 4;

pub(crate) const EXECUTION_GAS_MULTIPLIER: u64 = 20;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ module std::features {
is_enabled(TREAT_FRIEND_AS_PRIVATE)
}

/// Whether the new SHA2-512, SHA3-512 and RIPEMD-160 hash function natives are enabled.
/// This is needed because of the introduction of new native functions.
/// Lifetime: transient
const SHA_512_AND_RIPEMD_160_NATIVES: u64 = 3;

public fun get_sha_512_and_ripemd_160_feature(): u64 { SHA_512_AND_RIPEMD_160_NATIVES }

public fun sha_512_and_ripemd_160_enabled(): bool acquires Features {
is_enabled(SHA_512_AND_RIPEMD_160_NATIVES)
}

// ============================================================================================
// Feature Flag Implementation

Expand Down
2 changes: 2 additions & 0 deletions aptos-move/framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ once_cell = "1.10.0"
proptest = { version = "1.0.0", optional = true }
proptest-derive = { version = "0.3.0", optional = true }
rayon = "1.5.2"
ripemd = "0.1.1"
serde = { version = "1.0.137", default-features = false }
serde_bytes = "0.11.6"
serde_json = "1.0.81"
serde_yaml = "0.8.24"
sha2 = "0.9.3"
sha3 = "0.9.1"
siphasher = "0.3.10"
smallvec = "1.8.0"
tempfile = "3.3.0"
Expand Down
Loading

0 comments on commit ba0d5dc

Please sign in to comment.