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

feat: Rename all SHA3 opcodes to KECCAK256 #514

Merged
merged 10 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
14 changes: 7 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 bins/revme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ rlp = { version = "0.5", default-features = false }
ruint = { version = "1.8.0", features = ["rlp", "serde"] }
serde = { version = "1.0", features = ["derive", "rc"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
sha3 = { version = "0.10", default-features = false }
keccak256 = { version = "0.10", default-features = false }
structopt = "0.3"
thiserror = "1.0"
triehash = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion bins/revme/src/statetest/merkle_trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use revm::{
primitives::{keccak256, Log, B160, B256, U256},
};
use rlp::RlpStream;
use sha3::{Digest, Keccak256};
use keccak256::{Digest, Keccak256};
use triehash::sec_trie_root;

pub fn log_rlp_hash(logs: Vec<Log>) -> B256 {
Expand Down
4 changes: 2 additions & 2 deletions crates/interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ revm-primitives = { path = "../primitives", version="1.1.2", default-features =
derive_more = "0.99"
enumn = "0.1"

# sha3 keccak hasher
sha3 = { version = "0.10", default-features = false, features = [] }
# keccak256 keccak hasher
keccak256 = { version = "0.10", default-features = false, features = [] }

# optional
serde = { version = "1.0", features = ["derive", "rc"], optional = true }
Expand Down
6 changes: 3 additions & 3 deletions crates/interpreter/src/gas/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn create2_cost(len: usize) -> Option<u64> {
// ceil(len / 32.0)
let len = len as u64;
let sha_addup_base = (len / 32) + u64::from((len % 32) != 0);
let sha_addup = SHA3WORD.checked_mul(sha_addup_base)?;
let sha_addup = KECCAK256WORD.checked_mul(sha_addup_base)?;
let gas = base.checked_add(sha_addup)?;

Some(gas)
Expand Down Expand Up @@ -146,10 +146,10 @@ pub fn log_cost(n: u8, len: u64) -> Option<u64> {
.checked_add(LOGTOPIC * n as u64)
}

pub fn sha3_cost(len: u64) -> Option<u64> {
pub fn keccak256_cost(len: u64) -> Option<u64> {
let wordd = len / 32;
let wordr = len % 32;
SHA3.checked_add(SHA3WORD.checked_mul(if wordr == 0 { wordd } else { wordd + 1 })?)
KECCAK256.checked_add(KECCAK256WORD.checked_mul(if wordr == 0 { wordd } else { wordd + 1 })?)
}

/// EIP-3860: Limit and meter initcode
Expand Down
4 changes: 2 additions & 2 deletions crates/interpreter/src/gas/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub const MEMORY: u64 = 3;
pub const LOG: u64 = 375;
pub const LOGDATA: u64 = 8;
pub const LOGTOPIC: u64 = 375;
pub const SHA3: u64 = 30;
pub const SHA3WORD: u64 = 6;
pub const KECCAK256: u64 = 30;
pub const KECCAK256WORD: u64 = 6;
pub const COPY: u64 = 3;
pub const BLOCKHASH: u64 = 20;
pub const CODEDEPOSIT: u64 = 200;
Expand Down
2 changes: 1 addition & 1 deletion crates/interpreter/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn eval<H: Host, S: Spec>(opcode: u8, interp: &mut Interpreter, host: &mut H
opcode::SHL => bitwise::shl::<S>(interp, host),
opcode::SHR => bitwise::shr::<S>(interp, host),
opcode::SAR => bitwise::sar::<S>(interp, host),
opcode::SHA3 => system::sha3(interp, host),
opcode::KECCAK256 => system::keccak256(interp, host),
opcode::ADDRESS => system::address(interp, host),
opcode::BALANCE => host::balance::<S>(interp, host),
opcode::SELFBALANCE => host::selfbalance::<S>(interp, host),
Expand Down
4 changes: 2 additions & 2 deletions crates/interpreter/src/instructions/opcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub const CODECOPY: u8 = 0x39;
pub const SHL: u8 = 0x1b;
pub const SHR: u8 = 0x1c;
pub const SAR: u8 = 0x1d;
pub const SHA3: u8 = 0x20;
pub const KECCAK256: u8 = 0x20;
pub const POP: u8 = 0x50;
pub const MLOAD: u8 = 0x51;
pub const MSTORE: u8 = 0x52;
Expand Down Expand Up @@ -550,7 +550,7 @@ macro_rules! gas_opcodee {
}),
/* 0x1e */ OpInfo::none(),
/* 0x1f */ OpInfo::none(),
/* 0x20 SHA3 */ OpInfo::dynamic_gas(),
/* 0x20 KECCAK256 */ OpInfo::dynamic_gas(),
/* 0x21 */ OpInfo::none(),
/* 0x22 */ OpInfo::none(),
/* 0x23 */ OpInfo::none(),
Expand Down
4 changes: 2 additions & 2 deletions crates/interpreter/src/instructions/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use crate::{
};
use core::cmp::min;

pub fn sha3(interpreter: &mut Interpreter, _host: &mut dyn Host) {
pub fn keccak256(interpreter: &mut Interpreter, _host: &mut dyn Host) {
pop!(interpreter, from, len);
let len = as_usize_or_fail!(interpreter, len, InstructionResult::InvalidOperandOOG);
gas_or_fail!(interpreter, gas::sha3_cost(len as u64));
gas_or_fail!(interpreter, gas::keccak256_cost(len as u64));
let hash = if len == 0 {
KECCAK_EMPTY
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/precompile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ once_cell = "1.17"
ripemd = { version = "0.1", default-features = false }
secp256k1 = { version = "0.27.0", default-features = false, features = ["alloc", "recovery"], optional = true }
sha2 = { version = "0.10.5", default-features = false }
sha3 = { version = "0.10.7", default-features = false }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR was just to rename things, revert this change of library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

keccak256 = { version = "0.10.7", default-features = false }

[dev-dependencies]
hex = "0.4"
Expand Down
4 changes: 2 additions & 2 deletions crates/precompile/src/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub const ECRECOVER: PrecompileAddress = PrecompileAddress(
#[allow(clippy::module_inception)]
mod secp256k1 {
use k256::ecdsa::{Error, RecoveryId, Signature, VerifyingKey};
use sha3::{Digest, Keccak256};
use keccak256::{Digest, Keccak256};

use crate::B256;

Expand Down Expand Up @@ -43,7 +43,7 @@ mod secp256k1 {
ecdsa::{RecoverableSignature, RecoveryId},
Message, Secp256k1,
};
use sha3::{Digest, Keccak256};
use keccak256::{Digest, Keccak256};

pub fn ecrecover(sig: &[u8; 65], msg: &B256) -> Result<B256, secp256k1::Error> {
let sig =
Expand Down
4 changes: 2 additions & 2 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ hex-literal = "0.4"
derive_more = "0.99"
enumn = "0.1"

# sha3 keccak hasher
sha3 = { version = "0.10", default-features = false, features = [] }
# keccak256 keccak hasher
keccak256 = { version = "0.10", default-features = false, features = [] }

# optional
serde = { version = "1.0", features = ["derive", "rc"], optional = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/utilities.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{B160, B256, U256};
use hex_literal::hex;
use sha3::{Digest, Keccak256};
use keccak256::{Digest, Keccak256};

pub const KECCAK_EMPTY: B256 = B256(hex!(
"c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
Expand Down