-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Katana: Add state update DA encodings (#2474)
- Loading branch information
Showing
13 changed files
with
598 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use num_bigint::BigUint; | ||
use num_traits::Num; | ||
|
||
use super::eip4844::{BLOB_LEN, BLS_MODULUS, GENERATOR}; | ||
use super::math::{fft, ifft}; | ||
|
||
/// Recovers the original data from a given blob. | ||
/// | ||
/// This function takes a vector of `BigUint` representing the data of a blob and | ||
/// returns the recovered original data as a vector of `BigUint`. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `data` - A vector of `BigUint` representing the blob data. | ||
/// | ||
/// # Returns | ||
/// | ||
/// A vector of `BigUint` representing the recovered original data. | ||
pub fn recover(data: Vec<BigUint>) -> Vec<BigUint> { | ||
let xs: Vec<BigUint> = (0..BLOB_LEN) | ||
.map(|i| { | ||
let bin = format!("{:012b}", i); | ||
let bin_rev = bin.chars().rev().collect::<String>(); | ||
GENERATOR.modpow(&BigUint::from_str_radix(&bin_rev, 2).unwrap(), &BLS_MODULUS) | ||
}) | ||
.collect(); | ||
|
||
ifft(data, xs, &BLS_MODULUS) | ||
} | ||
|
||
pub fn transform(data: Vec<BigUint>) -> Vec<BigUint> { | ||
let xs: Vec<BigUint> = (0..BLOB_LEN) | ||
.map(|i| { | ||
let bin = format!("{:012b}", i); | ||
let bin_rev = bin.chars().rev().collect::<String>(); | ||
GENERATOR.modpow(&BigUint::from_str_radix(&bin_rev, 2).unwrap(), &BLS_MODULUS) | ||
}) | ||
.collect(); | ||
|
||
fft(data, xs, &BLS_MODULUS) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use std::str::FromStr; | ||
|
||
use lazy_static::lazy_static; | ||
use num_bigint::{BigUint, ToBigUint}; | ||
|
||
// **************************************************************************** | ||
// * PARAMETERS & CONSTANTS * | ||
// **************************************************************************** | ||
/// Length of the blob. | ||
pub const BLOB_LEN: usize = 4096; | ||
|
||
lazy_static! { | ||
/// EIP-4844 BLS12-381 modulus. | ||
/// | ||
/// As defined in https://eips.ethereum.org/EIPS/eip-4844 | ||
pub static ref BLS_MODULUS: BigUint = BigUint::from_str( | ||
"52435875175126190479447740508185965837690552500527637822603658699938581184513", | ||
) | ||
.unwrap(); | ||
/// Generator of the group of evaluation points (EIP-4844 parameter). | ||
pub static ref GENERATOR: BigUint = BigUint::from_str( | ||
"39033254847818212395286706435128746857159659164139250548781411570340225835782", | ||
) | ||
.unwrap(); | ||
pub static ref TWO: BigUint = 2u32.to_biguint().unwrap(); | ||
} |
Oops, something went wrong.