Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check block_timestamp always increases. #638

Merged
merged 4 commits into from
Sep 19, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions evm_arithmetization/src/fixed_recursive_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
{
Expand Down Expand Up @@ -1423,6 +1430,17 @@ where
}
}

fn check_block_timestamp(
builder: &mut CircuitBuilder<F, D>,
prev_timestamp: Target,
timestamp: Target,
) {
// We check that timestamp >= prev_timestamp.
// In other words, we range-check `diff = timestamp - prev_timestamp`
// between 0 and 2ˆ32.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// between 0 and 2ˆ32.
// 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<F, D>,
pvs: &ExtraBlockDataTarget,
Expand Down
Loading