From 466191b06f6d940ebe0430943519d31e16a0c3fe Mon Sep 17 00:00:00 2001 From: Linda Guiga <101227802+LindaGuiga@users.noreply.github.com> Date: Thu, 19 Sep 2024 17:36:22 +0200 Subject: [PATCH] Check block_timestamp always increases. (#638) * Check block timestamp increases * Apply comment * Update comment * Update comment --- .../src/fixed_recursive_verifier.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index 459e33c93..7f3842826 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -1378,6 +1378,13 @@ where agg_pv.extra_block_data, ); + // Check that the paent block's timestamp is less than the current block's. + Self::check_block_timestamp( + &mut builder, + parent_pv.block_metadata.block_timestamp, + agg_pv.block_metadata.block_timestamp, + ); + // Connect the burn address targets. #[cfg(feature = "cdk_erigon")] { @@ -1420,6 +1427,17 @@ where } } + fn check_block_timestamp( + builder: &mut CircuitBuilder, + prev_timestamp: Target, + timestamp: Target, + ) { + // We check that timestamp >= prev_timestamp. + // In other words, we range-check `diff = timestamp - prev_timestamp` + // is between 0 and 2ˆ32. + let diff = builder.sub(timestamp, prev_timestamp); + builder.range_check(diff, 32); + } fn connect_extra_public_values( builder: &mut CircuitBuilder, pvs: &ExtraBlockDataTarget,