Skip to content

Commit

Permalink
turn some more deserialization functions into generic; add roundtrip …
Browse files Browse the repository at this point in the history
…tests

Add serialization roundtrip tests
  • Loading branch information
jayz22 committed Sep 16, 2024
1 parent a83cefb commit 6eff233
Show file tree
Hide file tree
Showing 9 changed files with 778 additions and 563 deletions.
282 changes: 141 additions & 141 deletions soroban-env-host/observations/22/test__bls12_381__g1_msm.json

Large diffs are not rendered by default.

236 changes: 118 additions & 118 deletions soroban-env-host/observations/22/test__bls12_381__g2_msm.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
" 0 begin": "cpu:0, mem:0, prngs:-/-, objs:-/-, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-",
" 1 call bytes_new_from_slice(95)": "cpu:661",
" 2 ret bytes_new_from_slice -> Ok(Bytes(obj#1))": "cpu:1644, mem:175, objs:-/1@14742518",
" 1 call bytes_new_from_slice(95)": "cpu:1322",
" 2 ret bytes_new_from_slice -> Ok(Bytes(obj#1))": "cpu:2305, mem:175, objs:-/1@14742518",
" 3 call bls12_381_map_fp2_to_g2(Bytes(obj#1))": "",
" 4 ret bls12_381_map_fp2_to_g2 -> Err(Error(Crypto, InvalidInput))": "cpu:1766",
" 5 call bytes_new_from_slice(97)": "cpu:2427",
" 6 ret bytes_new_from_slice -> Ok(Bytes(obj#3))": "cpu:3412, mem:352, objs:-/2@b8cae411",
" 4 ret bls12_381_map_fp2_to_g2 -> Err(Error(Crypto, InvalidInput))": "cpu:2427",
" 5 call bytes_new_from_slice(97)": "cpu:3749",
" 6 ret bytes_new_from_slice -> Ok(Bytes(obj#3))": "cpu:4734, mem:352, objs:-/2@b8cae411",
" 7 call bls12_381_map_fp2_to_g2(Bytes(obj#3))": "",
" 8 ret bls12_381_map_fp2_to_g2 -> Err(Error(Crypto, InvalidInput))": "cpu:3534",
" 8 ret bls12_381_map_fp2_to_g2 -> Err(Error(Crypto, InvalidInput))": "cpu:4856",
" 9 call bytes_new_from_slice(192)": "cpu:0, mem:0",
" 10 ret bytes_new_from_slice -> Ok(Bytes(obj#5))": "cpu:1009, mem:272, objs:-/3@84cbabcf",
" 11 call bytes_new_from_slice(96)": "",
Expand Down
188 changes: 94 additions & 94 deletions soroban-env-host/observations/22/test__bls12_381__pairing.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
" 0 begin": "cpu:0, mem:0, prngs:-/-, objs:-/-, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-",
" 1 call obj_from_u256_pieces(2395589458197215953, 3306305587277880961, 1302117398068482837, 1091207826991875146)": "cpu:50772796, mem:28008, objs:-/137@d07a46d8",
" 2 ret obj_from_u256_pieces -> Ok(U256(obj#275))": "cpu:50773297, mem:28072, objs:-/138@99d5e5d2",
" 3 call obj_from_u256_pieces(4030740013859617607, 13817590489558995017, 443594582117458576, 245589856645029399)": "cpu:50776507, mem:28320",
" 4 ret obj_from_u256_pieces -> Ok(U256(obj#277))": "cpu:50777008, mem:28384, objs:-/139@ce81e5d9",
" 5 call obj_from_u256_pieces(2309403286221278731, 240231957602763745, 18358523006851037387, 13739599435256500115)": "cpu:50780218, mem:28632",
" 6 ret obj_from_u256_pieces -> Ok(U256(obj#279))": "cpu:50780719, mem:28696, objs:-/140@279a975",
" 7 call obj_from_u256_pieces(5744460099082395691, 11679559040025848215, 5800079206407269482, 14330949528024819573)": "cpu:50783929, mem:28944",
" 8 ret obj_from_u256_pieces -> Ok(U256(obj#281))": "cpu:50784430, mem:29008, objs:-/141@3f854b89",
" 9 call obj_from_u256_pieces(912784256554815413, 7739630991749586382, 11693624627592045674, 9648884353269389255)": "cpu:50787640, mem:29256",
" 10 ret obj_from_u256_pieces -> Ok(U256(obj#283))": "cpu:50788141, mem:29320, objs:-/142@24879da6",
" 11 call obj_from_u256_pieces(1298169624505566978, 11840534902383509259, 10489044078202748843, 10046771591107357601)": "cpu:50791351, mem:29568",
" 12 ret obj_from_u256_pieces -> Ok(U256(obj#285))": "cpu:50791852, mem:29632, objs:-/143@765f0703",
" 13 call obj_from_u256_pieces(4462537922610993750, 5476907946140276402, 15301198056592352265, 8829090581031049060)": "cpu:50795062, mem:29880",
" 14 ret obj_from_u256_pieces -> Ok(U256(obj#287))": "cpu:50795563, mem:29944, objs:-/144@fc5d4293",
" 15 call obj_from_u256_pieces(1483814255270150809, 2240693107019974066, 11035480608488985609, 5591664456856301659)": "cpu:50798773, mem:30192",
" 16 ret obj_from_u256_pieces -> Ok(U256(obj#289))": "cpu:50799274, mem:30256, objs:-/145@3c777c38",
" 17 call obj_from_u256_pieces(2823066946149997955, 4017845098771023863, 2091132495329236295, 4382883068235871617)": "cpu:50802484, mem:30504",
" 18 ret obj_from_u256_pieces -> Ok(U256(obj#291))": "cpu:50802985, mem:30568, objs:-/146@5fdd6fd7",
" 19 call obj_from_u256_pieces(8147738635046659263, 10838147310065800303, 9456691195047663294, 4156381095270017721)": "cpu:50806195, mem:30816",
" 20 ret obj_from_u256_pieces -> Ok(U256(obj#293))": "cpu:50806696, mem:30880, objs:-/147@d2116a6",
" 21 call obj_from_u256_pieces(4759692657470168240, 3248115619405505989, 1935398248938956755, 17870100943070610895)": "cpu:50809906, mem:31128",
" 22 ret obj_from_u256_pieces -> Ok(U256(obj#295))": "cpu:50810407, mem:31192, objs:-/148@d3aca663",
" 23 call obj_from_u256_pieces(6299505550503794325, 934313480772554357, 9575559878597866574, 13968606194827052782)": "cpu:50813617, mem:31440",
" 24 ret obj_from_u256_pieces -> Ok(U256(obj#297))": "cpu:50814118, mem:31504, objs:-/149@49b852dc",
" 25 call obj_from_u256_pieces(5154620316501156786, 16487987160575941779, 7214314208877781085, 7991574812575765638)": "cpu:50817328, mem:31752",
" 26 ret obj_from_u256_pieces -> Ok(U256(obj#299))": "cpu:50817829, mem:31816, objs:-/150@9ae0887",
" 27 call obj_from_u256_pieces(532576566866806321, 10721499738797675969, 16215558025196189643, 12632335931862967898)": "cpu:50821039, mem:32064",
" 28 ret obj_from_u256_pieces -> Ok(U256(obj#301))": "cpu:50821540, mem:32128, objs:-/151@22cb95b8",
" 29 call obj_from_u256_pieces(8159131102163283424, 8923210778304361529, 1540766709305171743, 2989208879561351542)": "cpu:50824750, mem:32376",
" 30 ret obj_from_u256_pieces -> Ok(U256(obj#303))": "cpu:50825251, mem:32440, objs:-/152@ed27ba1d",
" 31 call obj_from_u256_pieces(5698022951443837324, 16779749181027918978, 6902233456353033725, 10646855747138121935)": "cpu:50828461, mem:32688",
" 32 ret obj_from_u256_pieces -> Ok(U256(obj#305))": "cpu:50828962, mem:32752, objs:-/153@7d1f6066",
" 33 call obj_from_u256_pieces(3849184316064635501, 8312667462643589578, 14602721145082682090, 4963389936466161700)": "cpu:50832172, mem:33000",
" 34 ret obj_from_u256_pieces -> Ok(U256(obj#307))": "cpu:50832673, mem:33064, objs:-/154@610bedde",
" 35 call obj_from_u256_pieces(6428876429662729984, 1159517746365042179, 5484564165453778753, 15411623082197541403)": "cpu:50835883, mem:33312",
" 36 ret obj_from_u256_pieces -> Ok(U256(obj#309))": "cpu:50836384, mem:33376, objs:-/155@40c4136a",
" 37 call obj_from_u256_pieces(801460342213299702, 9908357551484169280, 1024931740778734376, 6858226285216280857)": "cpu:50839594, mem:33624",
" 38 ret obj_from_u256_pieces -> Ok(U256(obj#311))": "cpu:50840095, mem:33688, objs:-/156@794e1c81",
" 39 call obj_from_u256_pieces(3249626194219012092, 12917896548134785039, 10675741979518937446, 3611643771666195033)": "cpu:50843305, mem:33936",
" 40 ret obj_from_u256_pieces -> Ok(U256(obj#313))": "cpu:50843806, mem:34000, objs:-/157@1912f2a7",
" 41 end": "cpu:50845861, mem:34000, prngs:-/-, objs:-/157@1912f2a7, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-"
}
5 changes: 3 additions & 2 deletions soroban-env-host/src/cost_runner/cost_types/bls12_381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use ark_ec::pairing::PairingOutput;

