Split Params into base and developer-defined (#458)
I thought it would be nice to have a Predicate for the typed value so that the developer can work with predicates as values comfortably. Then I noticed that hashing a predicate required `Params` which would have been annoying for converting a `TypedValue::Predicate` to `RawValue` and this led to a small refactor over how `Params` work. We already had some fields in the `Params` struct that determine compatibility between encoded data. They can be seen as determining a kind of ABI compatibility. In general it's better if those parameters don't change so that different circuit configurations can still verify proofs from each other. So I decided to force those parameters to be constant in the code base and not allow the user of our library to change them. Many field element serialization/deserialization functions in our code depended on those parameters, and since now they are constant many functions get rid of the `Params` argument, which simplifies the code. This includes the serialization of a `Predicate` which was required to calculate its hash.
This commit is contained in:
parent
498e946612
commit
a7a30176a7
20 changed files with 376 additions and 468 deletions
|
|
@ -171,19 +171,19 @@ impl CustomPredicateBatchBuilder {
|
|||
priv_args: &[&str],
|
||||
sts: &[StatementTmplBuilder],
|
||||
) -> Result<Predicate> {
|
||||
if self.predicates.len() >= self.params.max_custom_batch_size {
|
||||
if self.predicates.len() >= Params::max_custom_batch_size() {
|
||||
return Err(Error::max_length(
|
||||
"self.predicates.len".to_string(),
|
||||
self.predicates.len(),
|
||||
self.params.max_custom_batch_size,
|
||||
Params::max_custom_batch_size(),
|
||||
));
|
||||
}
|
||||
|
||||
if args.len() > self.params.max_statement_args {
|
||||
if args.len() > Params::max_statement_args() {
|
||||
return Err(Error::max_length(
|
||||
"args.len".to_string(),
|
||||
args.len(),
|
||||
self.params.max_statement_args,
|
||||
Params::max_statement_args(),
|
||||
));
|
||||
}
|
||||
if (args.len() + priv_args.len()) > self.params.max_custom_predicate_wildcards {
|
||||
|
|
@ -278,7 +278,6 @@ mod tests {
|
|||
use StatementTmplBuilder as STB;
|
||||
|
||||
let params = Params {
|
||||
max_statement_args: 6,
|
||||
max_custom_predicate_wildcards: 12,
|
||||
..Default::default()
|
||||
};
|
||||
|
|
@ -292,7 +291,7 @@ mod tests {
|
|||
|
||||
let eth_dos_batch_mw: middleware::CustomPredicateBatch =
|
||||
Arc::unwrap_or_clone(eth_dos_batch);
|
||||
let fields = eth_dos_batch_mw.to_fields(¶ms);
|
||||
let fields = eth_dos_batch_mw.to_fields();
|
||||
println!("Batch b, serialized: {:?}", fields);
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue