From d8ac339d40d8f0ddba8df5b46c0c78a2dfd35824 Mon Sep 17 00:00:00 2001 From: zhoujunma Date: Tue, 2 Jul 2024 10:40:02 -0700 Subject: [PATCH] charge into_affine (#13893) --- .../cryptography/algebra/serialization.rs | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/aptos-move/framework/src/natives/cryptography/algebra/serialization.rs b/aptos-move/framework/src/natives/cryptography/algebra/serialization.rs index 83cf9ee34a9b9..19a6457f30aa1 100644 --- a/aptos-move/framework/src/natives/cryptography/algebra/serialization.rs +++ b/aptos-move/framework/src/natives/cryptography/algebra/serialization.rs @@ -10,7 +10,9 @@ use crate::{ }, safe_borrow_element, store_element, structure_from_ty_arg, }; -use aptos_gas_schedule::gas_params::natives::aptos_framework::*; +use aptos_gas_schedule::{ + gas_feature_versions::RELEASE_V1_16, gas_params::natives::aptos_framework::*, +}; use aptos_native_interface::{ safely_pop_arg, SafeNativeContext, SafeNativeError, SafeNativeResult, }; @@ -73,7 +75,7 @@ macro_rules! serialize_element { $structure_to_match:expr, $format_to_match:expr, [$(($field_structure:pat, $field_format:pat, $field_ty:ty, $field_serialization_func:ident,$reverse:expr, $field_serialization_gas:expr)),* $(,)?], - [$(($curve_structure:pat,$curve_format:pat, $curve_ty:ty, $curve_serialization_func:ident, $curve_serialization_gas:expr)),* $(,)?] + [$(($curve_structure:pat,$curve_format:pat, $curve_ty:ty, $curve_serialization_func:ident, $curve_serialization_gas:expr, $into_affine_gas:expr)),* $(,)?] ) => { match ($structure_to_match, $format_to_match) { $( @@ -101,6 +103,9 @@ macro_rules! serialize_element { element_ptr, element ); + if $context.gas_feature_version() >= RELEASE_V1_16 { + $context.charge($into_affine_gas)?; + } let element_affine = element.into_affine(); let mut buf = Vec::new(); $context.charge($curve_serialization_gas)?; @@ -220,56 +225,64 @@ pub fn serialize_internal( SerializationFormat::BLS12381G1Uncompressed, ark_bls12_381::G1Projective, serialize_uncompressed, - ALGEBRA_ARK_BLS12_381_G1_AFFINE_SERIALIZE_UNCOMP + ALGEBRA_ARK_BLS12_381_G1_AFFINE_SERIALIZE_UNCOMP, + ALGEBRA_ARK_BLS12_381_G1_PROJ_TO_AFFINE ), ( Structure::BLS12381G1, SerializationFormat::BLS12381G1Compressed, ark_bls12_381::G1Projective, serialize_compressed, - ALGEBRA_ARK_BLS12_381_G1_AFFINE_SERIALIZE_COMP + ALGEBRA_ARK_BLS12_381_G1_AFFINE_SERIALIZE_COMP, + ALGEBRA_ARK_BLS12_381_G1_PROJ_TO_AFFINE ), ( Structure::BLS12381G2, SerializationFormat::BLS12381G2Uncompressed, ark_bls12_381::G2Projective, serialize_uncompressed, - ALGEBRA_ARK_BLS12_381_G2_AFFINE_SERIALIZE_UNCOMP + ALGEBRA_ARK_BLS12_381_G2_AFFINE_SERIALIZE_UNCOMP, + ALGEBRA_ARK_BLS12_381_G2_PROJ_TO_AFFINE ), ( Structure::BLS12381G2, SerializationFormat::BLS12381G2Compressed, ark_bls12_381::G2Projective, serialize_compressed, - ALGEBRA_ARK_BLS12_381_G2_AFFINE_SERIALIZE_COMP + ALGEBRA_ARK_BLS12_381_G2_AFFINE_SERIALIZE_COMP, + ALGEBRA_ARK_BLS12_381_G2_PROJ_TO_AFFINE ), ( Structure::BN254G1, SerializationFormat::BN254G1Uncompressed, ark_bn254::G1Projective, serialize_uncompressed, - ALGEBRA_ARK_BN254_G1_AFFINE_SERIALIZE_UNCOMP + ALGEBRA_ARK_BN254_G1_AFFINE_SERIALIZE_UNCOMP, + ALGEBRA_ARK_BN254_G1_PROJ_TO_AFFINE ), ( Structure::BN254G1, SerializationFormat::BN254G1Compressed, ark_bn254::G1Projective, serialize_compressed, - ALGEBRA_ARK_BN254_G1_AFFINE_SERIALIZE_COMP + ALGEBRA_ARK_BN254_G1_AFFINE_SERIALIZE_COMP, + ALGEBRA_ARK_BN254_G1_PROJ_TO_AFFINE ), ( Structure::BN254G2, SerializationFormat::BN254G2Uncompressed, ark_bn254::G2Projective, serialize_uncompressed, - ALGEBRA_ARK_BN254_G2_AFFINE_SERIALIZE_UNCOMP + ALGEBRA_ARK_BN254_G2_AFFINE_SERIALIZE_UNCOMP, + ALGEBRA_ARK_BN254_G2_PROJ_TO_AFFINE ), ( Structure::BN254G2, SerializationFormat::BN254G2Compressed, ark_bn254::G2Projective, serialize_compressed, - ALGEBRA_ARK_BN254_G2_AFFINE_SERIALIZE_COMP + ALGEBRA_ARK_BN254_G2_AFFINE_SERIALIZE_COMP, + ALGEBRA_ARK_BN254_G2_PROJ_TO_AFFINE ), ] )