Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit d3ffb46

Browse files
authored
fix gascost in modexp (#796)
1 parent 76c6a7b commit d3ffb46

File tree

1 file changed

+10
-6
lines changed
  • zkevm-circuits/src/evm_circuit/execution/precompiles

1 file changed

+10
-6
lines changed

zkevm-circuits/src/evm_circuit/execution/precompiles/modexp.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -564,13 +564,16 @@ impl<F: Field> ModExpGasCost<F> {
564564
fn construct(
565565
cb: &mut EVMConstraintBuilder<F>,
566566
b_size: &SizeRepresent<F>,
567-
exp: &[Cell<F>; N_BYTES_WORD],
567+
exp: &[Cell<F>; MODEXP_SIZE_LIMIT],
568568
m_size: &SizeRepresent<F>,
569569
) -> Self {
570570
let max_length = MinMaxGadget::construct(cb, b_size.value(), m_size.value());
571571
let words = ConstantDivisionGadget::construct(cb, max_length.max() + 7.expr(), 8);
572572
let multiplication_complexity = words.quotient() * words.quotient();
573-
let exp_is_zero = IsZeroGadget::construct(cb, expr_from_bytes(exp));
573+
let exp_is_zero = IsZeroGadget::construct(
574+
cb,
575+
rlc::expr(&exp.clone().map(|c| c.expr()), cb.challenges().evm_word()),
576+
);
574577

575578
let (exp_byte_size, exp_msb, exp_msb_bit_length) =
576579
cb.condition(not::expr(exp_is_zero.expr()), |cb| {
@@ -645,12 +648,13 @@ impl<F: Field> ModExpGasCost<F> {
645648
self.words
646649
.assign(region, offset, b_size.max(m_size).as_u128() + 7u128)?;
647650
let exp_word = U256::from_big_endian(exponent);
648-
self.exp_is_zero.assign(
651+
self.exp_is_zero.assign_value(
649652
region,
650653
offset,
651-
exp_word
652-
.to_scalar()
653-
.expect("exponent is within scalar field"),
654+
region
655+
.challenges()
656+
.evm_word()
657+
.map(|r| rlc::value(exponent, r)),
654658
)?;
655659
self.exp_byte_size
656660
.assign(region, offset, ByteOrWord::Word(exp_word))?;

0 commit comments

Comments
 (0)