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

Scroll Axiom Keccak diffs #6

Draft
wants to merge 7 commits into
base: scroll-split-files
Choose a base branch
from

Conversation

naure
Copy link

@naure naure commented Apr 11, 2023

This PR displays the differences from Axiom’s code to PSE/Scroll code of the Keccak circuit. It contains a set of .diff files, generated by a script (also included).

Scope

Summary of Differences

  • Challenge API. Axiom and PSE have different variants of the "multiphase" or "challenge" concept.
    • Axiom uses separate functions for phase1 and phase2, rather than a single function in PSE.
    • PSE uses two challenges, shared with other circuits (evm_word, keccak_input).
  • Computation of input RLC (data_rlc). Similar idea but different code. PSE#1330.
  • Simplification of the function arguments in split and WordParts.
  • Different interface. PSE uses the SubCircuit trait in particular.
  • In PSE, the KeccakTable is defined in a central table.rs shared with other circuits.
  • PSE split from one file to multiple files.
  • PSE has minor refactoring around the constant functions (get_num_bits_per_absorb_lookup, variable KECCAK_DEGREE, etc).
  • PSE introduced new unittests since the fork (also more in PRs pending merge).
  • Axiom copied the non-keccak dependency code from PSE zkevm-circuits into a util module (eth_types, etc).
  • Adjustments to imports and item visibilities.

Entry-points and example usage

Axiom

    // Configure.
    let config = KeccakCircuitConfig::new(
        meta,                       // ConstraintSystem
        challenge,                  // Challenge
    );

    // Synthesize.
    config.load_aux_tables(&mut layouter)?;
    let mut challenge = layouter.get_challenge(config.challenge);
    let mut first_pass = true;
    layouter.assign_region(
        || "keccak circuit",
        |mut region| {
            if first_pass {
                first_pass = false;
                return Ok(());
            }
            let (witness, squeeze_digests) = multi_keccak_phase0(&self.inputs, self.capacity());
            config.assign(&mut region, &witness);

            #[cfg(feature = "halo2-axiom")]
            {
                region.next_phase();
                challenge = region.get_challenge(config.challenge);
            }
            multi_keccak_phase1(
                &mut region,
                &config.keccak_table,
                self.inputs.iter().map(|v| v.as_slice()),
                challenge,
                squeeze_digests,
            );
            Ok(())
        },
    )?;

Scroll

    // Configure.
    let config = KeccakCircuitConfig::new(
        meta,                       // ConstraintSystem
        KeccakCircuitConfigArgs {
            keccak_table,           // KeccakTable
            challenges,             // Challenges<Expression<F>>
        },
    );

    // Synthesize.
    let circuit = KeccakCircuit::new(
        num_rows,
        inputs,                     // Vec<Vec<u8>>
    );
    circuit.synthesize_sub(
        &config,
        &challenges,                // Challenges<Value<F>>
        &mut layouter,              // Layouter<F>
    )?;

@naure naure closed this Apr 11, 2023
@naure naure reopened this Apr 11, 2023
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.

1 participant