Skip to content

Commit

Permalink
fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
lispc committed Mar 3, 2023
1 parent 45c2e1a commit cfc7e8b
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 236 deletions.
2 changes: 1 addition & 1 deletion circuit-benchmarks/src/tx_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod tests {
max_calldata: 2_000_000,
max_inner_blocks: 64,
max_bytecode: 3_000_000,
keccak_padding: None, // FIXME: can this be none?
max_keccak_rows: 0, // FIXME: can this be none?
max_exp_steps: 100_000,
max_evm_rows: 4_000_000,
};
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/tests/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const CIRCUITS_PARAMS: CircuitsParams = CircuitsParams {
max_calldata: 30000,
max_inner_blocks: 64,
max_bytecode: 30000,
keccak_padding: None,
max_keccak_rows: 0,
max_exp_steps: 1000,
max_evm_rows: 0,
};
Expand All @@ -46,7 +46,7 @@ async fn test_mock_prove_tx() {
max_calldata: 40000,
max_inner_blocks: 64,
max_bytecode: 40000,
keccak_padding: None,
max_keccak_rows: 0,
max_exp_steps: 5000,
max_evm_rows: 0,
};
Expand Down Expand Up @@ -111,7 +111,7 @@ async fn test_circuit_all_block() {
max_calldata: 2_000_000,
max_inner_blocks: 64,
max_bytecode: 3_000_000,
keccak_padding: None,
max_keccak_rows: 0,
max_exp_steps: 100_000,
max_evm_rows: 0,
};
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ impl<F: Field> ExecutionConfig<F> {
step_next.state.block_number.expr() - step_curr.state.block_number.expr(),
),
])
.filter(move |(_, from, _, _)| *from == G::EXECUTION_STATE)
.filter(move |(_, from, _, _)| *from == execution_state)
.map(|(_, _, to, expr)| step_next.execution_state_selector(to) * expr)
)
.chain(
Expand All @@ -827,7 +827,7 @@ impl<F: Field> ExecutionConfig<F> {
step_next.state.block_number.expr() - step_curr.state.block_number.expr(),
),
])
.filter(move |(_, from, _)| *from != G::EXECUTION_STATE)
.filter(move |(_, from, _)| *from != execution_state)
.map(|(_, _, expr)| expr)
)
// Accumulate all state transition checks.
Expand Down
174 changes: 13 additions & 161 deletions zkevm-circuits/src/evm_circuit/execution/begin_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{
param::{N_BYTES_ACCOUNT_ADDRESS, N_BYTES_GAS, N_BYTES_WORD},
step::ExecutionState,
util::{
and,
common_gadget::TransferWithGasFeeGadget,
constraint_builder::{
ConstraintBuilder, ReversionInfo, StepStateTransition,
Expand All @@ -21,10 +20,10 @@ use crate::{
table::{AccountFieldTag, CallContextFieldTag, TxFieldTag as TxContextFieldTag},
};
use eth_types::{Address, Field, ToLittleEndian, ToScalar};
use ethers_core::utils::{get_contract_address, keccak256};
use gadgets::util::expr_from_bytes;
use ethers_core::utils::{get_contract_address, keccak256, rlp::RlpStream};
use gadgets::util::{and, expr_from_bytes, not, or, Expr};
use halo2_proofs::circuit::Value;
use halo2_proofs::plonk::Error;
use halo2_proofs::{circuit::Value, plonk::Expression};

#[cfg(feature = "reject-eip2718")]
use gadgets::util::select;
Expand Down Expand Up @@ -97,15 +96,6 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
]
.map(|field_tag| cb.tx_context(tx_id.expr(), field_tag, None));

let call_callee_address = cb.query_cell();
cb.condition(not::expr(tx_is_create.expr()), |cb| {
cb.require_equal(
"Tx to non-zero address",
tx_callee_address.expr(),
call_callee_address.expr(),
);
});

let tx_caller_address_is_zero = IsZeroGadget::construct(cb, tx_caller_address.expr());
cb.require_equal(
"CallerAddress != 0 (not a padding tx)",
Expand Down Expand Up @@ -206,6 +196,8 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
// TODO: guard against call to precompiled contracts.
let is_empty_code_hash =
IsEqualGadget::construct(cb, phase2_code_hash.expr(), cb.empty_hash_rlc());
let is_zero_code_hash = IsZeroGadget::construct(cb, phase2_code_hash.expr());
let is_empty_code = or::expr([is_empty_code_hash.expr(), is_zero_code_hash.expr()]);

cb.condition(not::expr(tx_is_create.expr()), |cb| {
cb.account_read(
Expand Down Expand Up @@ -233,9 +225,6 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
tx_nonce.expr(),
create.caller_nonce(),
);




// 1. Handle contract creation transaction.
cb.condition(tx_is_create.expr(), |cb| {
Expand Down Expand Up @@ -325,7 +314,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
});
});

// TODO: 2. Handle call to precompiled contracts.
// 2. Handle call to precompiled contracts.

// a valid precompile address is: 1 <= addr <= 9 (addr != 0 && addr < 0xA)
let is_precompile_lt = LtGadget::construct(cb, tx_callee_address.expr(), 0xA.expr());
Expand All @@ -342,81 +331,6 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
);
});

