Skip to content

feat: support bberg lookups#37

Merged
Maddiaa0 merged 8 commits into
avmfrom
md/lookups
Jan 9, 2024
Merged

feat: support bberg lookups#37
Maddiaa0 merged 8 commits into
avmfrom
md/lookups

Conversation

@Maddiaa0

@Maddiaa0 Maddiaa0 commented Jan 5, 2024

Copy link
Copy Markdown
Member

see AztecProtocol/aztec-packages#3880 for implementation example

Lookups allow us to assert that values in a set of columns equal some values in another set of columns.

This approach uses the log derivative method to perform lookups, where the lookup relation requires four extra columns ( as well as the read and write columns ) to function.

  • One selector column to initiate adding a value into the READ side of the lookup table ( lhs in pil )
  • One selector column to initiate adding a value into the WRITE side of the lookup table ( rhs in pil ) - { adding to the table }
  • One selector column to compute inverses - ( helper column )
  • One column to store the number of times a WRITE term is read - ( helper column )

The selector columns will need to be defined manually - as in the ToyAvm example.
The inverse column and the counts columns are automatically included by the code gen. ( this means there are two extra columns per lookup ( which is a little bit inefficient; but will do for now ).

The name of the inverse column is decided by the attribute tag #[attribute] above the lookup - which is required.
The name of the counts column is ${attribute}_counts.

Note: that in the circuit builder you are currently required to set the counts column value manually.

syntax:

  #[lookup_xor] // attribute
    q_xor { xor_a, xor_b, xor_c } in q_xor_table { table_xor_a, table_xor_b, table_xor_c };
    // lhs selector, lhs columns        // rhs selector, rhs columns

@jeanmon jeanmon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Very nice work! Please address/look at my feedback before merging.

Comment thread bberg/src/circuit_builder.rs Outdated
return false;
}}",
permutation_name = permutation_name
lookup_name = lookup_name

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nitpick: I would prefer two different identifiers, unless this is Rust standard practice.

@Maddiaa0 Maddiaa0 Jan 9, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This can just be replaced with the single identifier, as it is just for string templating - will edit

Comment thread bberg/src/lookup_builder.rs Outdated
}

#[derive(Debug)]
/// PermSide

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy-paste leftover? Probably should be "LookupSide"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Actually good point here- they are more or less the same i can unify the type

@Maddiaa0 Maddiaa0 Jan 9, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Actually i probably wont, even though it is repeated it is much more readable when they are defined beside each other

Comment thread bberg/src/lookup_builder.rs Outdated
) -> Vec<Lookup>;
}

impl LookupBuilder for BBFiles {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In this function and subsequent ones, replace variables like "perm", "perm_settings" by "lookup", "lookup_settings".

Comment thread bberg/src/lookup_builder.rs Outdated
*
* @details To create your own lookup:
* 1) Create a copy of this class and rename it
* 2) Update all the values with the ones needed for your permutation

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* 2) Update all the values with the ones needed for your permutation
* 2) Update all the values with the ones needed for your lookup

static constexpr size_t READ_TERM_TYPES[READ_TERMS] = {read_term_types};

/**
* @brief They type of WRITE_TERM used for each write index

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* @brief They type of WRITE_TERM used for each write index
* @brief The type of WRITE_TERM used for each write index

Comment thread bberg/src/lookup_builder.rs Outdated
}}")
}

fn get_perm_side<F: FieldElement>(def: &SelectedExpressions<AlgebraicExpression<F>>) -> LookupSide {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Rename function to "get_lookup_side"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I shall unify these

{compute_inverse_exists}

/**
* @brief Get all the entities for the lookup when need to update them

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* @brief Get all the entities for the lookup when need to update them
* @brief Get all the entities for the lookup when we need to update them

Comment thread bberg/src/lookup_builder.rs Outdated
@Maddiaa0 Maddiaa0 changed the title feat: support lookups feat: support bberg lookups Jan 9, 2024
@Maddiaa0 Maddiaa0 merged commit 5ed8dc7 into avm Jan 9, 2024
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.

2 participants