Skip to content

Commit

Permalink
all the changes to make aave work
Browse files Browse the repository at this point in the history
  • Loading branch information
mm-zk committed Jan 7, 2025
1 parent 7b6c490 commit ba12fc5
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 25 deletions.
25 changes: 25 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,31 @@
},
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug era_test_node at 8545",
"cargo": {
"args": [
"build",
"--bin=era_test_node",
"--package=era_test_node"
],
"filter": {
"name": "era_test_node",
"kind": "bin"
}
},
"args": [
"--port",
"8545",
"run",
],
"env": {
"CARGO_PROFILE_DEV": "true"
},
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
Expand Down
27 changes: 14 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions WORK.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,24 @@ Simulate works now, but still the gas estimate doesn't properly handle the cost

Cleaned up the diff - so now we have nice interface.
The main issue currently is with the tracers - as they require a different 'flow' for old VM vs new.


## AAve issues

[TODO]- 'call' to deployment should return the bytecode.



Issues found:
* EIP161 - nonce for create should start with '1'
* should increase nonce on Create2 too.
* issues with bad 'frame' rollbacks on preimages (when we failed in constructor)
* out of gas - had to add -g 400 to increase the multiplier
* bad ordering - had to add '--slow' to make it run one-by-one
* delegateStatic issue - when 'static' method was doing delegation call (we read from wrong place).
* not closing frame - causing error




call methods creating a 'deadlock' in era test node.
4 changes: 2 additions & 2 deletions src/config/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ pub const DEFAULT_FAIR_PUBDATA_PRICE: u64 = 13_607_659_111;
/// Scale factor for estimating L1 gas prices
pub const DEFAULT_ESTIMATE_GAS_PRICE_SCALE_FACTOR: f64 = 2.0;
/// Scale factor for estimating gas limits
pub const DEFAULT_ESTIMATE_GAS_SCALE_FACTOR: f32 = 1.3;
pub const DEFAULT_ESTIMATE_GAS_SCALE_FACTOR: f32 = 5.3;
/// Default port for the test node server
pub const NODE_PORT: u16 = 8011;
/// Network ID for the test node
#[cfg(feature = "zkos")]
// For ZK os - hardcoded to 37 for now.
pub const TEST_NODE_NETWORK_ID: u32 = 37;
pub const TEST_NODE_NETWORK_ID: u32 = 31337;
#[cfg(not(feature = "zkos"))]
pub const TEST_NODE_NETWORK_ID: u32 = 260;
/// Default derivation path for the test node
Expand Down
1 change: 1 addition & 0 deletions src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ pub fn print_transaction_summary(

tracing::info!("{} [{}] Hash: {:?}", emoji, status, tx.hash());
tracing::info!("Initiator: {:?}", tx.initiator_account());
tracing::info!("Nonce: {:?}", tx.nonce());
tracing::info!("Payer: {:?}", tx.payer());
tracing::info!(
"Gas Limit: {} | Used: {} | Refunded: {}",
Expand Down
15 changes: 11 additions & 4 deletions src/node/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> EthNamespa
block_number: BlockNumber,
full_transactions: bool,
) -> RpcResult<Option<Block<TransactionVariant>>> {
tracing::warn!("get_block_by_number: {:?}", block_number);
let inner = self.get_inner().clone();

Box::pin(async move {
Expand Down Expand Up @@ -314,7 +315,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> EthNamespa
})
};

match maybe_block {
let res = match maybe_block {
Some(mut block) => {
let block_hash = block.hash;
block.transactions = block
Expand Down Expand Up @@ -344,7 +345,9 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> EthNamespa
Ok(Some(block))
}
None => Ok(None),
}
};
//tracing::warn!("get_block_by_number: {:?}", res);
res
})
}

Expand Down Expand Up @@ -412,15 +415,17 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> EthNamespa
#[cfg(feature = "zkos")]
let nonce_key = super::zkos::zkos_get_nonce_key(&address);

match inner.write() {
let res = match inner.write() {
Ok(guard) => match guard.fork_storage.read_value_internal(&nonce_key) {
Ok(result) => Ok(h256_to_u64(result).into()),
Err(error) => Err(report_into_jsrpc_error(error)),
},
Err(_) => Err(into_jsrpc_error(Web3Error::InternalError(
anyhow::Error::msg("Failed to acquire write lock for nonce retrieval"),
))),
}
};
tracing::warn!("get_transaction_count: {:?}", res);
res
})
}

