Skip to content

Commit

Permalink
Merge branch 'main' into tee_prover_new_2
Browse files Browse the repository at this point in the history
  • Loading branch information
haraldh authored Oct 8, 2024
2 parents a96663a + 3fd2fb1 commit d0b8e76
Show file tree
Hide file tree
Showing 173 changed files with 372 additions and 17,770 deletions.
13 changes: 6 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ zk_evm_1_4_1 = { package = "zk_evm", version = "0.141" }
zk_evm_1_5_0 = { package = "zk_evm", version = "=0.150.5" }

# New VM; pinned to a specific commit because of instability
zksync_vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "74577d9be13b1bff9d1a712389731f669b179e47" }
zksync_vm2 = { git = "https://github.com/matter-labs/vm2.git", rev = "a233d44bbe61dc6a758a754c3b78fe4f83e56699" }

# Consensus dependencies.
zksync_concurrency = "=0.3.0"
Expand Down
12 changes: 3 additions & 9 deletions core/lib/eth_client/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ pub struct FailureInfo {

#[cfg(test)]
mod tests {
use zksync_eth_signer::{EthereumSigner, PrivateKeySigner, TransactionParameters};
use zksync_eth_signer::{PrivateKeySigner, TransactionParameters};
use zksync_types::{
eth_sender::{EthTxBlobSidecarV1, SidecarBlobV1},
web3, K256PrivateKey, EIP_4844_TX_TYPE, H256, U256, U64,
Expand Down Expand Up @@ -384,10 +384,7 @@ mod tests {
.as_ref(),
)]),
};
let raw_tx = signer
.sign_transaction(raw_transaction.clone())
.await
.unwrap();
let raw_tx = signer.sign_transaction(raw_transaction.clone());

let hash = web3::keccak256(&raw_tx).into();
// Transaction generated with https://github.com/inphi/blob-utils with
Expand Down Expand Up @@ -493,10 +490,7 @@ mod tests {
blob_versioned_hashes: Some(vec![versioned_hash_1, versioned_hash_2]),
};

let raw_tx = signer
.sign_transaction(raw_transaction.clone())
.await
.unwrap();
let raw_tx = signer.sign_transaction(raw_transaction);

let hash = web3::keccak256(&raw_tx).into();
// Transaction generated with https://github.com/inphi/blob-utils with
Expand Down
9 changes: 4 additions & 5 deletions core/lib/eth_signer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ keywords.workspace = true
categories.workspace = true

[dependencies]
zksync_types.workspace = true
zksync_basic_types.workspace = true
zksync_crypto_primitives.workspace = true

async-trait.workspace = true
rlp.workspace = true
thiserror.workspace = true
async-trait.workspace = true

[dev-dependencies]
tokio = { workspace = true, features = ["full"] }
1 change: 0 additions & 1 deletion core/lib/eth_signer/src/error.rs

This file was deleted.

3 changes: 2 additions & 1 deletion core/lib/eth_signer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use async_trait::async_trait;
use zksync_types::{Address, EIP712TypedStructure, Eip712Domain, PackedEthSignature};
use zksync_basic_types::Address;
use zksync_crypto_primitives::{EIP712TypedStructure, Eip712Domain, PackedEthSignature};

pub use crate::{pk_signer::PrivateKeySigner, raw_ethereum_tx::TransactionParameters};