// 1. Handle contract creation transaction
cb.condition(tx_is_create.expr(), |cb| {
cb.account_write(
call_callee_address.expr(),
AccountFieldTag::Nonce,
1.expr(),
0.expr(),
Some(&mut reversion_info),
);
for (field_tag, value) in [
(CallContextFieldTag::Depth, 1.expr()),
(CallContextFieldTag::CallerAddress, tx_caller_address.expr()),
(
CallContextFieldTag::CalleeAddress,
call_callee_address.expr(),
),
(CallContextFieldTag::CallDataOffset, 0.expr()),
(
CallContextFieldTag::CallDataLength,
tx_call_data_length.expr(),
),
(CallContextFieldTag::Value, tx_value.expr()),
(CallContextFieldTag::IsStatic, 0.expr()),
(CallContextFieldTag::LastCalleeId, 0.expr()),
(CallContextFieldTag::LastCalleeReturnDataOffset, 0.expr()),
(CallContextFieldTag::LastCalleeReturnDataLength, 0.expr()),
(CallContextFieldTag::IsRoot, 1.expr()),
(CallContextFieldTag::IsCreate, 1.expr()),
(
CallContextFieldTag::CodeHash,
cb.curr.state.code_hash.expr(),
),
] {
cb.call_context_lookup(true.expr(), Some(call_id.expr()), field_tag, value);
}

cb.require_step_state_transition(StepStateTransition {
// 24 reads and writes:
// - Write CallContext TxId
// - Write CallContext RwCounterEndOfReversion
// - Write CallContext IsPersistent
// - Write CallContext IsSuccess
// - Write caller Account Nonce
// - Write TxAccessListAccount
// - Write TxAccessListAccount
// - Write Account Balance (Not Reversible)
// - Write Account Balance (Reversible)
// - Write Account Balance (Reversible)
// - Write callee Account Nonce (Reversible)
// - Write CallContext Depth
// - Write CallContext CallerAddress
// - Write CallContext CalleeAddress
// - Write CallContext CallDataOffset
// - Write CallContext CallDataLength
// - Write CallContext Value
// - Write CallContext IsStatic
// - Write CallContext LastCalleeId
// - Write CallContext LastCalleeReturnDataOffset
// - Write CallContext LastCalleeReturnDataLength
// - Write CallContext IsRoot
// - Write CallContext IsCreate
// - Write CallContext CodeHash
rw_counter: Delta(24.expr()),
call_id: To(call_id.expr()),
is_root: To(true.expr()),
is_create: To(tx_is_create.expr()),
code_hash: To(cb.curr.state.code_hash.expr()),
gas_left: To(gas_left.clone()),
reversible_write_counter: To(3.expr()),
log_id: To(0.expr()),
..StepStateTransition::new_context()
});
});

