Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

[refactor] deprecate lazy_static #915

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions bus-mapping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ethers-providers = "0.17.0"
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_02_02" }
poseidon-circuit = { git = "https://github.com/scroll-tech/poseidon-circuit.git", branch = "scroll-dev-0901"}
itertools = "0.10"
lazy_static = "1.4"
once_cell = "1.18"
log = "0.4.14"
rand = { version = "0.8", optional = true }
serde = {version = "1.0.130", features = ["derive"] }
Expand All @@ -29,7 +29,6 @@ strum_macros = "0.24"

# precompile related crates
revm-precompile = { git = "https://github.com/scroll-tech/revm", branch = "scroll-fix" }
once_cell = "1.17.0"

[dev-dependencies]
hex = "0.4.3"
Expand Down
12 changes: 5 additions & 7 deletions bus-mapping/src/circuit_input_builder/tracer_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ use eth_types::{
geth_types::GethData,
word, Bytecode, Hash, ToAddress, ToWord, Word,
};
use lazy_static::lazy_static;
use mock::{
test_ctx::{helpers::*, LoggerConfig, TestContext},
MOCK_COINBASE,
};
use once_cell::sync::Lazy;
use pretty_assertions::assert_eq;
use std::collections::HashSet;

Expand Down Expand Up @@ -78,12 +78,10 @@ impl CircuitInputBuilderTx {
}
}

lazy_static! {
static ref ADDR_A: Address = Address::zero();
static ref WORD_ADDR_A: Word = ADDR_A.to_word();
static ref ADDR_B: Address = address!("0x0000000000000000000000000000000000000123");
static ref WORD_ADDR_B: Word = ADDR_B.to_word();
}
static ADDR_A: Lazy<Address> = Lazy::new(Address::zero);
static WORD_ADDR_A: Lazy<Word> = Lazy::new(|| ADDR_A.to_word());
static ADDR_B: Lazy<Address> = Lazy::new(|| address!("0x0000000000000000000000000000000000000123"));
static WORD_ADDR_B: Lazy<Word> = Lazy::new(|| ADDR_B.to_word());

fn mock_internal_create() -> Call {
Call {
Expand Down
2 changes: 1 addition & 1 deletion bus-mapping/src/evm/opcodes/chainid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mod chainid_tests {
},
(
RW::WRITE,
&StackOp::new(1, StackAddress::from(1023), (*MOCK_CHAIN_ID).into())
&StackOp::new(1, StackAddress::from(1023), MOCK_CHAIN_ID.into())
)
);
}
Expand Down
23 changes: 10 additions & 13 deletions bus-mapping/src/state_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@ use crate::{
util::{hash_code, KECCAK_CODE_HASH_ZERO},
};
use eth_types::{Address, Hash, Word, H256, U256};
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use std::collections::{BTreeSet, HashMap, HashSet};

lazy_static! {
static ref ACCOUNT_ZERO: Account = Account::zero();
/// Hash value for empty code hash.
static ref EMPTY_CODE_HASH: Hash = CodeDB::hash(&[]);
/// bytes of empty code hash, in little endian order.
pub static ref EMPTY_CODE_HASH_LE: [u8; 32] = {
let mut bytes = EMPTY_CODE_HASH.to_fixed_bytes();
bytes.reverse();
bytes
};
}

static ACCOUNT_ZERO: Lazy<Account> = Lazy::new(Account::zero);
/// Hash value for empty code hash.
static EMPTY_CODE_HASH: Lazy<Hash> = Lazy::new(|| CodeDB::hash(&[]));
/// bytes of empty code hash, in little endian order.
pub static EMPTY_CODE_HASH_LE: Lazy<[u8; 32]> = Lazy::new(|| {
let mut bytes = EMPTY_CODE_HASH.to_fixed_bytes();
bytes.reverse();
bytes
});
const VALUE_ZERO: Word = Word::zero();

/// Memory storage for contract code by code hash.
Expand Down
2 changes: 1 addition & 1 deletion eth-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
ethers-core = "0.17.0"
ethers-signers = "0.17.0"
hex = "0.4"
lazy_static = "1.4"
once_cell = "1.18"
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", tag = "v2023_02_02" }
regex = "1.5.4"
serde = {version = "1.0.130", features = ["derive"] }
Expand Down
11 changes: 5 additions & 6 deletions eth-types/src/evm_types/opcode_ids.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
//! Doc this
use crate::{error::Error, evm_types::GasCost};
use core::fmt::Debug;
use lazy_static::lazy_static;
use once_cell::sync::Lazy;
use regex::Regex;
use serde::{de, Deserialize, Serialize};
use std::{fmt, matches, str::FromStr};
use strum_macros::EnumIter;

