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 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
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::calculate_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 calculate_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