Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use U256::is_zero #5616

Merged
merged 1 commit into from
Nov 28, 2023
Merged
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
2 changes: 1 addition & 1 deletion crates/primitives/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Account {
Some(hash) => hash == KECCAK_EMPTY,
};

self.nonce == 0 && self.balance == U256::ZERO && is_bytecode_empty
self.nonce == 0 && self.balance.is_zero() && is_bytecode_empty
}

/// Returns an account bytecode's hash.
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/transaction/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Signature {
#[inline]
pub fn v(&self, chain_id: Option<u64>) -> u64 {
#[cfg(feature = "optimism")]
if self.r == U256::ZERO && self.s == U256::ZERO {
if self.r.is_zero() && self.s.is_zero() {
return 0
}

Expand Down
2 changes: 1 addition & 1 deletion crates/revm/revm-inspectors/src/tracing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl TracingInspector {
) -> bool {
if data.precompiles.contains(to) {
// only if this is _not_ the root call
return self.is_deep() && value == U256::ZERO
return self.is_deep() && value.is_zero()
}
false
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-engine-api/tests/it/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn payload_validation() {
assert_matches!(

try_into_sealed_block(block_with_zero_base_fee,None),
Err(PayloadError::BaseFee(val)) if val == U256::ZERO
Err(PayloadError::BaseFee(val)) if val.is_zero()
);

// Invalid encoded transactions
Expand Down
6 changes: 3 additions & 3 deletions crates/rpc/rpc/src/eth/revm_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,15 +609,15 @@ mod tests {
let CallFees { gas_price, .. } =
CallFees::ensure_fees(None, None, None, U256::from(99), None, None, Some(U256::ZERO))
.unwrap();
assert_eq!(gas_price, U256::ZERO);
assert!(gas_price.is_zero());
}

#[test]
fn test_blob_fees() {
let CallFees { gas_price, max_fee_per_blob_gas, .. } =
CallFees::ensure_fees(None, None, None, U256::from(99), None, None, Some(U256::ZERO))
.unwrap();
assert_eq!(gas_price, U256::ZERO);
assert!(gas_price.is_zero());
assert_eq!(max_fee_per_blob_gas, None);

let CallFees { gas_price, max_fee_per_blob_gas, .. } = CallFees::ensure_fees(
Expand All @@ -630,7 +630,7 @@ mod tests {
Some(U256::from(99)),
)
.unwrap();
assert_eq!(gas_price, U256::ZERO);
assert!(gas_price.is_zero());
assert_eq!(max_fee_per_blob_gas, Some(U256::from(99)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl BundleStateWithReceipts {

for (key, value) in account.storage.iter() {
let hashed_key = keccak256(B256::new(key.to_be_bytes()));
if value.present_value == U256::ZERO {
if value.present_value.is_zero() {
hashed_storage.insert_zero_valued_slot(hashed_key);
} else {
hashed_storage.insert_non_zero_valued_storage(hashed_key, value.present_value);
Expand Down
4 changes: 2 additions & 2 deletions crates/trie/src/hashed_cursor/post_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ mod tests {
let wiped = false;
let mut hashed_storage = HashedStorage::new(wiped);
for (slot, value) in post_state_storage.iter() {
if *value == U256::ZERO {
if value.is_zero() {
hashed_storage.insert_zero_valued_slot(*slot);
} else {
hashed_storage.insert_non_zero_valued_storage(*slot, *value);
Expand Down Expand Up @@ -1030,7 +1030,7 @@ mod tests {
for (address, (wiped, storage)) in &post_state_storages {
let mut hashed_storage = HashedStorage::new(*wiped);
for (slot, value) in storage {
if *value == U256::ZERO {
if value.is_zero() {
hashed_storage.insert_zero_valued_slot(*slot);
} else {
hashed_storage.insert_non_zero_valued_storage(*slot, *value);
Expand Down
2 changes: 1 addition & 1 deletion examples/db-access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn header_provider_example<T: HeaderProvider>(provider: T, number: u64) -> eyre:
// The header's total difficulty is stored in a separate table, so we have a separate call for
// it. This is not needed for post PoS transition chains.
let td = provider.header_td_by_number(number)?.ok_or(eyre::eyre!("header td not found"))?;
assert_ne!(td, U256::ZERO);
assert!(!td.is_zero());

// Can query headers by range as well, already sealed!
let headers = provider.sealed_headers_range(100..200)?;
Expand Down