Expand Down
65 changes: 39 additions & 26 deletions core/lib/eth_signer/src/pk_signer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use zksync_types::{
Address, EIP712TypedStructure, Eip712Domain, K256PrivateKey, PackedEthSignature,
use async_trait::async_trait;
use zksync_basic_types::Address;
use zksync_crypto_primitives::{
EIP712TypedStructure, Eip712Domain, K256PrivateKey, PackedEthSignature,
};

use crate::{
Expand All @@ -12,22 +14,20 @@ pub struct PrivateKeySigner {
private_key: K256PrivateKey,
}

// We define inherent methods duplicating `EthereumSigner` ones because they are sync and (other than `sign_typed_data`) infallible.
impl PrivateKeySigner {
pub fn new(private_key: K256PrivateKey) -> Self {
Self { private_key }
}
}

#[async_trait::async_trait]
impl EthereumSigner for PrivateKeySigner {
/// Get Ethereum address that matches the private key.
async fn get_address(&self) -> Result<Address, SignerError> {
Ok(self.private_key.address())
/// Gets an Ethereum address that matches this private key.
pub fn address(&self) -> Address {
self.private_key.address()
}

/// Signs typed struct using Ethereum private key by EIP-712 signature standard.
/// Result of this function is the equivalent of RPC calling `eth_signTypedData`.
async fn sign_typed_data<S: EIP712TypedStructure + Sync>(
pub fn sign_typed_data<S: EIP712TypedStructure + Sync>(
&self,
domain: &Eip712Domain,
typed_struct: &S,
Expand All @@ -39,16 +39,11 @@ impl EthereumSigner for PrivateKeySigner {
}

/// Signs and returns the RLP-encoded transaction.
async fn sign_transaction(
&self,
raw_tx: TransactionParameters,
) -> Result<Vec<u8>, SignerError> {
pub fn sign_transaction(&self, raw_tx: TransactionParameters) -> Vec<u8> {
// According to the code in web3 <https://docs.rs/web3/latest/src/web3/api/accounts.rs.html#86>
// We should use `max_fee_per_gas` as `gas_price` if we use EIP1559
let gas_price = raw_tx.max_fee_per_gas;

let max_priority_fee_per_gas = raw_tx.max_priority_fee_per_gas;

let tx = Transaction {
to: raw_tx.to,
nonce: raw_tx.nonce,
Expand All @@ -62,21 +57,42 @@ impl EthereumSigner for PrivateKeySigner {
max_fee_per_blob_gas: raw_tx.max_fee_per_blob_gas,
blob_versioned_hashes: raw_tx.blob_versioned_hashes,
};

let signed = tx.sign(&self.private_key, raw_tx.chain_id);
Ok(signed.raw_transaction.0)
signed.raw_transaction.0
}
}

#[async_trait]
impl EthereumSigner for PrivateKeySigner {
async fn get_address(&self) -> Result<Address, SignerError> {
Ok(self.address())
}

async fn sign_typed_data<S: EIP712TypedStructure + Sync>(
&self,
domain: &Eip712Domain,
typed_struct: &S,
) -> Result<PackedEthSignature, SignerError> {
self.sign_typed_data(domain, typed_struct)
}

async fn sign_transaction(
&self,
raw_tx: TransactionParameters,
) -> Result<Vec<u8>, SignerError> {
Ok(self.sign_transaction(raw_tx))
}
}

#[cfg(test)]
mod test {
use zksync_types::{K256PrivateKey, H160, H256, U256, U64};
use zksync_basic_types::{H160, H256, U256, U64};
use zksync_crypto_primitives::K256PrivateKey;

use super::PrivateKeySigner;
use crate::{raw_ethereum_tx::TransactionParameters, EthereumSigner};
use super::*;

#[tokio::test]
async fn test_generating_signed_raw_transaction() {
#[test]
fn test_generating_signed_raw_transaction() {
let private_key = K256PrivateKey::from_bytes(H256::from([5; 32])).unwrap();
let signer = PrivateKeySigner::new(private_key);
let raw_transaction = TransactionParameters {
Expand All @@ -94,10 +110,7 @@ mod test {
blob_versioned_hashes: None,
max_fee_per_blob_gas: None,
};
let raw_tx = signer
.sign_transaction(raw_transaction.clone())
.await
.unwrap();
let raw_tx = signer.sign_transaction(raw_transaction);
assert_ne!(raw_tx.len(), 1);
// pre-calculated signature with right algorithm implementation
let precalculated_raw_tx: Vec<u8> = vec![
Expand Down
6 changes: 3 additions & 3 deletions core/lib/eth_signer/src/raw_ethereum_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
//! Link to @Deniallugo's PR to web3: https://github.com/tomusdrw/rust-web3/pull/630
use rlp::RlpStream;
use zksync_types::{
ethabi::Address,
use zksync_basic_types::{
web3::{keccak256, AccessList, Signature, SignedTransaction},
K256PrivateKey, H256, U256, U64,
Address, H256, U256, U64,
};
use zksync_crypto_primitives::K256PrivateKey;

const LEGACY_TX_ID: u64 = 0;
const ACCESSLISTS_TX_ID: u64 = 1;
Expand Down
1 change: 0 additions & 1 deletion core/lib/multivm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ vise.workspace = true
[dev-dependencies]
assert_matches.workspace = true
pretty_assertions.workspace = true
tokio = { workspace = true, features = ["time"] }
zksync_test_account.workspace = true
ethabi.workspace = true
zksync_eth_signer.workspace = true
36 changes: 19 additions & 17 deletions core/lib/multivm/src/versions/vm_1_3_2/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@ pub struct Vm<S: WriteStorage, H: HistoryMode> {
pub(crate) system_env: SystemEnv,
}

impl<S: WriteStorage, H: HistoryMode> Vm<S, H> {
pub(crate) fn record_vm_memory_metrics(&self) -> VmMemoryMetrics {
VmMemoryMetrics {
event_sink_inner: self.vm.state.event_sink.get_size(),
event_sink_history: self.vm.state.event_sink.get_history_size(),
memory_inner: self.vm.state.memory.get_size(),
memory_history: self.vm.state.memory.get_history_size(),
decommittment_processor_inner: self.vm.state.decommittment_processor.get_size(),
decommittment_processor_history: self
.vm
.state
.decommittment_processor
.get_history_size(),
storage_inner: self.vm.state.storage.get_size(),
storage_history: self.vm.state.storage.get_history_size(),
}
}
}

impl<S: WriteStorage, H: HistoryMode> VmInterface for Vm<S, H> {
type TracerDispatcher = TracerDispatcher;

Expand Down Expand Up @@ -160,23 +179,6 @@ impl<S: WriteStorage, H: HistoryMode> VmInterface for Vm<S, H> {
}
}

fn record_vm_memory_metrics(&self) -> VmMemoryMetrics {
VmMemoryMetrics {
event_sink_inner: self.vm.state.event_sink.get_size(),
event_sink_history: self.vm.state.event_sink.get_history_size(),
memory_inner: self.vm.state.memory.get_size(),
memory_history: self.vm.state.memory.get_history_size(),
decommittment_processor_inner: self.vm.state.decommittment_processor.get_size(),
decommittment_processor_history: self
.vm
.state
.decommittment_processor
.get_history_size(),
storage_inner: self.vm.state.storage.get_size(),
storage_history: self.vm.state.storage.get_history_size(),
}
}

fn finish_batch(&mut self) -> FinishedL1Batch {
self.vm
.execute_till_block_end(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ pub(super) fn assemble_tx_meta(execution_mode: TxExecutionMode, execute_tx: bool
// Set 0 byte (execution mode)
output[0] = match execution_mode {
TxExecutionMode::VerifyExecute => 0x00,
TxExecutionMode::EstimateFee { .. } => 0x00,
TxExecutionMode::EthCall { .. } => 0x02,
TxExecutionMode::EstimateFee => 0x00,
TxExecutionMode::EthCall => 0x02,
};

// Set 31 byte (marker for tx execution)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<S: WriteStorage, H: HistoryMode> Vm<S, H> {
}

/// Returns the info about all oracles' sizes.
pub(crate) fn record_vm_memory_metrics_inner(&self) -> VmMemoryMetrics {
pub(crate) fn record_vm_memory_metrics(&self) -> VmMemoryMetrics {
VmMemoryMetrics {
event_sink_inner: self.state.event_sink.get_size(),
event_sink_history: self.state.event_sink.get_history_size(),
Expand Down
Loading

0 comments on commit d0b8e76

Please sign in to comment.