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

[WIP] L1 block hashes POC #1040

Draft
wants to merge 46 commits into
base: develop
Choose a base branch
from

Conversation

vladimir-trifonov
Copy link

Description

  • Update the circuit with the two new public inputs - lastAppliedL1Block, blockRangeHash
  • Update the circuit logic to check that the lastAppliedL1Block in the block trace matches the last applied block via L1Blockhashes transaction.
  • Update the circuit to note all the blockhashes appended by L1Blockhashes in a batch and check them against the public blockRangeHash.
  • Update the circuit to check that the lastAppliedL1Block matches the last block trace lastAppliedL1Block.

Issue Link

[link issue here]

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Contents

  • [item]

Rationale

[design decisions and extended information]

How Has This Been Tested?

[explanation]


How to fill a PR description

Please give a concise description of your PR.

The target readers could be future developers, reviewers, and auditors. By reading your description, they should easily understand the changes proposed in this pull request.

MUST: Reference the issue to resolve

Single responsability

Is RECOMMENDED to create single responsibility commits, but not mandatory.

Anyway, you MUST enumerate the changes in a unitary way, e.g.

This PR contains:
- Cleanup of xxxx, yyyy
- Changed xxxx to yyyy in order to bla bla
- Added xxxx function to ...
- Refactored ....

Design choices

RECOMMENDED to:

  • What types of design choices did you face?
  • What decisions you have made?
  • Any valuable information that could help reviewers to think critically

Copy link

@roynalnaruto roynalnaruto left a comment

Choose a reason for hiding this comment

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

Completed first pass. Going through the PI circuit changes again for in-depth review. Will post asap

@@ -190,6 +190,7 @@ func Trace(config TraceConfig) (*types.BlockTrace, error) {
// Random: &randao,
BaseFee: toBigInt(config.Block.BaseFee),
GasLimit: blockGasLimit,
// TODO: add last_applied_l1_block and l1_block_hashes

Choose a reason for hiding this comment

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

TODO

Comment on lines +164 to +158
let mut num_all_l1_block_hashes_in_blocks = 0;
for block_ctx in self.block_ctxs.ctxs.values() {
if let Some(l1_block_hashes) = &block_ctx.l1_block_hashes {
num_all_l1_block_hashes_in_blocks += l1_block_hashes.len();
}
}

num_all_l1_block_hashes_in_blocks

Choose a reason for hiding this comment

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

can't we just do last_applied_l1_block - prev_last_applied_l1_block to get the same number?

Copy link
Author

Choose a reason for hiding this comment

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

we want the exact count of l1 block hashes so we can constraint it against last_applied_l1_block - prev_last_applied_l1_block

Comment on lines 175 to 164
self.block_ctxs.ctxs
.last_key_value()
.map(|(_, blk)| blk.eth_block.last_applied_l1_block.unwrap_or(U64::zero()))

Choose a reason for hiding this comment

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

similarly here, shouldn't this simply be last_applied_l1_block?

Comment on lines 1295 to 1452
if public_data.prev_last_applied_l1_block != 0 {
assert!(
public_data.last_applied_l1_block >= public_data.prev_last_applied_l1_block,
"last_applied_l1_block should be greater or equal than prev_last_applied_l1_block");
l1_block_hashes_count =
public_data.last_applied_l1_block - public_data.prev_last_applied_l1_block;
}

Choose a reason for hiding this comment

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

shouldn't this simply be:

let l1_block_hashes_count = public_data.last_applied_l1_block - public_data.prev_last_applied_l1_block;

?

Copy link
Author

Choose a reason for hiding this comment

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

the first time we have l1 block hashes in a block the prev_last_applied_l1_block will be 0 and then we don't want to have let l1_block_hashes_count = public_data.last_applied_l1_block - public_data.prev_last_applied_l1_block; because it will be an incorrect value, so in that case we just have an unuseful constraint that num_all_l1_block_hashes == num_all_l1_block_hashes

@vladimir-trifonov
Copy link
Author

vladimir-trifonov commented Dec 4, 2023

Current status, I added L1BlockHashes Tx and am trying to fix the Tx flow to not fail. We added an L1BlockHashes Tx to the test but currently, there are failing parts of the circuit.

@vladimir-trifonov vladimir-trifonov changed the title wip: l1 block hashes poc [WIP] L1 block hashes POC Dec 8, 2023
@vladimir-trifonov vladimir-trifonov force-pushed the LimeChain/wip-block-hashes-poc branch 2 times, most recently from 64274ff to 9ab71ab Compare December 19, 2023 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants