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

fix: fields fromstring not working as intended #7365

Conversation

sklppy88
Copy link
Contributor

@sklppy88 sklppy88 commented Jul 5, 2024

Please read contributing guidelines and remove this line.

Copy link
Contributor Author

sklppy88 commented Jul 5, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @sklppy88 and the rest of your teammates on Graphite Graphite

@sklppy88 sklppy88 changed the title init fix: fields fromstring not working add failing test case Jul 5, 2024
@sklppy88 sklppy88 force-pushed the ek/fix/7364/fields-fromstring-not-working-add-failing-test-case branch from 1340658 to f7e0d07 Compare July 5, 2024 15:02
@AztecBot
Copy link
Collaborator

AztecBot commented Jul 5, 2024

Benchmark results

Metrics with a significant change:

  • proof_construction_time_sha256_100_ms (16): 5,418 (-17%)
  • avm_simulation_time_ms (Token:mint_public): 67.6 (-81%)
  • avm_simulation_time_ms (Token:assert_minter_and_mint): 92.9 (+47%)
  • avm_simulation_time_ms (Token:transfer_public): 28.2 (-30%)
  • avm_simulation_time_ms (Token:_increase_public_balance): 65.1 (+335%)
  • app_circuit_proving_time_in_ms (AuthRegistry:set_authorized (avm)): 1,759 (+27%)
  • app_circuit_proving_time_in_ms (FPC:pay_refund (avm)): 17,824 (-26%)
  • protocol_circuit_proving_time_in_ms (root-parity): 33,695 (-18%)
  • protocol_circuit_proving_time_in_ms (public-kernel-setup): 36,574 (-17%)
  • protocol_circuit_proving_time_in_ms (public-kernel-teardown): 36,679 (-19%)
  • protocol_circuit_proving_time_in_ms (root-rollup): 19,697 (-17%)
Detailed results

All benchmarks are run on txs on the Benchmarking contract on the repository. Each tx consists of a batch call to create_note and increment_balance, which guarantees that each tx has a private call, a nested private call, a public call, and a nested public call, as well as an emitted private note, an unencrypted log, and public storage read and write.

This benchmark source data is available in JSON format on S3 here.

Proof generation

Each column represents the number of threads used in proof generation.

Metric 1 threads 4 threads 16 threads 32 threads 64 threads
proof_construction_time_sha256_ms 5,714 1,540 702 740 (-3%) 775 (+1%)
proof_construction_time_sha256_30_ms 11,724 3,144 1,405 1,436 1,470 (+1%)
proof_construction_time_sha256_100_ms 43,709 11,743 ⚠️ 5,418 (-17%) 5,435 5,337 (-1%)
proof_construction_time_poseidon_hash_ms 78.0 34.0 35.0 (+3%) 57.0 (-2%) 89.0 (+2%)
proof_construction_time_poseidon_hash_30_ms 1,515 415 (-1%) 199 229 (+2%) 266 (-1%)
proof_construction_time_poseidon_hash_100_ms 5,656 (+1%) 1,516 675 713 (-1%) 746

L2 block published to L1

Each column represents the number of txs on an L2 block published to L1.

Metric 4 txs 8 txs 16 txs
l1_rollup_calldata_size_in_bytes 1,412 1,412 1,412
l1_rollup_calldata_gas 9,452 9,472 9,476
l1_rollup_execution_gas 613,480 613,651 613,806
l2_block_processing_time_in_ms 760 1,422 (+1%) 2,705 (-1%)
l2_block_building_time_in_ms 12,879 (-1%) 25,488 49,778 (-1%)
l2_block_rollup_simulation_time_in_ms 12,878 (-1%) 25,488 49,777 (-1%)
l2_block_public_tx_process_time_in_ms 10,822 (-1%) 23,264 47,537 (-1%)

L2 chain processing

Each column represents the number of blocks on the L2 chain where each block has 8 txs.

Metric 3 blocks 5 blocks
node_history_sync_time_in_ms 7,048 9,950 (-1%)
node_database_size_in_bytes 12,447,824 16,248,912
pxe_database_size_in_bytes 16,254 26,813

Circuits stats

Stats on running time and I/O sizes collected for every kernel circuit run across all benchmarks.

