Skip to content

Commit 0a0c2df

Browse files
authored
Fix bn254pairing budget number, update xdr version (#1613)
### What Also fixed the bn/bls pairing calibration input floor (in the current setup, passing inputs {1, 2} ends up running input=1 twice). ### Why [TODO: Why this change is being made. Include any context required to understand the why.] ### Known limitations [TODO or N/A]
1 parent b4d965d commit 0a0c2df

File tree

8 files changed

+24
-29
lines changed

8 files changed

+24
-29
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ wasmparser = "=0.116.1"
3434

3535
# NB: When updating, also update the version in rs-soroban-env dev-dependencies
3636
[workspace.dependencies.stellar-xdr]
37-
version = "=23.0.0"
37+
version = "=24.0.1"
3838
git = "https://github.com/stellar/rs-stellar-xdr"
39-
rev = "abcfb947e8c8551ae52604f6d57b43895e2bd76d"
39+
rev = "89cc1cbadf1b9a16843826954dede7fec514d8e7"
4040
default-features = false
4141

4242
[workspace.dependencies.wasmi]

soroban-env-host/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ p256 = {version = "0.13.2", default-features = false, features = ["alloc"]}
8585
lazy_static = "1.5.0"
8686

8787
[dev-dependencies.stellar-xdr]
88-
version = "=23.0.0"
88+
version = "=24.0.1"
8989
git = "https://github.com/stellar/rs-stellar-xdr"
90-
rev = "abcfb947e8c8551ae52604f6d57b43895e2bd76d"
90+
rev = "89cc1cbadf1b9a16843826954dede7fec514d8e7"
9191
default-features = false
9292
features = ["arbitrary"]
9393

soroban-env-host/benches/common/cost_types/bls12_381.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,10 @@ impl HostCostMeasurement for Bls12381PairingMeasure {
339339
type Runner = Bls12381PairingRun;
340340

341341
fn new_random_case(_host: &Host, rng: &mut StdRng, input: u64) -> Bls12381PairingSample {
342+
let i = input.max(1);
342343
Bls12381PairingSample(
343-
(0..input)
344-
.into_iter()
345-
.map(|_| G1Affine::rand(rng))
346-
.collect(),
347-
(0..input)
348-
.into_iter()
349-
.map(|_| G2Affine::rand(rng))
350-
.collect(),
344+
(0..i).into_iter().map(|_| G1Affine::rand(rng)).collect(),
345+
(0..i).into_iter().map(|_| G2Affine::rand(rng)).collect(),
351346
)
352347
}
353348
}

soroban-env-host/benches/common/cost_types/bn254.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ impl HostCostMeasurement for Bn254PairingMeasure {
141141
type Runner = Bn254PairingRun;
142142

143143
fn new_random_case(_host: &Host, rng: &mut StdRng, input: u64) -> Bn254PairingSample {
144-
let i = input.max(2);
144+
let i = input.max(1);
145145
Bn254PairingSample(
146-
(1..i).into_iter().map(|_| G1Affine::rand(rng)).collect(),
147-
(1..i).into_iter().map(|_| G2Affine::rand(rng)).collect(),
146+
(0..i).into_iter().map(|_| G1Affine::rand(rng)).collect(),
147+
(0..i).into_iter().map(|_| G2Affine::rand(rng)).collect(),
148148
)
149149
}
150150
}

soroban-env-host/observations/25/test__bn254__test_bn254_multi_pairing_check.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
" 37 ret vec_len -> Ok(U32(3))": "cpu:10906",
4040
" 38 call vec_len(Vec(obj#67))": "cpu:17176, mem:1440",
4141
" 39 ret vec_len -> Ok(U32(3))": "cpu:17298",
42-
" 40 ret bn254_multi_pairing_check -> Ok(True)": "cpu:33243006, mem:222961",
42+
" 40 ret bn254_multi_pairing_check -> Ok(True)": "cpu:23308023, mem:149736",
4343
" 41 call bn254_g1_add(Bytes(obj#69), Bytes(obj#71))": "cpu:2947855, mem:768, objs:-/38@3d38193f",
4444
" 42 ret bn254_g1_add -> Ok(Bytes(obj#77))": "cpu:2957223, mem:928, objs:-/39@d695fd46",
4545
" 43 call vec_new_from_slice(3)": "",
@@ -51,7 +51,7 @@
5151
" 49 ret vec_len -> Ok(U32(3))": "cpu:2959893",
5252
" 50 call vec_len(Vec(obj#81))": "cpu:2966163, mem:1376",
5353
" 51 ret vec_len -> Ok(U32(3))": "cpu:2966285",
54-
" 52 ret bn254_multi_pairing_check -> Ok(True)": "cpu:36191993, mem:222897",
54+
" 52 ret bn254_multi_pairing_check -> Ok(True)": "cpu:26257010, mem:149672",
5555
" 53 call obj_from_u256_pieces(1010788071183958826, 11343673176685890334, 5321920092515675630, 13294342434574159125)": "cpu:0, mem:0",
5656
" 54 ret obj_from_u256_pieces -> Ok(U256(obj#83))": "cpu:503, mem:80, objs:-/42@1ef08dab",
5757
" 55 call obj_from_u256_pieces(2069246105850674101, 2198446477011941359, 661982898885800758, 4032643384944951997)": "",
@@ -73,7 +73,7 @@
7373
" 71 ret vec_len -> Ok(U32(4))": "cpu:3491116",
7474
" 72 call vec_len(Vec(obj#109))": "cpu:3499311, mem:2464",
7575
" 73 ret vec_len -> Ok(U32(4))": "cpu:3499433",
76-
" 74 ret bn254_multi_pairing_check -> Ok(True)": "cpu:44427711, mem:297085",
76+
" 74 ret bn254_multi_pairing_check -> Ok(True)": "cpu:32798899, mem:199580",
7777
" 75 call vec_new_from_slice(3)": "cpu:5001, mem:480, objs:-/58@13a45342",
7878
" 76 ret vec_new_from_slice -> Ok(Vec(obj#117))": "cpu:6153, mem:600, objs:-/59@e788809a",
7979
" 77 call vec_new_from_slice(3)": "cpu:9138, mem:1272, objs:-/62@c3c2a88",
@@ -83,7 +83,7 @@
8383
" 81 ret vec_len -> Ok(U32(3))": "cpu:10656",
8484
" 82 call vec_len(Vec(obj#125))": "cpu:16926, mem:1600",
8585
" 83 ret vec_len -> Ok(U32(3))": "cpu:17048",
86-
" 84 ret bn254_multi_pairing_check -> Ok(False)": "cpu:33242756, mem:223121",
86+
" 84 ret bn254_multi_pairing_check -> Ok(False)": "cpu:23307773, mem:149896",
8787
" 85 call vec_new_from_slice(3)": "cpu:5001, mem:480, objs:-/66@c109b6ce",
8888
" 86 ret vec_new_from_slice -> Ok(Vec(obj#133))": "cpu:6153, mem:600, objs:-/67@1722c54b",
8989
" 87 call vec_new_from_slice(3)": "cpu:9138, mem:1272, objs:-/70@bbdb09cd",
@@ -93,7 +93,7 @@
9393
" 91 ret vec_len -> Ok(U32(3))": "cpu:10656",
9494
" 92 call vec_len(Vec(obj#141))": "cpu:16926, mem:1600",
9595
" 93 ret vec_len -> Ok(U32(3))": "cpu:17048",
96-
" 94 ret bn254_multi_pairing_check -> Ok(False)": "cpu:33242756, mem:223121",
96+
" 94 ret bn254_multi_pairing_check -> Ok(False)": "cpu:23307773, mem:149896",
9797
" 95 call vec_new_from_slice(2)": "cpu:3334, mem:320, objs:-/73@d5c975db",
9898
" 96 ret vec_new_from_slice -> Ok(Vec(obj#147))": "cpu:4423, mem:432, objs:-/74@598dad8f",
9999
" 97 call vec_new_from_slice(2)": "cpu:6413, mem:880, objs:-/76@7c6b8e4a",
@@ -103,6 +103,6 @@
103103
" 101 ret vec_len -> Ok(U32(2))": "cpu:7868",
104104
" 102 call vec_len(Vec(obj#153))": "cpu:12213, mem:1136",
105105
" 103 ret vec_len -> Ok(U32(2))": "cpu:12335",
106-
" 104 ret bn254_multi_pairing_check -> Ok(True)": "cpu:25535472, mem:149556",
107-
" 105 end": "cpu:25535472, mem:149556, prngs:-/-, objs:-/77@7903cbb2, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-"
106+
" 104 ret bn254_multi_pairing_check -> Ok(True)": "cpu:17294319, mem:100612",
107+
" 105 end": "cpu:17294319, mem:100612, prngs:-/-, objs:-/77@7903cbb2, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-"
108108
}

