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

PI refactor

PI refactor #198

Triggered via pull request September 2, 2023 18:07
Status Failure
Total duration 23s
Artifacts

openai-review.yml

on: pull_request
OpenAI PR Comment
11s
OpenAI PR Comment
Fit to window
Zoom out
Zoom in

Annotations

2 errors
OpenAI PR Comment
Unable to process file command 'env' successfully.
OpenAI PR Comment
Invalid format 'GIT_PATCH_OUTPUT=From bcae2ed188cdb856b758bf67a5aeee15b1534157 Mon Sep 17 00:00:00 2001 From: Cecilia Zhang <[email protected]> Date: Sun, 30 Jul 2023 23:03:05 +0200 Subject: [PATCH 01/22] init --- Cargo.lock | 1 + gadgets/src/util.rs | 46 + zkevm-circuits/Cargo.toml | 1 + zkevm-circuits/src/circuit_tools.rs | 9 + .../src/circuit_tools/cached_region.rs | 233 +++ .../src/circuit_tools/cell_manager.rs | 477 +++++ .../src/circuit_tools/constraint_builder.rs | 1643 +++++++++++++++++ zkevm-circuits/src/circuit_tools/gadgets.rs | 168 ++ zkevm-circuits/src/circuit_tools/memory.rs | 322 ++++ .../src/circuit_tools/test/database.rs | 152 ++ zkevm-circuits/src/circuit_tools/test/mod.rs | 308 +++ .../circuit_tools/test/query_and_branch.rs | 154 ++ .../src/circuit_tools/test/shuffle.rs | 192 ++ .../src/circuit_tools/test/simple_rlp.rs | 78 + zkevm-circuits/src/keccak_circuit.rs | 2 +- zkevm-circuits/src/lib.rs | 1 + zkevm-circuits/src/taiko_pi_circuit.rs | 56 +- 17 files changed, 3835 insertions(+), 8 deletions(-) create mode 100644 zkevm-circuits/src/circuit_tools.rs create mode 100644 zkevm-circuits/src/circuit_tools/cached_region.rs create mode 100644 zkevm-circuits/src/circuit_tools/cell_manager.rs create mode 100644 zkevm-circuits/src/circuit_tools/constraint_builder.rs create mode 100644 zkevm-circuits/src/circuit_tools/gadgets.rs create mode 100644 zkevm-circuits/src/circuit_tools/memory.rs create mode 100644 zkevm-circuits/src/circuit_tools/test/database.rs create mode 100644 zkevm-circuits/src/circuit_tools/test/mod.rs create mode 100644 zkevm-circuits/src/circuit_tools/test/query_and_branch.rs create mode 100644 zkevm-circuits/src/circuit_tools/test/shuffle.rs create mode 100644 zkevm-circuits/src/circuit_tools/test/simple_rlp.rs diff --git a/Cargo.lock b/Cargo.lock index d4746e56aa..4062cc942f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5417,6 +5417,7 @@ dependencies = [ "mock", "num", "num-bigint", + "num_enum", "once_cell", "pretty_assertions", "rand", diff --git a/gadgets/src/util.rs b/gadgets/src/util.rs index e0bfcaa6f1..8ff5e3bcec 100644 --- a/gadgets/src/util.rs +++ b/gadgets/src/util.rs @@ -141,6 +141,35 @@ pub mod select { } } +/// Trait that implements functionality to get a scalar from +/// commonly used types. +pub trait Scalar<F: Field> { + /// Returns a scalar for the type. + fn scalar(&self) -> F; +} + +/// Implementation trait `Scalar` for type able to be casted to u64 +#[macro_export] +macro_rules! impl_scalar { + ($type:ty) => { + impl<F: eth_types::Field> $crate::util::Scalar<F> for $type { + #[inline] + fn scalar(&self) -> F { + F::from(*self as u64) + } + } + }; + ($type:ty, $method:path) => { + impl<F: eth_types::Field> $crate::util::Scalar<F> for $type { + #[inline] + fn scalar(&self) -> F { + F::from($method(self) as u64) + } + } + }; +} + + /// Trait that implements functionality to get a constant expression from /// commonly used types. pub trait Expr<F: Field> { @@ -152,6 +181,7 @@ pub trait Expr<F: Field> { #[macro_export] macro_rules! impl_expr { ($type:ty) => { + $crate::impl_scalar!($type); impl<F: eth_types::Field> $crate::util::Expr<F> for $type { #[inline] fn expr(&self) -> Expression<F> { @@ -160,6 +190,7 @@ macro_rules! impl_expr { } }; ($type:ty, $method:path) => { + $crate::impl_scalar!($type, $method); impl<F: eth_types::Field> $crate::util::Expr<F> for $type { #[inline] fn expr(&self) -> Expression<F> { @@ -173,9 +204,24 @@ impl_expr!(bool); impl_expr!(u8); impl_expr!(u64); impl_expr!(usize); +impl_expr!(isize); impl_expr!(OpcodeId, OpcodeId::as_u8); impl_expr!(GasCost, GasCost::as_u64); +impl<F: Field> Scalar<F> for i32 { + #[inline] + fn scalar(&self) -> F { + F::from(self.unsigned_abs() as u64) CONTRIBUTING.md Cargo.lock Cargo.toml Makefile README.md bus-mapping circuit-benchmarks eth-types external-tracer gadgets geth-utils integration-tests keccak256 mock rust-toolchain rustfmt.toml testool zkevm-circuits if self.is_negative() { -F::ONE } else { F::ONE } + } +} + +impl<F: Field> Scalar<F> for &F { + #[inline] + fn scalar(&self) -> F { + *(*self) + } +} + i