Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
txn inclusion logic added and code cleanup
Browse files Browse the repository at this point in the history
mohiiit committed Jun 13, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 4fc7502 commit 90e4a70
Showing 3 changed files with 32 additions and 34 deletions.
1 change: 0 additions & 1 deletion crates/da_clients/da-client-interface/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use async_trait::async_trait;
use color_eyre::Result;
use mockall::{automock, predicate::*};
use starknet::core::types::FieldElement;

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum DaVerificationStatus {
36 changes: 21 additions & 15 deletions crates/da_clients/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
@@ -5,20 +5,16 @@ use alloy::consensus::{
};
use alloy::eips::{eip2718::Encodable2718, eip2930::AccessList, eip4844::BYTES_PER_BLOB};
use alloy::network::{Ethereum, TxSigner};
use alloy::primitives::{bytes, FixedBytes, U256};
use alloy::primitives::{bytes, FixedBytes, TxHash, U256, U64};
use alloy::providers::{Provider, ProviderBuilder, RootProvider};
use alloy::rpc::client::RpcClient;
use alloy::signers::wallet::LocalWallet;
use alloy::transports::http::Http;
use async_trait::async_trait;

use color_eyre::Result;
// use reqwest::async_impl::client::Client;
use mockall::{automock, predicate::*};
use reqwest::Client;
use starknet::core::types::FieldElement;
use starknet::core::types::FromByteArrayError;
use std::future::IntoFuture;
use std::str::FromStr;
use url::Url;

@@ -51,17 +47,20 @@ impl DaClient for EthereumDaClient {
let eip1559_est = provider.estimate_eip1559_fees(None).await?;
let chain_id: u64 = provider.get_chain_id().await?.to_string().parse()?;

let max_fee_per_blob_gas: u128 = provider.get_blob_base_fee().await?.to_string().parse()?;
let max_priority_fee_per_gas: u128 = provider.get_max_priority_fee_per_gas().await?.to_string().parse()?;

let tx = TxEip4844 {
chain_id,
nonce: 0, // can be block number
gas_limit: 30_000_000,
max_fee_per_gas: eip1559_est.max_fee_per_gas.to_string().parse()?,
max_priority_fee_per_gas: eip1559_est.max_priority_fee_per_gas.to_string().parse()?,
to: addr,
max_priority_fee_per_gas,
to: addr, // maybe to the L1 contract for verification??
value: U256::from(0),
access_list: AccessList(vec![]),
blob_versioned_hashes: sidecar.versioned_hashes().collect(),
max_fee_per_blob_gas: 7300000_535,
max_fee_per_blob_gas,
input: bytes!(),
};
let tx_sidecar = TxEip4844WithSidecar { tx: tx.clone(), sidecar: sidecar.clone() };
@@ -78,8 +77,18 @@ impl DaClient for EthereumDaClient {
Ok(pending_tx.tx_hash().to_string())
}

async fn verify_inclusion(&self, _external_id: &str) -> Result<DaVerificationStatus> {
todo!()
async fn verify_inclusion(&self, external_id: &str) -> Result<DaVerificationStatus> {
let provider = &self.provider;
let tx_hash: TxHash = external_id.parse().unwrap();
let txn_response = provider.get_transaction_receipt(tx_hash).await?;

match txn_response {
None => Ok(DaVerificationStatus::Pending),
Some(receipt) => match receipt.status_code {
Some(status) if status == U64::from(1) => Ok(DaVerificationStatus::Verified),
_ => Ok(DaVerificationStatus::Rejected),
},
}
}

async fn max_blob_per_txn(&self) -> u64 {
@@ -132,11 +141,8 @@ async fn prepare_sidecar(
#[cfg(test)]
mod tests {
use super::*;
use rstest::rstest;
use std::fs::File;
use std::io::{self, BufRead};
use std::io::{BufReader, Read};
use tokio_test;

#[tokio::test]
async fn test_kzg() {
@@ -162,7 +168,7 @@ mod tests {
let data_v8 = hex_string_to_u8_vec(&data).expect("error creating hex string from data");

// creation of sidecar
let (sidecar_blobs, sidecar_commitments, sidecar_proofs) =
let (_sidecar_blobs, sidecar_commitments, sidecar_proofs) =
prepare_sidecar(&[data_v8], &trusted_setup).await.expect("Error creating the sidecar blobs");

// blob commitment from L1
@@ -201,7 +207,7 @@ mod tests {
Ok(result)
}

fn vec_u8_to_hex_string(data: &[u8]) -> String {
fn _vec_u8_to_hex_string(data: &[u8]) -> String {
let hex_chars: Vec<String> = data.iter().map(|byte| format!("{:02X}", byte)).collect();
hex_chars.join("")
}
29 changes: 11 additions & 18 deletions crates/orchestrator/src/jobs/da_job/mod.rs
Original file line number Diff line number Diff line change
@@ -2,19 +2,18 @@ use crate::config::Config;
use crate::jobs::types::{JobItem, JobStatus, JobType, JobVerificationStatus};
use crate::jobs::Job;
use async_trait::async_trait;
use axum::routing::get;
use color_eyre::eyre::{eyre, Ok};
use color_eyre::Result;
use lazy_static::lazy_static;
use num_bigint::{BigUint, ToBigUint};
use num_traits::Num;
use num_traits::{One, Zero};
use num_traits::Zero;
use std::ops::{Add, Mul, Rem};
use std::result::Result::{Err, Ok as OtherOk};
use std::str::FromStr;

use serde::{Deserialize, Serialize};
use starknet::core::types::{BlockId, FieldElement, MaybePendingStateUpdate, StateDiff, StateUpdate, StorageEntry};
//
use starknet::core::types::{BlockId, FieldElement, MaybePendingStateUpdate, StateUpdate, StorageEntry};
use starknet::providers::Provider;
use std::collections::HashMap;
use tracing::log;
@@ -226,7 +225,7 @@ async fn state_update_to_blob_data(

// @note: if nonce is null and there is some len of writes, make an api call to get the contract nonce for the block

if (nonce.is_none() && writes.len() > 0 && addr != FieldElement::ONE) {
if nonce.is_none() && writes.len() > 0 && addr != FieldElement::ONE {
let get_current_nonce_result = config.starknet_client().get_nonce(BlockId::Number(block_no), addr).await;

nonce = match get_current_nonce_result {
@@ -243,7 +242,7 @@ async fn state_update_to_blob_data(
// block number and hash
// @note: ONE special address can be used to mark the range of block, if in future
// the team wants to submit multiple blocks in a sinle blob etc.
if (addr == FieldElement::ONE && da_word == FieldElement::ONE) {
if addr == FieldElement::ONE && da_word == FieldElement::ONE {
continue;
}
blob_data.push(addr);
@@ -277,21 +276,21 @@ fn da_word(class_flag: bool, nonce_change: Option<FieldElement>, num_changes: u6
let mut binary_string = "0".repeat(127);

// class flag of one bit
if (class_flag) {
if class_flag {
binary_string += "1"
} else {
binary_string += "0"
}

// checking for nonce here
if let Some(new_nonce) = nonce_change {
if let Some(_new_nonce) = nonce_change {
let bytes: [u8; 32] = nonce_change.unwrap().to_bytes_be();
let biguint = BigUint::from_bytes_be(&bytes);
let binary_string_local = format!("{:b}", biguint);
let padded_binary_string = format!("{:0>64}", binary_string_local);
binary_string += &padded_binary_string;
} else {
let mut binary_string_local = "0".repeat(64);
let binary_string_local = "0".repeat(64);
binary_string += &binary_string_local;
}

@@ -312,24 +311,18 @@ fn da_word(class_flag: bool, nonce_change: Option<FieldElement>, num_changes: u6
#[cfg(test)]
mod tests {
use super::*;
use crate::tests::common::{constants::ETHEREUM_MAX_BLOB_PER_TXN, init_config};
use da_client_interface::{DaVerificationStatus, MockDaClient};
use crate::tests::common::init_config;
use ::serde::{Deserialize, Serialize};
use httpmock::prelude::*;
use majin_blob_core::blob;
use majin_blob_types::{
serde,
state_diffs::{ContractUpdate, DataJson, StorageUpdate, UnorderedEq},
};
use majin_blob_types::{serde, state_diffs::UnorderedEq};
// use majin_blob_types::serde;
use rstest::rstest;

use serde_json::json;
use std::collections::HashSet;
use std::fs;
use std::fs::File;
use std::io::Read;
use std::io::{self, BufRead, BufReader, Write};
use std::path::Path;

#[rstest]
#[case(false, 1, 1, "18446744073709551617")]

0 comments on commit 90e4a70

Please sign in to comment.