Deneb review suggestions (2) (#4680)
* Serde deny unknown fields * Require 0x prefix
This commit is contained in:
parent
e783a40e01
commit
0bfc933c50
@ -6,12 +6,13 @@ use serde_derive::Deserialize;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct KZGBlobToKZGCommitmentInput {
|
||||
pub blob: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
#[serde(bound = "E: EthSpec", deny_unknown_fields)]
|
||||
pub struct KZGBlobToKZGCommitment<E: EthSpec> {
|
||||
pub input: KZGBlobToKZGCommitmentInput,
|
||||
pub output: Option<String>,
|
||||
|
@ -6,13 +6,14 @@ use serde_derive::Deserialize;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct KZGComputeBlobKZGProofInput {
|
||||
pub blob: String,
|
||||
pub commitment: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
#[serde(bound = "E: EthSpec", deny_unknown_fields)]
|
||||
pub struct KZGComputeBlobKZGProof<E: EthSpec> {
|
||||
pub input: KZGComputeBlobKZGProofInput,
|
||||
pub output: Option<String>,
|
||||
|
@ -13,13 +13,14 @@ pub fn parse_point(point: &str) -> Result<Hash256, Error> {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct KZGComputeKZGProofInput {
|
||||
pub blob: String,
|
||||
pub z: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
#[serde(bound = "E: EthSpec", deny_unknown_fields)]
|
||||
pub struct KZGComputeKZGProof<E: EthSpec> {
|
||||
pub input: KZGComputeKZGProofInput,
|
||||
pub output: Option<(String, Hash256)>,
|
||||
|
@ -16,7 +16,7 @@ pub fn get_kzg<P: KzgPreset>() -> Result<Kzg<P>, Error> {
|
||||
}
|
||||
|
||||
pub fn parse_proof(proof: &str) -> Result<KzgProof, Error> {
|
||||
hex::decode(&proof[2..])
|
||||
hex::decode(strip_0x(proof)?)
|
||||
.map_err(|e| Error::FailedToParseTest(format!("Failed to parse proof: {:?}", e)))
|
||||
.and_then(|bytes| {
|
||||
bytes
|
||||
@ -27,7 +27,7 @@ pub fn parse_proof(proof: &str) -> Result<KzgProof, Error> {
|
||||
}
|
||||
|
||||
pub fn parse_commitment(commitment: &str) -> Result<KzgCommitment, Error> {
|
||||
hex::decode(&commitment[2..])
|
||||
hex::decode(strip_0x(commitment)?)
|
||||
.map_err(|e| Error::FailedToParseTest(format!("Failed to parse commitment: {:?}", e)))
|
||||
.and_then(|bytes| {
|
||||
bytes.try_into().map_err(|e| {
|
||||
@ -38,7 +38,7 @@ pub fn parse_commitment(commitment: &str) -> Result<KzgCommitment, Error> {
|
||||
}
|
||||
|
||||
pub fn parse_blob<E: EthSpec>(blob: &str) -> Result<Blob<E>, Error> {
|
||||
hex::decode(&blob[2..])
|
||||
hex::decode(strip_0x(blob)?)
|
||||
.map_err(|e| Error::FailedToParseTest(format!("Failed to parse blob: {:?}", e)))
|
||||
.and_then(|bytes| {
|
||||
Blob::<E>::new(bytes)
|
||||
@ -46,7 +46,15 @@ pub fn parse_blob<E: EthSpec>(blob: &str) -> Result<Blob<E>, Error> {
|
||||
})
|
||||
}
|
||||
|
||||
fn strip_0x(s: &str) -> Result<&str, Error> {
|
||||
s.strip_prefix("0x").ok_or(Error::FailedToParseTest(format!(
|
||||
"Hex is missing 0x prefix: {}",
|
||||
s
|
||||
)))
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct KZGVerifyBlobKZGProofInput {
|
||||
pub blob: String,
|
||||
pub commitment: String,
|
||||
@ -54,7 +62,7 @@ pub struct KZGVerifyBlobKZGProofInput {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
#[serde(bound = "E: EthSpec", deny_unknown_fields)]
|
||||
pub struct KZGVerifyBlobKZGProof<E: EthSpec> {
|
||||
pub input: KZGVerifyBlobKZGProofInput,
|
||||
pub output: Option<bool>,
|
||||
|
@ -5,6 +5,7 @@ use serde_derive::Deserialize;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct KZGVerifyBlobKZGProofBatchInput {
|
||||
pub blobs: Vec<String>,
|
||||
pub commitments: Vec<String>,
|
||||
@ -12,7 +13,7 @@ pub struct KZGVerifyBlobKZGProofBatchInput {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
#[serde(bound = "E: EthSpec", deny_unknown_fields)]
|
||||
pub struct KZGVerifyBlobKZGProofBatch<E: EthSpec> {
|
||||
pub input: KZGVerifyBlobKZGProofBatchInput,
|
||||
pub output: Option<bool>,
|
||||
|
@ -5,6 +5,7 @@ use serde_derive::Deserialize;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct KZGVerifyKZGProofInput {
|
||||
pub commitment: String,
|
||||
pub z: String,
|
||||
@ -13,7 +14,7 @@ pub struct KZGVerifyKZGProofInput {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
#[serde(bound = "E: EthSpec", deny_unknown_fields)]
|
||||
pub struct KZGVerifyKZGProof<E: EthSpec> {
|
||||
pub input: KZGVerifyKZGProofInput,
|
||||
pub output: Option<bool>,
|
||||
|
Loading…
Reference in New Issue
Block a user