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

Remove blobbasefee from block header #100

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions evm_arithmetization/src/cpu/kernel/asm/memory/metadata.asm
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,6 @@ global sys_chainid:
%mload_global_metadata(@GLOBAL_METADATA_BLOCK_BASE_FEE)
%endmacro

%macro blobbasefee
%mload_global_metadata(@GLOBAL_METADATA_BLOCK_BLOB_BASE_FEE)
%endmacro

global sys_basefee:
// stack: kexit_info
%charge_gas_const(@GAS_BASE)
Expand Down Expand Up @@ -318,7 +314,7 @@ global sys_blobbasefee:
// stack: kexit_info
%charge_gas_const(@GAS_BASE)
// stack: kexit_info
%blobbasefee
PROVER_INPUT(blobbasefee)
// stack: blobbasefee, kexit_info
SWAP1
EXIT_KERNEL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub(crate) enum GlobalMetadata {
BlockGasLimit,
BlockChainId,
BlockBaseFee,
BlockBlobBaseFee,
BlockBlobGasUsed,
BlockExcessBlobGas,
BlockGasUsed,
Expand Down Expand Up @@ -115,7 +114,7 @@ pub(crate) enum GlobalMetadata {
}

impl GlobalMetadata {
pub(crate) const COUNT: usize = 56;
pub(crate) const COUNT: usize = 55;

/// Unscales this virtual offset by their respective `Segment` value.
pub(crate) const fn unscale(&self) -> usize {
Expand Down Expand Up @@ -146,7 +145,6 @@ impl GlobalMetadata {
Self::BlockChainId,
Self::BlockBaseFee,
Self::BlockGasUsed,
Self::BlockBlobBaseFee,
Self::BlockBlobGasUsed,
Self::BlockExcessBlobGas,
Self::BlockGasUsedBefore,
Expand Down Expand Up @@ -207,7 +205,6 @@ impl GlobalMetadata {
Self::BlockGasLimit => "GLOBAL_METADATA_BLOCK_GAS_LIMIT",
Self::BlockChainId => "GLOBAL_METADATA_BLOCK_CHAIN_ID",
Self::BlockBaseFee => "GLOBAL_METADATA_BLOCK_BASE_FEE",
Self::BlockBlobBaseFee => "GLOBAL_METADATA_BLOCK_BLOB_BASE_FEE",
Self::BlockBlobGasUsed => "GLOBAL_METADATA_BLOCK_BLOB_GAS_USED",
Self::BlockExcessBlobGas => "GLOBAL_METADATA_BLOCK_EXCESS_BLOB_GAS",
Self::BlockGasUsed => "GLOBAL_METADATA_BLOCK_GAS_USED",
Expand Down
7 changes: 6 additions & 1 deletion evm_arithmetization/src/cpu/kernel/constants/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,15 @@ const MAX_NONCE: (&str, u64) = ("MAX_NONCE", 0xffffffffffffffff);
const CALL_STACK_LIMIT: (&str, u64) = ("CALL_STACK_LIMIT", 1024);

/// Cancun-related constants
/// See <https://eips.ethereum.org/EIPS/eip-4788#deployment>.
/// See <https://eips.ethereum.org/EIPS/eip-4788> and
/// <https://eips.ethereum.org/EIPS/eip-4844>.
pub mod cancun_constants {
use super::*;

pub const BLOB_BASE_FEE_UPDATE_FRACTION: U256 = U256([0x32f0ed, 0, 0, 0]);

pub const MIN_BLOB_BASE_FEE: U256 = U256::one();

pub const BEACON_ROOTS_ADDRESS: (&str, [u8; 20]) = (
"BEACON_ROOTS_ADDRESS",
hex!("000F3df6D732807Ef1319fB7B8bB8522d0Beac02"),
Expand Down
4 changes: 0 additions & 4 deletions evm_arithmetization/src/cpu/kernel/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@ impl<F: Field> Interpreter<F> {
(GlobalMetadata::BlockGasLimit, metadata.block_gaslimit),
(GlobalMetadata::BlockChainId, metadata.block_chain_id),
(GlobalMetadata::BlockBaseFee, metadata.block_base_fee),
(
GlobalMetadata::BlockBlobBaseFee,
metadata.block_blob_base_fee,
),
(
GlobalMetadata::BlockCurrentHash,
h2u(inputs.block_hashes.cur_hash),
Expand Down
4 changes: 0 additions & 4 deletions evm_arithmetization/src/generation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,6 @@ fn apply_metadata_and_tries_memops<F: RichField + Extendable<D>, const D: usize>
h2u(inputs.block_hashes.cur_hash),
),
(GlobalMetadata::BlockGasUsed, metadata.block_gas_used),
(
GlobalMetadata::BlockBlobBaseFee,
metadata.block_blob_base_fee,
),
(
GlobalMetadata::BlockBlobGasUsed,
metadata.block_blob_gas_used,
Expand Down
28 changes: 28 additions & 0 deletions evm_arithmetization/src/generation/prover_input.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::mem::transmute;
use std::cmp::min;
use std::collections::{BTreeSet, HashMap};
use std::str::FromStr;

Expand All @@ -9,6 +10,9 @@ use num_bigint::BigUint;
use plonky2::field::types::Field;
use serde::{Deserialize, Serialize};

use crate::cpu::kernel::constants::cancun_constants::{
BLOB_BASE_FEE_UPDATE_FRACTION, MIN_BLOB_BASE_FEE,
};
use crate::cpu::kernel::constants::context_metadata::ContextMetadata;
use crate::cpu::kernel::constants::global_metadata::GlobalMetadata;
use crate::cpu::kernel::interpreter::simulate_cpu_and_get_user_jumps;
Expand Down Expand Up @@ -48,6 +52,7 @@ impl<F: Field> GenerationState<F> {
"sf" => self.run_sf(input_fn),
"ffe" => self.run_ffe(input_fn),
"rlp" => self.run_rlp(),
"blobbasefee" => self.run_blobbasefee(),
"current_hash" => self.run_current_hash(),
"account_code" => self.run_account_code(),
"bignum_modmul" => self.run_bignum_modmul(),
Expand Down Expand Up @@ -136,6 +141,15 @@ impl<F: Field> GenerationState<F> {
.ok_or(ProgramError::ProverInputError(OutOfRlpData))
}

fn run_blobbasefee(&mut self) -> Result<U256, ProgramError> {
let excess_blob_gas = self.inputs.block_metadata.block_excess_blob_gas;
Ok(fake_exponential(
MIN_BLOB_BASE_FEE,
excess_blob_gas,
BLOB_BASE_FEE_UPDATE_FRACTION,
))
}

fn run_current_hash(&mut self) -> Result<U256, ProgramError> {
Ok(U256::from_big_endian(&self.inputs.block_hashes.cur_hash.0))
}
Expand Down Expand Up @@ -829,3 +843,17 @@ fn modexp(x: U256, e: U256, n: U256) -> Result<U256, ProgramError> {

Ok(product)
}

/// See EIP-4844: <https://eips.ethereum.org/EIPS/eip-4844#helpers>.
fn fake_exponential(factor: U256, numerator: U256, denominator: U256) -> U256 {
let mut i = 1;
let mut output = U256::zero();
let mut numerator_accum = factor * denominator;
while !numerator_accum.is_zero() {
output += numerator_accum;
numerator_accum *= numerator; // (denominator * i)
i += 1;
}

output // denominator
}
10 changes: 1 addition & 9 deletions evm_arithmetization/src/recursive_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ pub(crate) fn get_memory_extra_looking_sum_circuit<F: RichField + Extendable<D>,
// This contains the `block_beneficiary`, `block_random`, `block_base_fee`,
// `block_blob_base_fee`, `block_blob_gas_used`, `block_excess_blob_gas`,
// `parent_beacon_block_root` as well as `cur_hash`.
let block_fields_arrays: [(GlobalMetadata, &[Target]); 8] = [
let block_fields_arrays: [(GlobalMetadata, &[Target]); 7] = [
(
GlobalMetadata::BlockBeneficiary,
&public_values.block_metadata.block_beneficiary,
Expand All @@ -392,10 +392,6 @@ pub(crate) fn get_memory_extra_looking_sum_circuit<F: RichField + Extendable<D>,
GlobalMetadata::BlockBaseFee,
&public_values.block_metadata.block_base_fee,
),
(
GlobalMetadata::BlockBlobBaseFee,
&public_values.block_metadata.block_blob_base_fee,
),
(
GlobalMetadata::BlockBlobGasUsed,
&public_values.block_metadata.block_blob_gas_used,
Expand Down Expand Up @@ -800,10 +796,6 @@ where
block_metadata_target.block_gas_used,
u256_to_u32(block_metadata.block_gas_used)?,
);
// BlobBaseFee fits in 2 limbs
let blob_basefee = u256_to_u64(block_metadata.block_blob_base_fee)?;
witness.set_target(block_metadata_target.block_blob_base_fee[0], blob_basefee.0);
witness.set_target(block_metadata_target.block_blob_base_fee[1], blob_basefee.1);
// BlobGasUsed fits in 2 limbs
let blob_gas_used = u256_to_u64(block_metadata.block_blob_gas_used)?;
witness.set_target(
Expand Down
8 changes: 0 additions & 8 deletions evm_arithmetization/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@ where
GlobalMetadata::BlockGasUsed,
public_values.block_metadata.block_gas_used,
),
(
GlobalMetadata::BlockBlobBaseFee,
public_values.block_metadata.block_blob_base_fee,
),
(
GlobalMetadata::BlockBlobGasUsed,
public_values.block_metadata.block_blob_gas_used,
Expand Down Expand Up @@ -351,10 +347,6 @@ pub(crate) mod debug_utils {
GlobalMetadata::BlockGasUsed,
public_values.block_metadata.block_gas_used,
),
(
GlobalMetadata::BlockBlobBaseFee,
public_values.block_metadata.block_blob_base_fee,
),
(
GlobalMetadata::BlockBlobGasUsed,
public_values.block_metadata.block_blob_gas_used,
Expand Down