Skip to content

Commit

Permalink
fix: build calldata correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
fborello-lambda committed Dec 27, 2024
1 parent 5e136f4 commit 51b02d5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
14 changes: 12 additions & 2 deletions cmd/ethrex/ethrex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,21 @@ async fn main() {
let authrpc_jwtsecret = std::fs::read(authrpc_jwtsecret).expect("Failed to read JWT secret");
let head_block_hash = {
let current_block_number = store.get_latest_block_number().unwrap();
store.get_canonical_block_hash(current_block_number).unwrap().unwrap()
store
.get_canonical_block_hash(current_block_number)
.unwrap()
.unwrap()
};
let max_tries = 3;
let url = format!("http://{authrpc_socket_addr}");
let block_producer_engine = ethrex_dev::block_producer::start_block_producer(url, authrpc_jwtsecret.into(), head_block_hash, max_tries, 1000, ethrex_core::Address::default());
let block_producer_engine = ethrex_dev::block_producer::start_block_producer(
url,
authrpc_jwtsecret.into(),
head_block_hash,
max_tries,
1000,
ethrex_core::Address::default(),
);
tracker.spawn(block_producer_engine);
} else {
let networking = ethrex_net::start_network(
Expand Down
4 changes: 2 additions & 2 deletions crates/blockchain/payload.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
cmp::{min, Ordering},
cmp::{max, Ordering},
collections::HashMap,
};

Expand Down Expand Up @@ -125,7 +125,7 @@ pub fn create_payload(args: &BuildPayloadArgs, storage: &Store) -> Result<Block,
fn calc_gas_limit(parent_gas_limit: u64, desired_limit: u64) -> u64 {
let delta = parent_gas_limit / GAS_LIMIT_BOUND_DIVISOR - 1;
let mut limit = parent_gas_limit;
let desired_limit = min(desired_limit, MIN_GAS_LIMIT);
let desired_limit = max(desired_limit, MIN_GAS_LIMIT);
if limit < desired_limit {
limit = parent_gas_limit + delta;
if limit > desired_limit {
Expand Down
25 changes: 12 additions & 13 deletions crates/l2/proposer/prover_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ impl ProverServer {

pub async fn main_logic_dev(&self) -> Result<(), ProverServerError> {
loop {
thread::sleep(Duration::from_millis(200));
thread::sleep(Duration::from_millis(1000));

let last_committed_block = EthClient::get_last_committed_block(
&self.eth_client,
Expand All @@ -660,18 +660,13 @@ impl ProverServer {
)
.await?;

if last_committed_block == u64::MAX {
debug!("No blocks commited yet");
continue;
}
info!("Last committed: {last_committed_block} - Last verified: {last_verified_block}");

if last_committed_block == last_verified_block {
debug!("No new blocks to prove");
warn!("No new blocks to prove");
continue;
}

info!("Last committed: {last_committed_block} - Last verified: {last_verified_block}");

// IOnChainProposer
// function verify(uint256,bytes,bytes32,bytes32,bytes32,bytes,bytes)
// blockNumber, blockProof, imageId, journalDigest, programVKey, publicValues, proofBytes
Expand Down Expand Up @@ -702,14 +697,18 @@ impl ProverServer {
// offset of first bytes parameter
calldata.extend(H256::from_low_u64_be(7 * 32).as_bytes());
// extend with bytes32, bytes32, bytes32
for _ in 0..=3 {
calldata.extend(H256::zero().as_bytes());
}
// offset of second bytes parameter
calldata.extend(H256::zero().as_bytes());
calldata.extend(H256::zero().as_bytes());
calldata.extend(H256::zero().as_bytes());
// offset of second bytes parameter
calldata.extend(H256::from_low_u64_be(9 * 32).as_bytes());
// offset of third bytes parameter
calldata.extend(H256::from_low_u64_be(11 * 32).as_bytes());
// extend with size and bytes
calldata.extend(H256::from_low_u64_be(32).as_bytes());
calldata.extend(H256::zero().as_bytes());
calldata.extend(H256::from_low_u64_be(32).as_bytes());
calldata.extend(H256::zero().as_bytes());
// extend with size of the third bytes variable -> 32bytes
calldata.extend(H256::from_low_u64_be(32).as_bytes());
calldata.extend(H256::zero().as_bytes());

Expand Down
8 changes: 7 additions & 1 deletion crates/networking/rpc/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ impl RpcHandler for EstimateGasRequest {

// Prepare binary search
let mut highest_gas_limit = match transaction.gas {
Some(0) => block_header.gas_limit,
Some(gas) => gas.min(block_header.gas_limit),
None => block_header.gas_limit,
};
Expand Down Expand Up @@ -539,7 +540,12 @@ fn recap_with_account_balances(
.unwrap_or_default();
let account_gas =
account_balance.saturating_sub(transaction.value) / U256::from(transaction.gas_price);
Ok(highest_gas_limit.min(account_gas.as_u64()))
let account_gas = if account_gas > u64::MAX.into() {
u64::MAX
} else {
account_gas.as_u64()
};
Ok(highest_gas_limit.min(account_gas))
}

fn simulate_tx(
Expand Down

0 comments on commit 51b02d5

Please sign in to comment.