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

Implement Clone trait for CircuitBuilder #26

Merged
merged 7 commits into from
Apr 19, 2024
Merged

Implement Clone trait for CircuitBuilder #26

merged 7 commits into from
Apr 19, 2024

Conversation

doutv
Copy link
Collaborator

@doutv doutv commented Apr 18, 2024

Related: https://github.com/okx/zkdex-plonky2-circom-poc/pull/72

In order to implement Clone trait for CircuitBuilder, the key is to implement Clone for its member WitnessGeneratorRef

Since WitnessGenerator is a dynamic trait, containing lots of generators. I use https://github.com/dtolnay/dyn-clone to do it.
See more: https://stackoverflow.com/a/50785548/22481384

Comment on lines +107 to +109
pub trait WitnessGenerator<F, const D: usize>: 'static + Send + Sync + Debug + DynClone
where
F: RichField + Extendable<D>,
Copy link
Collaborator Author

@doutv doutv Apr 18, 2024

Choose a reason for hiding this comment

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

add DynClone trait requirement

Comment on lines +128 to 135
dyn_clone::clone_trait_object!(<F, const D: usize> WitnessGenerator<F, D> where F: RichField + Extendable<D>);

/// A wrapper around an `Box<WitnessGenerator>` which implements `PartialEq`
/// and `Eq` based on generator IDs.
#[derive(Clone)]
pub struct WitnessGeneratorRef<F: RichField + Extendable<D>, const D: usize>(
pub Box<dyn WitnessGenerator<F, D>>,
);
Copy link
Collaborator Author

@doutv doutv Apr 18, 2024

Choose a reason for hiding this comment

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

dyn_clone::clone_trait_object! Implement Clone trait for WitnessGenerator
Then WitnessGeneratorRef can automatically derive Clone trait

Cargo.toml Outdated
Comment on lines 6 to 8
cryptography_cuda = { git = "ssh://[email protected]/okx/cryptography_cuda.git", rev = "d44b861cf241d27688525e7a8f082199a2abcbfa", features = [
"no_cuda",
] }
Copy link
Collaborator Author

@doutv doutv Apr 18, 2024

Choose a reason for hiding this comment

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

Also, I add cryptography_cuda to workspace.dependencies
Used in zkdex-plonky2

@doutv doutv merged commit 85ad398 into dev Apr 19, 2024
0 of 4 checks passed
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