Circuit simulation_time_in_ms witness_generation_time_in_ms proving_time_in_ms input_size_in_bytes output_size_in_bytes proof_size_in_bytes num_public_inputs size_in_gates
private-kernel-init 109 (-2%) 413 (+4%) 14,020 (-4%) 20,002 55,022 74,208 2,252 524,288
private-kernel-inner 222 744 (+5%) 26,836 (-7%) 82,134 55,022 74,208 2,252 1,048,576
private-kernel-tail 1,059 (-1%) 2,565 (+2%) 49,887 (-7%) 62,409 62,089 14,944 400 2,097,152
base-parity 6.35 (+1%) 892 (+1%) 2,481 (-6%) 160 96.0 2,240 3.00 131,072
root-parity 70.7 (+1%) 59.6 (-20%) ⚠️ 33,695 (-18%) 27,868 96.0 2,752 19.0 2,097,152
base-rollup 4,126 (-1%) 5,057 (+3%) 81,129 (-12%) 172,028 632 3,552 44.0 4,194,304
root-rollup 128 (+1%) 73.6 (-17%) ⚠️ 19,697 (-17%) 25,053 652 3,488 42.0 1,048,576
public-kernel-setup 189 (-1%) 2,339 (-2%) ⚠️ 36,574 (-17%) 103,911 80,310 106,944 3,275 2,097,152
public-kernel-app-logic 145 (-1%) 3,339 36,569 (-12%) 103,911 80,310 106,944 3,275 2,097,152
public-kernel-tail 893 26,252 (+8%) 158,416 (-12%) 400,808 10,046 14,944 400 8,388,608
private-kernel-reset-small 292 1,170 (+3%) 25,909 79,273 55,022 74,208 2,252 1,048,576
public-kernel-teardown 134 3,328 (-1%) ⚠️ 36,679 (-19%) 103,911 80,310 106,944 3,275 2,097,152
merge-rollup 40.1 (-1%) N/A N/A 16,094 632 N/A N/A N/A
private-kernel-tail-to-public N/A 8,824 (-4%) 53,599 (-13%) N/A N/A 106,944 3,275 2,097,152

Stats on running time collected for app circuits

Function input_size_in_bytes output_size_in_bytes witness_generation_time_in_ms proof_size_in_bytes proving_time_in_ms size_in_gates num_public_inputs
ContractClassRegisterer:register 1,312 9,344 394 N/A N/A N/A N/A
ContractInstanceDeployer:deploy 1,376 9,344 25.0 (+1%) N/A N/A N/A N/A
MultiCallEntrypoint:entrypoint 1,888 9,344 649 (+1%) N/A N/A N/A N/A
GasToken:deploy 1,344 9,344 570 (+3%) N/A N/A N/A N/A
SchnorrAccount:constructor 1,280 9,344 486 (+1%) N/A N/A N/A N/A
SchnorrAccount:entrypoint 2,272 9,344 824 15,840 4,955 (+5%) 131,072 428
Token:privately_mint_private_note 1,248 9,344 568 (+4%) N/A N/A N/A N/A
FPC:fee_entrypoint_public 1,312 9,344 107 (+2%) 15,840 1,898 (+11%) 65,536 428
Token:transfer 1,280 9,344 1,663 (+1%) 15,840 10,358 (-11%) 524,288 428
AuthRegistry:set_authorized (avm) 19,222 N/A N/A 91,232 ⚠️ 1,759 (+27%) N/A N/A
FPC:prepare_fee (avm) 26,664 N/A N/A 91,296 3,060 (+4%) N/A N/A
Token:transfer_public (avm) 42,914 N/A N/A 91,296 3,711 (-6%) N/A N/A
AuthRegistry:consume (avm) 33,100 N/A N/A 91,232 3,016 (+9%) N/A N/A
FPC:pay_refund (avm) 36,829 N/A N/A 91,264 ⚠️ 17,824 (-26%) N/A N/A
Benchmarking:create_note 1,312 9,344 470 N/A N/A N/A N/A
SchnorrAccount:verify_private_authwit 1,248 9,344 41.1 N/A N/A N/A N/A
Token:unshield 1,344 9,344 1,333 (-1%) N/A N/A N/A N/A
FPC:fee_entrypoint_private 1,344 9,344 1,742 (+1%) N/A N/A N/A N/A

AVM Simulation

Time to simulate various public functions in the AVM.

Function time_ms bytecode_size_in_bytes
GasToken:_increase_public_balance 82.5 (+3%) 13,790
GasToken:set_portal 12.5 (-18%) 3,339
Token:constructor 103 (+1%) 23,692
FPC:constructor 75.8 (+4%) 13,592
GasToken:mint_public 64.2 (+2%) 10,158
Token:mint_public ⚠️ 67.6 (-81%) 19,034
Token:assert_minter_and_mint ⚠️ 92.9 (+47%) 12,925
AuthRegistry:set_authorized 33.4 (-3%) 7,812
FPC:prepare_fee 99.9 (-3%) 15,062
Token:transfer_public ⚠️ 28.2 (-30%) 31,218
FPC:pay_refund 129 (+2%) 25,260
Benchmarking:increment_balance 1,315 (-1%) 15,267
Token:_increase_public_balance ⚠️ 65.1 (+335%) 15,006
FPC:pay_refund_with_shielded_rebate 116 (-28%) 26,347

Public DB Access

Time to access various public DBs.

Function time_ms
get-nullifier-index 0.158 (+2%)