Expand Down Expand Up @@ -455,6 +460,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> EthNamespa
.tx_results
.get(&hash)
.map(|info| info.receipt.clone());
tracing::warn!("get_transaction_receipt for {:?}: {:?}", hash, receipt);
Ok(receipt)
})
}
Expand Down Expand Up @@ -489,6 +495,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> EthNamespa
hash: zksync_types::H256,
full_transactions: bool,
) -> RpcResult<Option<Block<TransactionVariant>>> {
tracing::warn!("get_block_by_hash: {:?}", hash);
let inner = self.get_inner().clone();

Box::pin(async move {
Expand Down
7 changes: 5 additions & 2 deletions src/node/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone> InMemoryNode<S> {

// init vm

let (batch_env, _) = inner.create_l1_batch_env(&self.time, storage.clone());
//let (batch_env, _) = inner.create_l1_batch_env(&self.time, storage.clone());
let system_env = inner.create_system_env(base_contracts, execution_mode);

#[cfg(not(feature = "zkos"))]
Expand Down Expand Up @@ -1571,7 +1571,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone> InMemoryNode<S> {
Ok(TxExecutionOutput {
result: tx_result.clone(),
call_traces: call_traces.cloned().unwrap_or_default(),
bytecodes: tx_result.new_known_factory_deps.unwrap().clone(),
bytecodes: tx_result.new_known_factory_deps.unwrap_or_default().clone(),
})
}

Expand Down Expand Up @@ -1748,6 +1748,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone> InMemoryNode<S> {

// Execute transactions and bootloader
let mut executed_tx_hashes = Vec::with_capacity(tx_hashes.len());
tracing::error!("==== Starting seal block ==== {:?}", block_ctx);
for tx in txs {
// Executing a next transaction means that a previous transaction was either rolled back (in which case its snapshot
// was already removed), or that we build on top of it (in which case, it can be removed now).
Expand All @@ -1762,7 +1763,9 @@ impl<S: ForkSource + std::fmt::Debug + Clone> InMemoryNode<S> {
executed_tx_hashes.push(hash);
}
}
tracing::error!("==== Finished seal block ====");
vm.execute(InspectExecutionMode::Bootloader);
tracing::error!("==== Finished running bootloader mode ====");

// Write all the mutated keys (storage slots).
let mut inner = self
Expand Down
22 changes: 18 additions & 4 deletions src/node/zkos.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
use std::{alloc::Global, collections::HashMap};
use std::{alloc::Global, collections::HashMap, vec};

use basic_system::basic_system::simple_growable_storage::TestingTree;
use forward_system::run::{
test_impl::{InMemoryPreimageSource, InMemoryTree, TxListSource},
PreimageType, StorageCommitment,
};
use hex::ToHex;
use ruint::aliases::B160;
use system_hooks::addresses_constants::{
NOMINAL_TOKEN_BALANCE_STORAGE_ADDRESS, NONCE_HOLDER_HOOK_ADDRESS,
};
use zk_ee::{common_structs::derive_flat_storage_key, utils::Bytes32};
use zksync_multivm::interface::{
storage::{StoragePtr, WriteStorage},
ExecutionResult, PushTransactionResult, TxExecutionMode, VmExecutionLogs,
ExecutionResult, InspectExecutionMode, PushTransactionResult, TxExecutionMode, VmExecutionLogs,
VmExecutionResultAndLogs, VmInterface, VmInterfaceHistoryEnabled, VmRevertReason,
};
use zksync_types::{
Expand Down Expand Up @@ -347,9 +348,11 @@ pub fn execute_tx_in_zkos<W: WriteStorage>(
forward_system::run::ExecutionResult::Success(output) => match &output {
forward_system::run::ExecutionOutput::Call(data) => data,
forward_system::run::ExecutionOutput::Create(data, address) => {
dbg!(address);
// TODO - pass it to the output somehow.
println!("Deployed to {:?}", address);
println!(
"Deployed to {}",
address.to_be_bytes_vec().encode_hex::<String>()
);
data
}
},
Expand Down Expand Up @@ -535,12 +538,23 @@ impl<S: WriteStorage> VmInterface for ZKOsVM<S> {
dispatcher: &mut Self::TracerDispatcher,
execution_mode: zksync_multivm::interface::InspectExecutionMode,
) -> VmExecutionResultAndLogs {
if let InspectExecutionMode::Bootloader = execution_mode {
return VmExecutionResultAndLogs {
result: ExecutionResult::Success { output: vec![] },
logs: Default::default(),
statistics: Default::default(),
refunds: Default::default(),
new_known_factory_deps: Default::default(),
};
}
let simulate_only = match self.execution_mode {
TxExecutionMode::VerifyExecute => false,
TxExecutionMode::EstimateFee => true,
TxExecutionMode::EthCall => true,
};

assert_eq!(1, self.transactions.len());

// FIXME.
let tx = self.transactions[0].clone();
execute_tx_in_zkos(
Expand Down

0 comments on commit ba12fc5

Please sign in to comment.