Skip to content

Commit 36de35b

Browse files
authored
feat: Rename all SHA3 opcodes to KECCAK256 (#514)
* feat: Rename all SHA3 opcodes to KECCAK256 * feat: renaming sha3 function * feat: renaming sha3 params * revert: library * revert: library.1 * revert: library.2 * revert: library.3 * revert: library.4 * fix: failing test cases
1 parent 10f81ba commit 36de35b

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

crates/interpreter/src/gas/calc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn create2_cost(len: usize) -> Option<u64> {
6262
// ceil(len / 32.0)
6363
let len = len as u64;
6464
let sha_addup_base = (len / 32) + u64::from((len % 32) != 0);
65-
let sha_addup = SHA3WORD.checked_mul(sha_addup_base)?;
65+
let sha_addup = KECCAK256WORD.checked_mul(sha_addup_base)?;
6666
let gas = base.checked_add(sha_addup)?;
6767

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

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

155155
/// EIP-3860: Limit and meter initcode

crates/interpreter/src/gas/constants.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ pub const MEMORY: u64 = 3;
1414
pub const LOG: u64 = 375;
1515
pub const LOGDATA: u64 = 8;
1616
pub const LOGTOPIC: u64 = 375;
17-
pub const SHA3: u64 = 30;
18-
pub const SHA3WORD: u64 = 6;
17+
pub const KECCAK256: u64 = 30;
18+
pub const KECCAK256WORD: u64 = 6;
1919
pub const COPY: u64 = 3;
2020
pub const BLOCKHASH: u64 = 20;
2121
pub const CODEDEPOSIT: u64 = 200;

crates/interpreter/src/instructions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub fn eval<H: Host, S: Spec>(opcode: u8, interp: &mut Interpreter, host: &mut H
5555
opcode::SHL => bitwise::shl::<S>(interp, host),
5656
opcode::SHR => bitwise::shr::<S>(interp, host),
5757
opcode::SAR => bitwise::sar::<S>(interp, host),
58-
opcode::SHA3 => system::sha3(interp, host),
58+
opcode::KECCAK256 => system::calculate_keccak256(interp, host),
5959
opcode::ADDRESS => system::address(interp, host),
6060
opcode::BALANCE => host::balance::<S>(interp, host),
6161
opcode::SELFBALANCE => host::selfbalance::<S>(interp, host),

crates/interpreter/src/instructions/opcode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub const CODECOPY: u8 = 0x39;
3838
pub const SHL: u8 = 0x1b;
3939
pub const SHR: u8 = 0x1c;
4040
pub const SAR: u8 = 0x1d;
41-
pub const SHA3: u8 = 0x20;
41+
pub const KECCAK256: u8 = 0x20;
4242
pub const POP: u8 = 0x50;
4343
pub const MLOAD: u8 = 0x51;
4444
pub const MSTORE: u8 = 0x52;
@@ -551,7 +551,7 @@ macro_rules! gas_opcodee {
551551
}),
552552
/* 0x1e */ OpInfo::none(),
553553
/* 0x1f */ OpInfo::none(),
554-
/* 0x20 SHA3 */ OpInfo::dynamic_gas(),
554+
/* 0x20 KECCAK256 */ OpInfo::dynamic_gas(),
555555
/* 0x21 */ OpInfo::none(),
556556
/* 0x22 */ OpInfo::none(),
557557
/* 0x23 */ OpInfo::none(),

crates/interpreter/src/instructions/system.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use crate::{
66
};
77
use core::cmp::min;
88

9-
pub fn sha3(interpreter: &mut Interpreter, _host: &mut dyn Host) {
9+
pub fn calculate_keccak256(interpreter: &mut Interpreter, _host: &mut dyn Host) {
1010
pop!(interpreter, from, len);
1111
let len = as_usize_or_fail!(interpreter, len, InstructionResult::InvalidOperandOOG);
12-
gas_or_fail!(interpreter, gas::sha3_cost(len as u64));
12+
gas_or_fail!(interpreter, gas::keccak256_cost(len as u64));
1313
let hash = if len == 0 {
1414
KECCAK_EMPTY
1515
} else {

0 commit comments

Comments
 (0)