Tree insertion stats

The duration to insert a fixed batch of leaves into each tree type.

Metric 1 leaves 16 leaves 64 leaves 128 leaves 256 leaves 512 leaves 1024 leaves
batch_insert_into_append_only_tree_16_depth_ms 10.4 (+1%) 16.8 (+1%) N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_count 16.8 31.7 N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_ms 0.603 (+1%) 0.518 (+1%) N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_32_depth_ms N/A N/A 48.4 (+1%) 76.2 (+1%) 132 (+1%) 246 471
batch_insert_into_append_only_tree_32_depth_hash_count N/A N/A 95.9 159 287 543 1,055
batch_insert_into_append_only_tree_32_depth_hash_ms N/A N/A 0.495 (+1%) 0.468 (+1%) 0.453 0.445 0.439
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 59.7 112 (+1%) 183 (+1%) 354 693
batch_insert_into_indexed_tree_20_depth_hash_count N/A N/A 109 207 355 691 1,363
batch_insert_into_indexed_tree_20_depth_hash_ms N/A N/A 0.504 0.502 (+1%) 0.482 0.480 0.477
batch_insert_into_indexed_tree_40_depth_ms N/A N/A 73.2 (+1%) N/A N/A N/A N/A
batch_insert_into_indexed_tree_40_depth_hash_count N/A N/A 133 N/A N/A N/A N/A
batch_insert_into_indexed_tree_40_depth_hash_ms N/A N/A 0.521 (+1%) N/A N/A N/A N/A

Miscellaneous

Transaction sizes based on how many contract classes are registered in the tx.

Metric 0 registered classes 1 registered classes
tx_size_in_bytes 74,082 667,868

Transaction size based on fee payment method

| Metric | |
| - | |

const arbitraryHexString = '0x123';
const expectedBigInt = 291n;

expect(GrumpkinScalar.fromString(arbitraryString).toBigInt()).toEqual(expectedBigInt);
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't arbitary string resolve to 123 and not 291?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's always resolved as hex currently, regardless of whether it's prefixed or not. Do we want to change the base behavior ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The base issue was that any string was getting truncated if it was an odd length.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm can we make it clear then that fromString expects a hex string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, added the comment as you specified in scrum, and refactored the check because the check didn't actually work for a hexstring like 12xx34xx56.

Copy link
Contributor

Choose a reason for hiding this comment

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

@sklppy88 can this problem get revised? I am hitting this issue in a deep object, so i cant easily convert all my strings to hex format

Copy link
Contributor Author

@sklppy88 sklppy88 Oct 25, 2024

Choose a reason for hiding this comment

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

Hello @olehmisar: I haven't had the green light to change the current behavior, but will your problem be alleviated if I add a param for you to specify the encoding ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See here, would this fix your problem ?

Copy link
Contributor

@olehmisar olehmisar Oct 25, 2024

Choose a reason for hiding this comment

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

@sklppy88 i am have to do something like this:

encodeArguments(abi, args.map((arg) => {
  if (Number.isFinite(Number(arg))) {
    return new Fr(BigInt(arg));
  }
  return arg;
}));

Now imagine that args contains a nested object or array. i will have to iterate over each object deeply (prob using recursion) to convert each number into a hex string manually.

Your example won't help as it will just change:

- return new Fr(BigInt(arg));
+ return new Fr(arg, "dec");

But if you fixed the original problem, i would be able to just write this code:

encodeArguments(abi, args)

Copy link
Contributor

Choose a reason for hiding this comment

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

could you please explain the reasoning behind not wanting to change it to autodetection of decimal vs hex? For me it's such an obvious decision. What am i missing?

@sklppy88 sklppy88 force-pushed the ek/fix/7364/fields-fromstring-not-working-add-failing-test-case branch from f7e0d07 to 2ec5610 Compare July 8, 2024 20:40
@sklppy88 sklppy88 force-pushed the ek/fix/7364/fields-fromstring-not-working-add-failing-test-case branch from 2ec5610 to 337bd61 Compare July 8, 2024 21:21
Please read [contributing guidelines](CONTRIBUTING.md) and remove this
line.
@sklppy88 sklppy88 changed the title fix: fields fromstring not working add failing test case fix: fields fromstring not working Jul 9, 2024
@sklppy88 sklppy88 marked this pull request as ready for review July 9, 2024 13:49
@sklppy88 sklppy88 changed the title fix: fields fromstring not working fix: fields fromstring not working as intended Jul 9, 2024
@sklppy88 sklppy88 merged commit 633eb6b into master Jul 9, 2024
93 checks passed
@sklppy88 sklppy88 deleted the ek/fix/7364/fields-fromstring-not-working-add-failing-test-case branch July 9, 2024 13:49
@sklppy88 sklppy88 linked an issue Jul 9, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AztecJS: Fr.fromString() serialization bug returns invalid value
4 participants