From cbec978fdc13cac3ae390f7c5b1cfbe905ed1b49 Mon Sep 17 00:00:00 2001 From: Linda Guiga Date: Wed, 18 Sep 2024 18:23:30 +0200 Subject: [PATCH 1/4] Check block timestamp increases --- .../src/fixed_recursive_verifier.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index be9a3daeb..54a2875f1 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -1381,6 +1381,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")] { @@ -1423,6 +1430,18 @@ 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 - 1` + // between 0 and 2ˆ32. + let diff = builder.sub(timestamp, prev_timestamp); + let diff = builder.add_const(diff, F::NEG_ONE); + builder.range_check(diff, 32); + } fn connect_extra_public_values( builder: &mut CircuitBuilder, pvs: &ExtraBlockDataTarget, From 7e8fcba0779436f2ff3a6682f271af30901fc789 Mon Sep 17 00:00:00 2001 From: Linda Guiga Date: Wed, 18 Sep 2024 19:40:24 +0200 Subject: [PATCH 2/4] Apply comment --- evm_arithmetization/src/fixed_recursive_verifier.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index 54a2875f1..3bd6655e5 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -1439,7 +1439,6 @@ where // In other words, we range-check `diff = timestamp - prev_timestamp - 1` // between 0 and 2ˆ32. let diff = builder.sub(timestamp, prev_timestamp); - let diff = builder.add_const(diff, F::NEG_ONE); builder.range_check(diff, 32); } fn connect_extra_public_values( From 0885d93e0f1a33de0bd8722a8cb3392de8362021 Mon Sep 17 00:00:00 2001 From: Linda Guiga Date: Wed, 18 Sep 2024 23:44:30 +0200 Subject: [PATCH 3/4] Update comment --- evm_arithmetization/src/fixed_recursive_verifier.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index 3bd6655e5..4346f1179 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -1435,8 +1435,8 @@ where prev_timestamp: Target, timestamp: Target, ) { - // We check that timestamp > prev_timestamp. - // In other words, we range-check `diff = timestamp - prev_timestamp - 1` + // We check that timestamp >= prev_timestamp. + // In other words, we range-check `diff = timestamp - prev_timestamp` // between 0 and 2ˆ32. let diff = builder.sub(timestamp, prev_timestamp); builder.range_check(diff, 32); From 7cbc658795207a0192ca9265b4f2a0cfba96dd43 Mon Sep 17 00:00:00 2001 From: Linda Guiga Date: Thu, 19 Sep 2024 17:09:51 +0200 Subject: [PATCH 4/4] Update comment --- evm_arithmetization/src/fixed_recursive_verifier.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evm_arithmetization/src/fixed_recursive_verifier.rs b/evm_arithmetization/src/fixed_recursive_verifier.rs index 4346f1179..cf67ba5e6 100644 --- a/evm_arithmetization/src/fixed_recursive_verifier.rs +++ b/evm_arithmetization/src/fixed_recursive_verifier.rs @@ -1437,7 +1437,7 @@ where ) { // We check that timestamp >= prev_timestamp. // In other words, we range-check `diff = timestamp - prev_timestamp` - // between 0 and 2ˆ32. + // is between 0 and 2ˆ32. let diff = builder.sub(timestamp, prev_timestamp); builder.range_check(diff, 32); }