Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Features] support bn254_algebra in aptos_stdlib #11142

Merged
merged 25 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
480756d
[feat][aptos-stdlib] crypto algebra bn254
nanne007 Nov 29, 2023
71c74ab
scripts: fix update_algebra_gas_params.py
nanne007 Nov 30, 2023
eeedf11
add bn254 to default features to make unit test pass
nanne007 Nov 30, 2023
1570e31
fix a bug mentioned in the comments
nanne007 Dec 1, 2023
0e637ae
add test for bn254
nanne007 Dec 2, 2023
b429d5c
bn254: add test and doc
nanne007 Dec 2, 2023
9aaa429
ark_bn254 benches and derived gas parameters (#2)
zjma Dec 4, 2023
28bf7bc
resolve comments
nanne007 Dec 4, 2023
f391a95
doc: `cargo run -p aptos-framework release` to generate doc
nanne007 Dec 4, 2023
653e798
address comments, and regenerate doc
nanne007 Dec 6, 2023
af3e4f8
update doc
zjma Dec 8, 2023
563a827
update doc
zjma Dec 8, 2023
75a0cc1
Merge remote-tracking branch 'origin/main' into bn256
zjma Dec 8, 2023
7030c9f
lint, fix ut
zjma Dec 8, 2023
3361d64
lint
zjma Dec 8, 2023
8e8187f
address comments from `alinush`
nanne007 Dec 10, 2023
0199f69
delete bn254_fq2 related code
nanne007 Dec 10, 2023
62e3cf8
address comments on bench
nanne007 Dec 10, 2023
694f5c9
Merge remote-tracking branch 'origin/main' into bn256
zjma Dec 11, 2023
6185826
lint, also hardcode BN254 Gt generator to save cold start time
zjma Dec 11, 2023
2f3e78a
revert debugging stuff
zjma Dec 11, 2023
a77c7e3
update gas version
zjma Dec 12, 2023
8d74140
Merge remote-tracking branch 'origin/main' into bn256
zjma Dec 12, 2023
ef67f4e
lint
zjma Dec 12, 2023
ce2f204
Merge remote-tracking branch 'origin/main' into bn256
zjma Dec 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ anstyle = "1.0.1"
arc-swap = "1.6.0"
arr_macro = "0.2.1"
ark-bls12-381 = "0.4.0"
ark-bn254 = "0.4.0"
ark-ec = "0.4.0"
ark-ff = "0.4.0"
ark-serialize = "0.4.0"
Expand Down
82 changes: 79 additions & 3 deletions aptos-move/aptos-gas-schedule/src/gas_schedule/aptos_framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,84 @@
[account_create_address_base: InternalGas, "account.create_address.base", 6000],
[account_create_signer_base: InternalGas, "account.create_signer.base", 6000],

// Algebra gas parameters begin.
// Generated at time 1680606720.0709136 by `scripts/algebra-gas/update_algebra_gas_params.py` with gas_per_ns=10.23.
// BN254 algebra gas parameters begin.
// Generated at time 1701559125.5498126 by `scripts/algebra-gas/update_bn254_algebra_gas_params.py` with gas_per_ns=209.10511688369482.
[algebra_ark_bn254_fq12_add: InternalGas, { 13.. => "algebra.ark_bn254_fq12_add" }, 4_406],
[algebra_ark_bn254_fq12_clone: InternalGas, { 13.. => "algebra.ark_bn254_fq12_clone" }, 4_392],
[algebra_ark_bn254_fq12_deser: InternalGas, { 13.. => "algebra.ark_bn254_fq12_deser" }, 129_063],
[algebra_ark_bn254_fq12_div: InternalGas, { 13.. => "algebra.ark_bn254_fq12_div" }, 2_813_602],
[algebra_ark_bn254_fq12_eq: InternalGas, { 13.. => "algebra.ark_bn254_fq12_eq" }, 12_142],
[algebra_ark_bn254_fq12_from_u64: InternalGas, { 13.. => "algebra.ark_bn254_fq12_from_u64" }, 14_463],
[algebra_ark_bn254_fq12_inv: InternalGas, { 13.. => "algebra.ark_bn254_fq12_inv" }, 2_168_418],
[algebra_ark_bn254_fq12_mul: InternalGas, { 13.. => "algebra.ark_bn254_fq12_mul" }, 643_914],
[algebra_ark_bn254_fq12_neg: InternalGas, { 13.. => "algebra.ark_bn254_fq12_neg" }, 13_311],
[algebra_ark_bn254_fq12_one: InternalGas, { 13.. => "algebra.ark_bn254_fq12_one" }, 209],
[algebra_ark_bn254_fq12_pow_u256: InternalGas, { 13.. => "algebra.ark_bn254_fq12_pow_u256" }, 192_871_746],
[algebra_ark_bn254_fq12_serialize: InternalGas, { 13.. => "algebra.ark_bn254_fq12_serialize" }, 117_336],
[algebra_ark_bn254_fq12_square: InternalGas, { 13.. => "algebra.ark_bn254_fq12_square" }, 468_955],
[algebra_ark_bn254_fq12_sub: InternalGas, { 13.. => "algebra.ark_bn254_fq12_sub" }, 30_497],
[algebra_ark_bn254_fq12_zero: InternalGas, { 13.. => "algebra.ark_bn254_fq12_zero" }, 209],
[algebra_ark_bn254_fq_add: InternalGas, { 13.. => "algebra.ark_bn254_fq_add" }, 4_373],
[algebra_ark_bn254_fq_clone: InternalGas, { 13.. => "algebra.ark_bn254_fq_clone" }, 4_313],
[algebra_ark_bn254_fq_deser: InternalGas, { 13.. => "algebra.ark_bn254_fq_deser" }, 17_588],
[algebra_ark_bn254_fq_div: InternalGas, { 13.. => "algebra.ark_bn254_fq_div" }, 1_140_544],
[algebra_ark_bn254_fq_eq: InternalGas, { 13.. => "algebra.ark_bn254_fq_eq" }, 4_373],
[algebra_ark_bn254_fq_from_u64: InternalGas, { 13.. => "algebra.ark_bn254_fq_from_u64" }, 14_137],
[algebra_ark_bn254_fq_inv: InternalGas, { 13.. => "algebra.ark_bn254_fq_inv" }, 1_136_577],
[algebra_ark_bn254_fq_mul: InternalGas, { 13.. => "algebra.ark_bn254_fq_mul" }, 10_050],
[algebra_ark_bn254_fq_neg: InternalGas, { 13.. => "algebra.ark_bn254_fq_neg" }, 4_314],
[algebra_ark_bn254_fq_one: InternalGas, { 13.. => "algebra.ark_bn254_fq_one" }, 209],
[algebra_ark_bn254_fq_pow_u256: InternalGas, { 13.. => "algebra.ark_bn254_fq_pow_u256" }, 2_081_451],
[algebra_ark_bn254_fq_serialize: InternalGas, { 13.. => "algebra.ark_bn254_fq_serialize" }, 25_938],
[algebra_ark_bn254_fq_square: InternalGas, { 13.. => "algebra.ark_bn254_fq_square" }, 4_314],
[algebra_ark_bn254_fq_sub: InternalGas, { 13.. => "algebra.ark_bn254_fq_sub" }, 6_148],
[algebra_ark_bn254_fq_zero: InternalGas, { 13.. => "algebra.ark_bn254_fq_zero" }, 209],
[algebra_ark_bn254_fr_add: InternalGas, { 13.. => "algebra.ark_bn254_fr_add" }, 4_377],
[algebra_ark_bn254_fr_deser: InternalGas, { 13.. => "algebra.ark_bn254_fr_deser" }, 16_722],
[algebra_ark_bn254_fr_div: InternalGas, { 13.. => "algebra.ark_bn254_fr_div" }, 1_217_943],
[algebra_ark_bn254_fr_eq: InternalGas, { 13.. => "algebra.ark_bn254_fr_eq" }, 4_396],
[algebra_ark_bn254_fr_from_u64: InternalGas, { 13.. => "algebra.ark_bn254_fr_from_u64" }, 13_485],
[algebra_ark_bn254_fr_inv: InternalGas, { 13.. => "algebra.ark_bn254_fr_inv" }, 1_209_015],
[algebra_ark_bn254_fr_mul: InternalGas, { 13.. => "algebra.ark_bn254_fr_mul" }, 9_867],
[algebra_ark_bn254_fr_neg: InternalGas, { 13.. => "algebra.ark_bn254_fr_neg" }, 4_314],
[algebra_ark_bn254_fr_one: InternalGas, { 13.. => "algebra.ark_bn254_fr_one" }, 0],
[algebra_ark_bn254_fr_serialize: InternalGas, { 13.. => "algebra.ark_bn254_fr_serialize" }, 25_749],
[algebra_ark_bn254_fr_square: InternalGas, { 13.. => "algebra.ark_bn254_fr_square" }, 4_311],
[algebra_ark_bn254_fr_sub: InternalGas, { 13.. => "algebra.ark_bn254_fr_sub" }, 10_370],
[algebra_ark_bn254_fr_zero: InternalGas, { 13.. => "algebra.ark_bn254_fr_zero" }, 209],
[algebra_ark_bn254_g1_affine_deser_comp: InternalGas, { 13.. => "algebra.ark_bn254_g1_affine_deser_comp" }, 23_497_333],
[algebra_ark_bn254_g1_affine_deser_uncomp: InternalGas, { 13.. => "algebra.ark_bn254_g1_affine_deser_uncomp" }, 21_528_706],
[algebra_ark_bn254_g1_affine_serialize_comp: InternalGas, { 13.. => "algebra.ark_bn254_g1_affine_serialize_comp" }, 44_924],
[algebra_ark_bn254_g1_affine_serialize_uncomp: InternalGas, { 13.. => "algebra.ark_bn254_g1_affine_serialize_uncomp" }, 58_820],
[algebra_ark_bn254_g1_proj_add: InternalGas, { 13.. => "algebra.ark_bn254_g1_proj_add" }, 106_501],
[algebra_ark_bn254_g1_proj_double: InternalGas, { 13.. => "algebra.ark_bn254_g1_proj_double" }, 63_682],
[algebra_ark_bn254_g1_proj_eq: InternalGas, { 13.. => "algebra.ark_bn254_g1_proj_eq" }, 53_021],
[algebra_ark_bn254_g1_proj_generator: InternalGas, { 13.. => "algebra.ark_bn254_g1_proj_generator" }, 209],
[algebra_ark_bn254_g1_proj_infinity: InternalGas, { 13.. => "algebra.ark_bn254_g1_proj_infinity" }, 209],
[algebra_ark_bn254_g1_proj_neg: InternalGas, { 13.. => "algebra.ark_bn254_g1_proj_neg" }, 209],
[algebra_ark_bn254_g1_proj_scalar_mul: InternalGas, { 13.. => "algebra.ark_bn254_g1_proj_scalar_mul" }, 26_456_386],
[algebra_ark_bn254_g1_proj_sub: InternalGas, { 13.. => "algebra.ark_bn254_g1_proj_sub" }, 106_903],
[algebra_ark_bn254_g1_proj_to_affine: InternalGas, { 13.. => "algebra.ark_bn254_g1_proj_to_affine" }, 6_340],
[algebra_ark_bn254_g2_affine_deser_comp: InternalGas, { 13.. => "algebra.ark_bn254_g2_affine_deser_comp" }, 67_710_223],
[algebra_ark_bn254_g2_affine_deser_uncomp: InternalGas, { 13.. => "algebra.ark_bn254_g2_affine_deser_uncomp" }, 60_677_591],
[algebra_ark_bn254_g2_affine_serialize_comp: InternalGas, { 13.. => "algebra.ark_bn254_g2_affine_serialize_comp" }, 69_214],
[algebra_ark_bn254_g2_affine_serialize_uncomp: InternalGas, { 13.. => "algebra.ark_bn254_g2_affine_serialize_uncomp" }, 98_505],
[algebra_ark_bn254_g2_proj_add: InternalGas, { 13.. => "algebra.ark_bn254_g2_proj_add" }, 318_234],
[algebra_ark_bn254_g2_proj_double: InternalGas, { 13.. => "algebra.ark_bn254_g2_proj_double" }, 158_874],
[algebra_ark_bn254_g2_proj_eq: InternalGas, { 13.. => "algebra.ark_bn254_g2_proj_eq" }, 141_359],
[algebra_ark_bn254_g2_proj_generator: InternalGas, { 13.. => "algebra.ark_bn254_g2_proj_generator" }, 209],
[algebra_ark_bn254_g2_proj_infinity: InternalGas, { 13.. => "algebra.ark_bn254_g2_proj_infinity" }, 209],
[algebra_ark_bn254_g2_proj_neg: InternalGas, { 13.. => "algebra.ark_bn254_g2_proj_neg" }, 209],
[algebra_ark_bn254_g2_proj_scalar_mul: InternalGas, { 13.. => "algebra.ark_bn254_g2_proj_scalar_mul" }, 76_395_801],
[algebra_ark_bn254_g2_proj_sub: InternalGas, { 13.. => "algebra.ark_bn254_g2_proj_sub" }, 321_727],
[algebra_ark_bn254_g2_proj_to_affine: InternalGas, { 13.. => "algebra.ark_bn254_g2_proj_to_affine" }, 1_251_909],
[algebra_ark_bn254_multi_pairing_base: InternalGas, { 13.. => "algebra.ark_bn254_multi_pairing_base" }, 127_794_596],
[algebra_ark_bn254_multi_pairing_per_pair: InternalGasPerArg, { 13.. => "algebra.ark_bn254_multi_pairing_per_pair" }, 67_624_587],
[algebra_ark_bn254_pairing: InternalGas, { 13.. => "algebra.ark_bn254_pairing" }, 209_703_839],
// BN254 algebra gas parameters end.

// BLS12-381 algebra gas parameters begin.
// Generated at time 1680606720.0709136 by `scripts/algebra-gas/update_algebra_gas_params.py` with gas_per_ns=204.6.

Check warning on line 96 in aptos-move/aptos-gas-schedule/src/gas_schedule/aptos_framework.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-gas-schedule/src/gas_schedule/aptos_framework.rs#L19-L96

Added lines #L19 - L96 were not covered by tests
[algebra_ark_bls12_381_fq12_add: InternalGas, { 8.. => "algebra.ark_bls12_381_fq12_add" }, 36380],
[algebra_ark_bls12_381_fq12_clone: InternalGas, { 8.. => "algebra.ark_bls12_381_fq12_clone" }, 4220],
[algebra_ark_bls12_381_fq12_deser: InternalGas, { 8.. => "algebra.ark_bls12_381_fq12_deser" }, 223600],
Expand Down Expand Up @@ -79,7 +155,7 @@
[algebra_ark_h2c_bls12381g1_xmd_sha256_sswu_per_msg_byte: InternalGasPerByte, { 8.. => "algebra.ark_h2c_bls12381g1_xmd_sha256_sswu_per_msg_byte" }, 960],
[algebra_ark_h2c_bls12381g2_xmd_sha256_sswu_base: InternalGas, { 8.. => "algebra.ark_h2c_bls12381g2_xmd_sha256_sswu_base" }, 135460040],
[algebra_ark_h2c_bls12381g2_xmd_sha256_sswu_per_msg_byte: InternalGasPerByte, { 8.. => "algebra.ark_h2c_bls12381g2_xmd_sha256_sswu_per_msg_byte" }, 960],
// Algebra gas parameters end.
// BLS12-381 algebra gas parameters end.

Check warning on line 158 in aptos-move/aptos-gas-schedule/src/gas_schedule/aptos_framework.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-gas-schedule/src/gas_schedule/aptos_framework.rs#L158

Added line #L158 was not covered by tests

[bls12381_base: InternalGas, "bls12381.base", 3000],

Expand Down
4 changes: 3 additions & 1 deletion aptos-move/aptos-gas-schedule/src/ver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
/// - Changing how gas is calculated in any way
///
/// Change log:
/// - V13
/// - Added BN254 operations.
/// - V12
/// - Making resource group charge on first read independent of BTreeMap serialization.
/// - V11
Expand Down Expand Up @@ -44,4 +46,4 @@
/// global operations.
/// - V1
/// - TBA
pub const LATEST_GAS_FEATURE_VERSION: u64 = 12;
pub const LATEST_GAS_FEATURE_VERSION: u64 = 13;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, a gas version bump here.

Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub enum FeatureFlag {
VMBinaryFormatV7,
ResourceGroupsChargeAsSizeSum,
CommissionChangeDelegationPool,
BN254Structures,
}

fn generate_features_blob(writer: &CodeWriter, data: &[u64]) {
Expand Down Expand Up @@ -244,6 +245,7 @@ impl From<FeatureFlag> for AptosFeatureFlag {
FeatureFlag::CommissionChangeDelegationPool => {
AptosFeatureFlag::COMMISSION_CHANGE_DELEGATION_POOL
},
FeatureFlag::BN254Structures => AptosFeatureFlag::BN254_STRUCTURES,
}
}
}
Expand Down Expand Up @@ -318,6 +320,7 @@ impl From<AptosFeatureFlag> for FeatureFlag {
AptosFeatureFlag::COMMISSION_CHANGE_DELEGATION_POOL => {
FeatureFlag::CommissionChangeDelegationPool
},
AptosFeatureFlag::BN254_STRUCTURES => FeatureFlag::BN254Structures,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Ok(
StateKey {
inner: AccessPath { address: 0xbeef, path: "Resource(0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>)" },
hash: OnceCell(Uninit),
}: Modification(a4aac0a47e8d03000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000beef00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000beef),
}: Modification(78a9c0a47e8d03000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000beef00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000beef),
StateKey {
inner: AccessPath { address: 0xbeef, path: "Resource(0x1::account::Account)" },
hash: OnceCell(Uninit),
Expand All @@ -32,7 +32,7 @@ Ok(
StateKey {
inner: TableItem { handle: 1b854694ae746cdbd8d44186ca4929b2b337df21d1c74633be19b2710552fdca, key: 0619dc29a0aac8fa146714058e8dd6d2d0f3bdf5f6331907bf91f3acd81e6935 },
hash: OnceCell(Uninit),
}: Modification(a30bf005000000000100000000000000),
}: Modification(770af005000000000100000000000000),
},
},
),
Expand All @@ -57,15 +57,15 @@ Ok(
StateKey {
inner: AccessPath { address: 0xbeef, path: "Resource(0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>)" },
hash: OnceCell(Uninit),
}: Modification(6c79c0a47e8d03000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000beef00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000beef),
}: Modification(4078c0a47e8d03000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000beef00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000beef),
StateKey {
inner: AccessPath { address: 0xbeef, path: "Resource(0x1::account::Account)" },
hash: OnceCell(Uninit),
}: Modification(201304972f9242cbc3528a1e286323471ab891baa37e0053b85651693a79854a000e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000beef00000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000beef0000),
StateKey {
inner: TableItem { handle: 1b854694ae746cdbd8d44186ca4929b2b337df21d1c74633be19b2710552fdca, key: 0619dc29a0aac8fa146714058e8dd6d2d0f3bdf5f6331907bf91f3acd81e6935 },
hash: OnceCell(Uninit),
}: Modification(6bdaef05000000000100000000000000),
}: Modification(3fd9ef05000000000100000000000000),
},
},
),
Expand Down Expand Up @@ -94,15 +94,15 @@ Ok(
StateKey {
inner: AccessPath { address: 0xbeef, path: "Resource(0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>)" },
hash: OnceCell(Uninit),
}: Modification(1c4cc0a47e8d03000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000beef00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000beef),
}: Modification(f04ac0a47e8d03000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000beef00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000beef),
StateKey {
inner: AccessPath { address: 0xbeef, path: "Resource(0x1::account::Account)" },
hash: OnceCell(Uninit),
}: Modification(201304972f9242cbc3528a1e286323471ab891baa37e0053b85651693a79854a000f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000beef00000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000beef0000),
StateKey {
inner: TableItem { handle: 1b854694ae746cdbd8d44186ca4929b2b337df21d1c74633be19b2710552fdca, key: 0619dc29a0aac8fa146714058e8dd6d2d0f3bdf5f6331907bf91f3acd81e6935 },
hash: OnceCell(Uninit),
}: Modification(1badef05000000000100000000000000),
}: Modification(efabef05000000000100000000000000),
},
},
),
Expand Down