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

In-circuit blockhash calculation #129

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open

In-circuit blockhash calculation #129

wants to merge 29 commits into from

Conversation

ggkitsas
Copy link

@ggkitsas ggkitsas commented Jul 26, 2023

Description

In-circuit blockhash calculation. Design documentation can be found here: https://www.notion.so/taikoxyz/In-circuit-blockhash-calculation-docs-069984cbc14446a9a1ea88387178e9ce

Important Notes

  • There are 2 Block tables - that was for streamlining the refactoring effort. Eventually we should merge the two.
  • There are 2 Keccak tables - same reason
  • code assumes there exist 256 previous blocks - that is not always correct and we should modify it to be able to work with less than 256 blocks
  • we don't have a way to get actual data for the 256 previous blocks at the moment - should be revisited
  • currently there are several structs that hold similar data and is unclear where things are (block constants, context, protocol instance, eth_block). When time allows we should really clean all this up

Re-targeting #98 to main

Issue Link

[https://github.com//issues/79]

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

@ggkitsas ggkitsas marked this pull request as ready for review August 31, 2023 13:09
@ggkitsas ggkitsas changed the title WIP: In-circuit blockhash calculation In-circuit blockhash calculation Aug 31, 2023
@ggkitsas ggkitsas requested a review from Brechtpd August 31, 2023 13:43
Copy link

@Brechtpd Brechtpd left a comment

Choose a reason for hiding this comment

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

Just some minor suggestions, otherwise looks good!

zkevm-circuits/src/taiko_pi_circuit.rs Show resolved Hide resolved
zkevm-circuits/src/taiko_pi_circuit.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/taiko_pi_circuit.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/taiko_pi_circuit.rs Show resolved Hide resolved
zkevm-circuits/src/taiko_pi_circuit.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/taiko_pi_circuit.rs Outdated Show resolved Hide resolved
zkevm-circuits/src/taiko_pi_circuit.rs Show resolved Hide resolved
Copy link
Collaborator

@smtmfft smtmfft left a comment

Choose a reason for hiding this comment

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

Just a quick through, need checking design doc to do another review.

Cargo.toml Show resolved Hide resolved
gadgets/src/less_than.rs Show resolved Hide resolved
zkevm-circuits/src/table/keccak_table.rs Show resolved Hide resolved
zkevm-circuits/src/taiko_pi_circuit.rs Show resolved Hide resolved
zkevm-circuits/src/taiko_pi_circuit.rs Outdated Show resolved Hide resolved
Comment on lines +219 to +225
let output_hi = output.iter().take(16).fold(F::ZERO, |acc, byte| {
acc * F::from(BYTE_POW_BASE) + F::from(*byte as u64)
});

let output_lo = output.iter().skip(16).fold(F::ZERO, |acc, byte| {
acc * F::from(BYTE_POW_BASE) + F::from(*byte as u64)
});

Choose a reason for hiding this comment

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

Comment on lines +1258 to +1263
let hash_hi = hash.iter().take(16).fold(F::ZERO, |acc, byte| {
acc * F::from(BYTE_POW_BASE) + F::from(*byte as u64)
});
let hash_lo = hash.iter().skip(16).fold(F::ZERO, |acc, byte| {
acc * F::from(BYTE_POW_BASE) + F::from(*byte as u64)
});

Choose a reason for hiding this comment

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

and here?

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

Successfully merging this pull request may close these issues.

4 participants