use crate::{
cost_runner::{CostRunner, CostType},
crypto::bls12_381::FP_SERIALIZED_SIZE,
impl_const_cost_runner_for_bls_consume_sample, impl_const_cost_runner_for_bls_deref_sample,
impl_lin_cost_runner_for_bls_deref_sample,
xdr::ContractCostType::{
Expand Down Expand Up @@ -251,7 +252,7 @@ impl CostRunner for Bls12381EncodeFpRun {
) -> Self::RecycledType {
let Bls12381EncodeFpSample(buf, fp) = &mut sample;
let _ = host
.serialize_uncompressed_into_slice(fp, buf, 1, "test")
.serialize_uncompressed_into_slice::<FP_SERIALIZED_SIZE, _>(fp, buf, "test")
.unwrap();
black_box(Some(sample))
}
Expand Down Expand Up @@ -282,7 +283,7 @@ impl CostRunner for Bls12381DecodeFpRun {
) -> Self::RecycledType {
let Bls12381DecodeFpSample(buf) = &sample;
let res = host
.deserialize_uncompessed_no_validate(buf, 1, "test")
.deserialize_uncompessed_no_validate::<FP_SERIALIZED_SIZE, _>(buf, "test")
.unwrap();
black_box((Some(sample), Some(res)))
}
Expand Down
Loading

0 comments on commit 6eff233

Please sign in to comment.