From 2cf31f5f2d5322f104d4c4748f09ef5e0ba96cd6 Mon Sep 17 00:00:00 2001 From: Robin Salen <30937548+Nashtare@users.noreply.github.com> Date: Tue, 6 Jun 2023 09:39:36 +0200 Subject: [PATCH] Prevent shift ops from panicking (#1073) --- evm/src/witness/operation.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/evm/src/witness/operation.rs b/evm/src/witness/operation.rs index 5241c71b..1208c27f 100644 --- a/evm/src/witness/operation.rs +++ b/evm/src/witness/operation.rs @@ -468,7 +468,12 @@ pub(crate) fn generate_shl( ) -> Result<(), ProgramError> { let [(input0, log_in0), (input1, log_in1)] = stack_pop_with_log_and_fill::<2, _>(state, &mut row)?; - let result = input1 << input0; + + let result = if input0 > U256::from(255u64) { + U256::zero() + } else { + input1 << input0 + }; append_shift(state, row, input0, log_in0, log_in1, result) } @@ -478,7 +483,12 @@ pub(crate) fn generate_shr( ) -> Result<(), ProgramError> { let [(input0, log_in0), (input1, log_in1)] = stack_pop_with_log_and_fill::<2, _>(state, &mut row)?; - let result = input1 >> input0; + + let result = if input0 > U256::from(255u64) { + U256::zero() + } else { + input1 >> input0 + }; append_shift(state, row, input0, log_in0, log_in1, result) }