static INVALID_OPCODE_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new("opcode 0x([[:xdigit:]]{1,2}) not defined").expect("invalid regex"));

/// Opcode enum. One-to-one corresponding to an `u8` value.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Hash, EnumIter, PartialOrd, Ord)]
pub enum OpcodeId {
Expand Down Expand Up @@ -1243,11 +1246,7 @@ impl FromStr for OpcodeId {
"TSTORE" => OpcodeId::INVALID(0xb4),
_ => {
// Parse an invalid opcode value as reported by geth
lazy_static! {
static ref RE: Regex = Regex::new("opcode 0x([[:xdigit:]]{1,2}) not defined")
.expect("invalid regex");
}
if let Some(cap) = RE.captures(s) {
if let Some(cap) = INVALID_OPCODE_REGEX.captures(s) {
if let Some(byte_hex) = cap.get(1).map(|m| m.as_str()) {
return Ok(OpcodeId::INVALID(
u8::from_str_radix(byte_hex, 16).expect("invalid hex byte from regex"),
Expand Down
53 changes: 27 additions & 26 deletions eth-types/src/sign_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use halo2_proofs::{
Coordinates,
},
};
use lazy_static::lazy_static;
use num_bigint::BigUint;
use once_cell::sync::Lazy;
use subtle::CtOption;

/// Do a secp256k1 signature with a given randomness value.
Expand Down Expand Up @@ -110,27 +110,28 @@ impl SignData {
}
}

lazy_static! {
/// This is the sign data of default padding tx
static ref SIGN_DATA_DEFAULT: SignData = {
let (tx_req, sig) = get_dummy_tx();
let tx = Transaction {
tx_type: TxType::PreEip155,
rlp_unsigned_bytes: tx_req.rlp_unsigned().to_vec(),
rlp_bytes: tx_req.rlp_signed(&sig).to_vec(),
v: sig.v,
r: sig.r,
s: sig.s,
// other fields are irrelevant to get the sign_data()
..Default::default()
};

let sign_data = tx.sign_data().unwrap();
assert_eq!(sign_data.get_addr(), address!("0x7e5f4552091a69125d5dfcb7b8c2659029395bdf"));

sign_data
/// This is the sign data of default padding tx
static SIGN_DATA_DEFAULT: Lazy<SignData> = Lazy::new(|| {
let (tx_req, sig) = get_dummy_tx();
let tx = Transaction {
tx_type: TxType::PreEip155,
rlp_unsigned_bytes: tx_req.rlp_unsigned().to_vec(),
rlp_bytes: tx_req.rlp_signed(&sig).to_vec(),
v: sig.v,
r: sig.r,
s: sig.s,
// other fields are irrelevant to get the sign_data()
..Default::default()
};
}

let sign_data = tx.sign_data().unwrap();
assert_eq!(
sign_data.get_addr(),
address!("0x7e5f4552091a69125d5dfcb7b8c2659029395bdf")
);

sign_data
});

impl Default for SignData {
// Hardcoded valid signature corresponding to a hardcoded private key and
Expand Down Expand Up @@ -181,11 +182,11 @@ pub fn recover_pk(
)
}

lazy_static! {
/// Secp256k1 Curve Scalar. Referece: Section 2.4.1 (parameter `n`) in "SEC 2: Recommended
/// Elliptic Curve Domain Parameters" document at http://www.secg.org/sec2-v2.pdf
pub static ref SECP256K1_Q: BigUint = BigUint::from_bytes_le(&(secp256k1::Fq::zero() - secp256k1::Fq::one()).to_repr()) + 1u64;
}
/// Secp256k1 Curve Scalar. Referece: Section 2.4.1 (parameter `n`) in "SEC 2: Recommended
/// Elliptic Curve Domain Parameters" document at http://www.secg.org/sec2-v2.pdf
pub static SECP256K1_Q: Lazy<BigUint> = Lazy::new(|| {
BigUint::from_bytes_le(&(secp256k1::Fq::zero() - secp256k1::Fq::one()).to_repr()) + 1u64
});

/// Helper function to convert a `CtOption` into an `Result`. Similar to
/// `Option::ok_or`.
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
lazy_static = "1.4"
once_cell = "1.18"
ethers = { version = "0.17.0", features = ["ethers-solc"] }
serde_json = "1.0.66"
serde = { version = "1.0.130", features = ["derive"] }
Expand Down
Loading