Skip to content

Commit

Permalink
update PR reviews fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
heemankv committed Aug 23, 2024
1 parent 8e9c13d commit b93372e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ MADARA_RPC_URL="http://localhost:3000"
ETHEREUM_RPC_URL="http://localhost:3001"
MEMORY_PAGES_CONTRACT_ADDRESS="0x000000000000000000000000000000000001dead"
PRIVATE_KEY="0xdead"
# Private key of Test wallet provided by Anvil
ETHEREUM_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
STARKNET_SOLIDITY_CORE_CONTRACT_ADDRESS="0x000000000000000000000000000000000002dead"

Expand Down
18 changes: 9 additions & 9 deletions crates/settlement-clients/ethereum/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use c_kzg::{Blob, KzgCommitment, KzgProof, KzgSettings};
use color_eyre::{eyre::ContextCompat, Result as EyreResult};
use std::fmt::Write;

/// Converts a `&[Vec<u8>]` to `Vec<U256>`. Each inner slice is expected to be exactly 32 bytes long.
/// Converts a `&[[u8; 32]]` to `Vec<U256>`.
/// Pads with zeros if any inner slice is shorter than 32 bytes.
pub(crate) fn vec_u8_32_to_vec_u256(slices: &[[u8; 32]]) -> EyreResult<Vec<U256>> {
slices.iter().map(|slice| slice_u8_to_u256(slice)).collect()
Expand All @@ -17,9 +17,9 @@ pub(crate) fn slice_u8_to_u256(slice: &[u8]) -> EyreResult<U256> {
U256::try_from_be_slice(slice).wrap_err_with(|| "could not convert &[u8] to U256".to_string())
}

// Function to convert a slice of u8 to a padded hex string
// Function only takes a slice of length up to 32 elements
// Pads the value on the right side with zeros only if the converted string has lesser than 64 characters.
/// Function to convert a slice of u8 to a padded hex string
/// Function only takes a slice of length up to 32 elements
/// Pads the value on the right side with zeros only if the converted string has lesser than 64 characters.
pub(crate) fn to_padded_hex(slice: &[u8]) -> String {
assert!(slice.len() <= 32, "Slice length must not exceed 32");
let hex = slice.iter().fold(String::new(), |mut output, byte| {
Expand All @@ -46,7 +46,7 @@ pub fn get_input_data_for_eip_4844(program_output: Vec<[u8; 32]>, kzg_proof: [u8

// program_output
let program_output_length = program_output.len();
let program_output_hex = vec_u8_32_to_hex_string(program_output);
let program_output_hex = u8_32_slice_to_hex_string(&program_output);

// length for program_output: 3*64 [offset, length, lines all have 64 char length] + length of program_output
let length_program_output = (3 * 64 + program_output_hex.len()) / 2;
Expand All @@ -72,8 +72,8 @@ pub fn get_input_data_for_eip_4844(program_output: Vec<[u8; 32]>, kzg_proof: [u8
Ok(input_data)
}

pub(crate) fn vec_u8_32_to_hex_string(data: Vec<[u8; 32]>) -> String {
data.into_iter().fold(String::new(), |mut output, arr| {
pub(crate) fn u8_32_slice_to_hex_string(data: &[[u8; 32]]) -> String {
data.iter().fold(String::new(), |mut output, arr| {
// Convert the array to a hex string
let hex = arr.iter().fold(String::new(), |mut output, byte| {
let _ = write!(output, "{byte:02x}");
Expand Down Expand Up @@ -232,8 +232,8 @@ mod tests {
],
format!("{}{}", "ff".repeat(32), "f5".repeat(32))
)]
fn vec_u8_32_to_hex_string_works(#[case] slice: Vec<[u8; 32]>, #[case] expected: String) {
let result = vec_u8_32_to_hex_string(slice);
fn u8_32_slice_to_hex_string_works(#[case] slice: Vec<[u8; 32]>, #[case] expected: String) {
let result = u8_32_slice_to_hex_string(&slice);
assert_eq!(result, expected);
}

Expand Down

0 comments on commit b93372e

Please sign in to comment.