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

Move config responsibilities from Layouter to Chip #253

Merged
merged 9 commits into from
May 4, 2021
Merged

Conversation

therealyingtong
Copy link
Collaborator

@therealyingtong therealyingtong commented Apr 19, 2021

Closes #235

Review recommendations:

trait Chip<F: FieldExt> is responsible for:

  • configuring the underlying constraint system (i.e. creating columns, gates, permutations, lookups);
  • holding on to its own configuration: where previously we had layouter().config() we now have self.config(); and
  • loading any fixed configuration needed into the circuit at the beginning of circuit synthesis.

The "top-level" chip is simply the chip with the most comprehensive config, i.e. it provides all columns and permutations needed by other chips.

trait Layouter<F: FieldExt> is responsible for:

  • assign_region(&mut self) assigning values according to its own defined strategy;
  • namespacing;

The layouter knows nothing about any config. This is fine because when a chip calls layouter.assign_region(), it has access to self.config() to inform the layouter. So we no longer see a Layouter<C: Chip> generic type, and this removal also trickles down to RegionLayouter, Region.

@codecov-commenter
Copy link

codecov-commenter commented Apr 19, 2021

Codecov Report

Merging #253 (6f199d3) into main (24d7100) will increase coverage by 0.28%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #253      +/-   ##
==========================================
+ Coverage   81.71%   81.99%   +0.28%     
==========================================
  Files          32       32              
  Lines        3221     3210      -11     
==========================================
  Hits         2632     2632              
+ Misses        589      578      -11     
Impacted Files Coverage Δ
src/circuit.rs 0.00% <0.00%> (ø)
src/circuit/layouter.rs 0.00% <0.00%> (ø)
src/plonk/circuit.rs 61.80% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 24d7100...6f199d3. Read the comment docs.

@therealyingtong therealyingtong force-pushed the chip-config branch 2 times, most recently from 19c52dc to 7904da5 Compare April 21, 2021 15:59
@therealyingtong therealyingtong changed the title [draft] Move config responsibilities from Layouter to Chip Move config responsibilities from Layouter to Chip Apr 21, 2021
@therealyingtong therealyingtong marked this pull request as ready for review April 21, 2021 16:00
Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

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

Partial review.

src/circuit.rs Outdated Show resolved Hide resolved
src/circuit.rs Outdated Show resolved Hide resolved
src/circuit.rs Outdated Show resolved Hide resolved
src/circuit.rs Outdated Show resolved Hide resolved
src/circuit.rs Outdated Show resolved Hide resolved
src/circuit/layouter.rs Outdated Show resolved Hide resolved
@therealyingtong therealyingtong changed the base branch from main to patch-test-plonk-api April 23, 2021 13:47
Base automatically changed from patch-test-plonk-api to main April 23, 2021 21:51
src/plonk/circuit.rs Outdated Show resolved Hide resolved
examples/simple-example.rs Outdated Show resolved Hide resolved
examples/simple-example.rs Outdated Show resolved Hide resolved
examples/simple-example.rs Outdated Show resolved Hide resolved
examples/two-chip.rs Outdated Show resolved Hide resolved
examples/simple-example.rs Outdated Show resolved Hide resolved
examples/simple-example.rs Outdated Show resolved Hide resolved
examples/simple-example.rs Outdated Show resolved Hide resolved
@@ -275,7 +319,7 @@ struct MyCircuit<F: FieldExt> {

impl<F: FieldExt> Circuit<F> for MyCircuit<F> {
// Since we are using a single chip for everything, we can just reuse its config.
type Config = FieldConfig;
type Config = FieldConfigEnum;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
type Config = FieldConfigEnum;
type Config = FieldConfig;

I think this could also maybe instead be type Chip = FieldChip, since I think now we'll always just construct the chip from its config immediately inside Circuit::synthesize. But that's a higher-level refactor (and would probably also require making the layouter choice an associated type), so let's leave that out of this PR.

examples/two-chip.rs Outdated Show resolved Hide resolved
therealyingtong and others added 4 commits April 28, 2021 10:47
Co-authored-by: Jack Grigg <jack@electriccoin.co>
Co-authored-by: Jack Grigg <jack@electriccoin.co>
Co-authored-by: Jack Grigg <jack@electriccoin.co>
hasher.finalize(layouter.namespace(|| "finalize"))
}
}
// //! Gadget and chips for the [SHA-256] hash function.
Copy link
Contributor

@daira daira May 2, 2021

Choose a reason for hiding this comment

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

Use a block comment (/* ... */) so that when #256 fixes the example, we can see the actual changes in the diff. (Nice PR number btw 😆.)

a: Self::Num,
b: Self::Num,
) -> Result<Self::Num, Error> {
let config = self.config().add_config.clone();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to avoid these clones? I tried but the lifetime requirements defeated me.

Copy link
Contributor

Choose a reason for hiding this comment

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

These ones, I think not (at least if we want the sub-cores to be usable on their own). We still have a large reduction in config cloning from this PR.

Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

utACK

Copy link
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

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

utACK

@str4d str4d merged commit cae6f6a into main May 4, 2021
@str4d str4d deleted the chip-config branch May 4, 2021 03:36
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.

[Circuit] Implement Core/Chip abstraction
4 participants