Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

✨ add EC and modexp precompiles #143

Open
wants to merge 4 commits into
base: dl-precompiles
Choose a base branch
from

Conversation

NikitaMasych
Copy link

What ❔

Add tests for ECMul, ECAdd, ECPairing and Modexp.

Why ❔

The above were absent.

Checklist

  • PR title corresponds to the body of PR (we generate changelog entries from PRs).
  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • Code has been formatted via zk fmt and zk lint.

>(
builder: CsBuilder<T, F, GC, TB>,
) -> CsBuilder<T, F, impl GateConfigurationHolder<F>, impl StaticToolboxHolder> {
// TODO: Maybe some gates are not actually needed since it was copy-pasting from the previous secp256k1 ecmul implementation.
Copy link
Contributor

Choose a reason for hiding this comment

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

you can check if this is the case or not by running a full proof of the circuit and then printing the gate stats - it should give you a tally of how often each gate is called

(Some(TARGET_CIRCUIT_TRACE_LENGTH), Some(1 << 26))
}

fn add_tables<CS: ConstraintSystem<F>>(cs: &mut CS) {
Copy link
Contributor

Choose a reason for hiding this comment

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

are any of these tables actually necessary? i thought ecadd only uses gates and it seems useless to add byte splits, bitwise ops and fixed base muls

(Some(TARGET_CIRCUIT_TRACE_LENGTH), Some(1 << 26))
}

fn add_tables<CS: ConstraintSystem<F>>(cs: &mut CS) {
Copy link
Contributor

Choose a reason for hiding this comment

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

i assume it's the same case with gates and tables here but these should be checked and removed before merging on each new circuit

Comment on lines +117 to +119
ECAdd(T),
ECMul(T),
ECPairing(T),
Copy link
Contributor

Choose a reason for hiding this comment

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

i think its best to keep the order of when the circuit was added, so they should be at the bottom of the list, it will break backwards compatibility with the old numeric_circuit_types

Comment on lines +143 to +145
ZkSyncBaseLayerStorage::ECAdd(..) => "Elliptic Curve points addition",
ZkSyncBaseLayerStorage::ECMul(..) => "Elliptic Curve point multiplication by a scalar",
ZkSyncBaseLayerStorage::ECPairing(..) => "Elliptic Curve pairing on BN254",
Copy link
Contributor

Choose a reason for hiding this comment

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

same goes then for all these instances of course

Comment on lines 285 to 313
match el {
ZkSyncBaseLayerCircuit::ECAdd(_) => {
base_test_circuit(el);
}
_ => {
continue;
}
}
// base_test_circuit(el);
Copy link
Contributor

Choose a reason for hiding this comment

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

ensure this is changed back before merging

@jules jules changed the base branch from v1.5.0 to dl-precompiles May 25, 2024 14:16
@NikitaMasych NikitaMasych force-pushed the feature/ec-and-modexp-precompiles branch from 370c42a to 12a6b87 Compare May 27, 2024 17:42
@NikitaMasych
Copy link
Author

Rebased to dl-precompiles

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants