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

Plafer cleanup block hash table #1333

Merged
merged 14 commits into from
May 28, 2024
Merged

Conversation

plafer
Copy link
Contributor

@plafer plafer commented May 10, 2024

Makes the block hash table aux column builder more readable. Also adds more documentation.

Copy link
Contributor

@Al-Kindi-0 Al-Kindi-0 left a comment

Choose a reason for hiding this comment

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

Looks great, thank you!
Just a couple of minor nits from my side

Comment on lines 77 to 78
/// - current_block_id: contains the ID of the current block. Note: the current block's ID is the
/// parent block's ID from the perspective of the block being added to the table.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should we just use parent_id as in the docs? It was a bit easier for me to understand the logic of this virtual table using this name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, switched back to parent_block_id

processor/src/decoder/aux_trace/block_hash_table.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks great! Thank you!

One thing I am wondering is whether we should create a struct for the block hash table row. It could look something like this:

struct BlockHashTableRow {
    parent_block_id: Felt,
    child_block_hash: Word,
    is_first_child: bool,
    is_loop_body: bool,
}

Then, we could add various constructor methods to it:

impl BlockHashTableRow {
    pub fn from_end(trace: &MainTrace, row: usize) -> Self {
        todo!()
    }

    pub fn from_join(trace: &MainTrace, row: usize, is_first_child: bool) -> Self {
        todo!()
    }

    ...
}

And then we could add a to_value() method to reduce a row to a single value. It could look like this:

impl BlockHashTableRow {
    pub fn to_value<E: FieldElement<BaseField = Felt>>(&self, alphas: &[E]) -> E {
        todo!()
    }
}

Then, when using these, we could do something like:

SPLIT => BlockHashTableRow::from_split(main_trace, i).to_value(alphas),

I think this structure would make it a bit easier to follow - though, I think the improvement would not be all that big over what you already have. So, if you'd rather keep it as is, that's fine too.

processor/src/decoder/aux_trace/block_hash_table.rs Outdated Show resolved Hide resolved
@plafer
Copy link
Contributor Author

plafer commented May 16, 2024

I agree that a BlockHashTableRow would be a nice abstraction (we could modify the one that's already in the tests).

The only place where it breaks a little bit is with JOIN, where 2 rows are created from the opcode, so a BlockHashTableRow::from_join() wouldn't really work. So maybe the current version is better, since it doesn't assume that one opcode maps to one row?

@bobbinth
Copy link
Contributor

The only place where it breaks a little bit is with JOIN, where 2 rows are created from the opcode, so a BlockHashTableRow::from_join() wouldn't really work. So maybe the current version is better, since it doesn't assume that one opcode maps to one row?

I think it could still works if the constructor has the following signature:

pub fn from_join(trace: &MainTrace, row: usize, is_first_child: bool) -> Self {
    todo!()
}

Then, this function can be called twice to generate two rows (once with is_first_child = true, and the other time with is_first_child = false). Then, the two rows would be reduced to values and multiplied.

@plafer
Copy link
Contributor Author

plafer commented May 26, 2024

@bobbinth implementation now uses BlockHashTableRow. I also renamed BlockHashTableRow::to_value() to collapse().

@plafer
Copy link
Contributor Author

plafer commented May 26, 2024

Note: clippy failures are due to a new version of nightly rust, and there are many errors, so I think we should do it in another PR instead

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! I left a couple of small comments inline. Once these are addressed, we can merge.

assembly/src/ast/instruction/mod.rs Outdated Show resolved Hide resolved
assembly/src/ast/instruction/opcode.rs Outdated Show resolved Hide resolved
core/src/operations/mod.rs Outdated Show resolved Hide resolved
@bobbinth bobbinth merged commit ac9b07c into next May 28, 2024
14 of 15 checks passed
@bobbinth bobbinth deleted the plafer-cleanup-block-hash-table branch May 28, 2024 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants