Skip to content

Commit

Permalink
docs: add config parameters to ecc Book (#1068)
Browse files Browse the repository at this point in the history
* fix: add config parameters

* fix: toml explanation

* review comments
  • Loading branch information
arayikhalatyan authored Dec 16, 2024
1 parent 11632d3 commit c170209
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions book/src/custom-extensions/ecc.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,20 @@ pub fn main() {
let p3 = &p1 + &p2;
}
```

### Config parameters

For the guest program to build successfully, all used moduli and curves must be declared in the `.toml` config file in the following format:

```toml
[app_vm_config.modular]
supported_modulus = ["115792089237316195423570985008687907853269984665640564039457584007908834671663", "115792089237316195423570985008687907852837564279074904382605163141518161494337"]

[[app_vm_config.ecc.supported_curves]]
modulus = "115792089237316195423570985008687907853269984665640564039457584007908834671663"
scalar = "115792089237316195423570985008687907852837564279074904382605163141518161494337"
a = "0"
b = "7"
```

The `supported_modulus` parameter is a list of moduli that the guest program will use. The `ecc.supported_curves` parameter is a list of supported curves that the guest program will use. They must be provided in decimal format in the `.toml` file. For multiple curves create multiple `[[app_vm_config.ecc.supported_curves]]` sections.
12 changes: 12 additions & 0 deletions extensions/ecc/circuit/src/weierstrass_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,27 @@ use super::{EcAddNeChip, EcDoubleChip};
#[derive(Clone, Debug, derive_new::new, Serialize, Deserialize)]
pub struct CurveConfig {
/// The coordinate modulus of the curve.
#[serde(deserialize_with = "deserialize_biguint_from_str")]
pub modulus: BigUint,
/// The scalar field modulus of the curve.
#[serde(deserialize_with = "deserialize_biguint_from_str")]
pub scalar: BigUint,
/// The coefficient a of y^2 = x^3 + ax + b.
#[serde(deserialize_with = "deserialize_biguint_from_str")]
pub a: BigUint,
/// The coefficient b of y^2 = x^3 + ax + b.
#[serde(deserialize_with = "deserialize_biguint_from_str")]
pub b: BigUint,
}

fn deserialize_biguint_from_str<'de, D>(deserializer: D) -> Result<BigUint, D::Error>
where
D: serde::Deserializer<'de>,
{
let s: String = Deserialize::deserialize(deserializer)?;
s.parse().map_err(serde::de::Error::custom)
}

pub static SECP256K1_CONFIG: Lazy<CurveConfig> = Lazy::new(|| CurveConfig {
modulus: SECP256K1_MODULUS.clone(),
scalar: SECP256K1_ORDER.clone(),
Expand Down

0 comments on commit c170209

Please sign in to comment.