Skip to content

Commit

Permalink
ed25519 test-only natives implementation tweak (aptos-labs#5289)
Browse files Browse the repository at this point in the history
* fix compile error when feature testing is not on

* ensure ed25519 test-only natives is not loaded in production

* make linter happy
  • Loading branch information
zjma authored Oct 26, 2022
1 parent 434f8df commit 5ea5e19
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
9 changes: 5 additions & 4 deletions aptos-move/aptos-vm/src/natives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ pub fn assert_no_test_natives() {
LATEST_GAS_FEATURE_VERSION
)
.into_iter()
.all(
|(_, module_name, func_name, _)| module_name.as_str() != "unit_test"
&& func_name.as_str() != "create_signers_for_testing"
))
.all(|(_, module_name, func_name, _)| {
!(module_name.as_str() == "unit_test" && func_name.as_str() == "create_signers_for_testing"
|| module_name.as_str() == "ed25519" && func_name.as_str() == "generate_keys_internal"
|| module_name.as_str() == "ed25519" && func_name.as_str() == "sign_internal")
}))
}

#[cfg(feature = "testing")]
Expand Down
32 changes: 17 additions & 15 deletions aptos-move/framework/src/natives/cryptography/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ pub struct GasParameters {
}

pub fn make_all(gas_params: GasParameters) -> impl Iterator<Item = (String, NativeFunction)> {
let mut natives = vec![
let mut natives = vec![];

// Always-on natives.
natives.append(&mut vec![
(
"public_key_validate_internal",
make_native_from_func(gas_params.clone(), native_public_key_validate),
Expand All @@ -153,21 +156,20 @@ pub fn make_all(gas_params: GasParameters) -> impl Iterator<Item = (String, Nati
"signature_verify_strict_internal",
make_native_from_func(gas_params, native_signature_verify_strict),
),
];
]);

// Test-only natives.
#[cfg(feature = "testing")]
{
let mut test_only_natives = vec![
(
"generate_keys_internal",
make_test_only_native_from_func(native_test_only_generate_keys_internal),
),
(
"sign_internal",
make_test_only_native_from_func(native_test_only_sign_internal),
),
];
natives.append(&mut test_only_natives);
}
natives.append(&mut vec![
(
"generate_keys_internal",
make_test_only_native_from_func(native_test_only_generate_keys_internal),
),
(
"sign_internal",
make_test_only_native_from_func(native_test_only_sign_internal),
),
]);

crate::natives::helpers::make_module_natives(natives)
}
Expand Down

0 comments on commit 5ea5e19

Please sign in to comment.