// 2. Handle call to precompiled contracts.
cb.condition(is_precompile.expr(), |cb| {
cb.require_equal(
"precompile should be zero code hash",
Expand Down Expand Up @@ -508,17 +422,17 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
cb.condition(
and::expr([
not::expr(tx_is_create.expr()),
not::expr(is_empty_code_hash.expr()),
not::expr(is_empty_code.expr()),
]),
|cb| {
// Setup first call's context.
for (field_tag, value) in [
(CallContextFieldTag::Depth, 1.expr()),
(CallContextFieldTag::CallerAddress, tx_caller_address.expr()),
(
CallContextFieldTag::CalleeAddress,
call_callee_address.expr(),
),
(
CallContextFieldTag::CalleeAddress,
call_callee_address.expr(),
),
(CallContextFieldTag::CallDataOffset, 0.expr()),
(
CallContextFieldTag::CallDataLength,
Expand Down Expand Up @@ -602,7 +516,6 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
caller_nonce_hash_bytes,
create,
is_caller_callee_equal,
rlp_create,
}
}

Expand Down Expand Up @@ -647,6 +560,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
.expect("unexpected Address -> Scalar conversion failure");
let callee_address = tx
.callee_address
.unwrap_or(Address::zero())
.to_scalar()
.expect("unexpected Address -> Scalar conversion failure");
self.tx_caller_address
Expand All @@ -655,11 +569,6 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
.assign(region, offset, caller_address)?;
self.tx_callee_address
.assign(region, offset, Value::known(callee_address))?;
self.call_callee_address.assign(
.to_scalar()
.expect("unexpected Address -> Scalar conversion failure");
self.tx_callee_address
.assign(region, offset, Value::known(callee_address))?;
self.tx_callee_address_is_zero
.assign(region, offset, callee_address)?;
self.is_precompile_lt
Expand Down Expand Up @@ -731,7 +640,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
{
c.assign(region, offset, Value::known(F::from(*v as u64)))?;
}
self.rlp_create
self.create
.assign(region, offset, call.caller_address, tx.nonce, None, None)?;
self.is_empty_code_hash.assign_value(
region,
Expand Down Expand Up @@ -1099,61 +1008,4 @@ mod test {

CircuitTestBuilder::new_from_test_ctx(ctx).run();
}

#[test]
fn begin_tx_deploy_nonce_zero() {
begin_tx_deploy(0);
}
#[test]
fn begin_tx_deploy_nonce_small_1byte() {
begin_tx_deploy(1);
begin_tx_deploy(127);
}
#[test]
fn begin_tx_deploy_nonce_big_1byte() {
begin_tx_deploy(128);
begin_tx_deploy(255);
}
#[test]
fn begin_tx_deploy_nonce_2bytes() {
begin_tx_deploy(0x0100u64);
begin_tx_deploy(0x1020u64);
begin_tx_deploy(0xffffu64);
}
#[test]
fn begin_tx_deploy_nonce_3bytes() {
begin_tx_deploy(0x010000u64);
begin_tx_deploy(0x102030u64);
begin_tx_deploy(0xffffffu64);
}
#[test]
fn begin_tx_deploy_nonce_4bytes() {
begin_tx_deploy(0x01000000u64);
begin_tx_deploy(0x10203040u64);
begin_tx_deploy(0xffffffffu64);
}
#[test]
fn begin_tx_deploy_nonce_5bytes() {
begin_tx_deploy(0x0100000000u64);
begin_tx_deploy(0x1020304050u64);
begin_tx_deploy(0xffffffffffu64);
}
#[test]
fn begin_tx_deploy_nonce_6bytes() {
begin_tx_deploy(0x010000000000u64);
begin_tx_deploy(0x102030405060u64);
begin_tx_deploy(0xffffffffffffu64);
}
#[test]
fn begin_tx_deploy_nonce_7bytes() {
begin_tx_deploy(0x01000000000000u64);
begin_tx_deploy(0x10203040506070u64);
begin_tx_deploy(0xffffffffffffffu64);
}
#[test]
fn begin_tx_deploy_nonce_8bytes() {
begin_tx_deploy(0x0100000000000000u64);
begin_tx_deploy(0x1020304050607080u64);
begin_tx_deploy(0xfffffffffffffffeu64);
}
}
1 change: 0 additions & 1 deletion zkevm-circuits/src/evm_circuit/execution/error_oog_exp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGExpGadget<F> {
);

let common_error_gadget = CommonErrorGadget::construct(cb, opcode.expr(), 4.expr());
0.expr(),
Self {
opcode,
base,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ impl<F: Field> ExecutionGadget<F> for ErrorWriteProtectionGadget<F> {
);

let common_error_gadget = CommonErrorGadget::construct(cb, opcode.expr(), 0.expr());
0.expr(),

Self {
opcode,
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/util/instrumentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ pub(crate) struct Instrument {
impl Instrument {
/// Collects `CellManager` stats from a compiled EVMCircuit in order to
/// extract metrics.
pub(crate) fn on_gadget_built<'a, F: FieldExt>(
pub(crate) fn on_gadget_built<F: FieldExt>(
&mut self,
execution_state: ExecutionState,
cb: &ConstraintBuilder<'a, F>,
cb: &ConstraintBuilder<F>,
) {
let sizes = cb
.curr
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/keccak_circuit/keccak_packed_multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,8 @@ pub(crate) fn keccak<F: Field>(
.to_vec()
})
.collect::<Vec<_>>();
trace!("hash: {:x?}", &(hash_bytes[0..4].concat()));
trace!("data rlc: {:x?}", data_rlc);
trace!("hash: {:x?}", &(hash_bytes[0..4].concat()));
trace!("data rlc: {:x?}", data_rlc);
}
}

Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/keccak_circuit/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn packed_multi_keccak_simple() {

#[test]
fn variadic_size_check() {
let k = 11;
let k = 14;
let num_rows = 2usize.pow(k);
// Empty
let inputs = vec![];
Expand Down
6 changes: 6 additions & 0 deletions zkevm-circuits/src/pi_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,11 @@ mod pi_circuit_test {
halo2curves::bn256::Fr,
};
use mock::TestContext;
//use mock::MOCK_CHAIN_ID;
//use mock::CORRECT_MOCK_TXS;
use pretty_assertions::assert_eq;
//use rand_chacha::ChaCha20Rng;
//use rand::SeedableRng;

fn run<
F: Field,
Expand Down Expand Up @@ -1241,6 +1245,7 @@ mod pi_circuit_test {
);
}

/*
fn run_size_check<F: Field, const MAX_TXS: usize, const MAX_CALLDATA: usize>(
public_data: [PublicData; 2],
) {
Expand Down Expand Up @@ -1303,4 +1308,5 @@ mod pi_circuit_test {
run_size_check::<Fr, MAX_TXS, MAX_CALLDATA>([pub_dat_1, pub_dat_2]);
}
*/
}
Loading

0 comments on commit cfc7e8b

Please sign in to comment.