soroban-env-host/src/budget.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,8 @@ impl Default for BudgetImpl {
655655
cpu.lin_term = ScaledU64(0);
656656
}
657657
ContractCostType::Bn254Pairing => {
658-
cpu.const_term = 10117409;
659-
cpu.lin_term = ScaledU64(609283036);
658+
cpu.const_term = 5263916;
659+
cpu.lin_term = ScaledU64(392472814);
660660
}
661661
ContractCostType::Bn254FrFromU256 => {
662662
cpu.const_term = 2052;
@@ -1007,8 +1007,8 @@ impl Default for BudgetImpl {
10071007
mem.lin_term = ScaledU64(0);
10081008
}
10091009
ContractCostType::Bn254Pairing => {
1010-
mem.const_term = 2204;
1011-
mem.lin_term = ScaledU64(9340474);
1010+
mem.const_term = 1821;
1011+
mem.lin_term = ScaledU64(6232546);
10121012
}
10131013
ContractCostType::Bn254FrFromU256 => {
10141014
mem.const_term = 0;

soroban-env-host/src/test/budget_metering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ fn total_amount_charged_from_random_inputs() -> Result<(), HostError> {
523523
Bn254G1ProjectiveToAffine 0 None 0 0 61 0 0 0
524524
Bn254G1Add 0 None 0 0 3623 0 0 0
525525
Bn254G1Mul 0 None 0 0 1150435 0 0 0
526-
Bn254Pairing 0 Some(0) 0 0 10117409 609283036 2204 9340474
526+
Bn254Pairing 0 Some(0) 0 0 5263916 392472814 1821 6232546
527527
Bn254FrFromU256 0 None 0 0 2052 0 0 0
528528
Bn254FrToU256 0 None 0 0 1133 0 312 0
529529
Bn254FrAddSub 0 None 0 0 74 0 0 0

0 commit comments

Comments
 (0)