Rename SHA3 -> Keccak256 (#3749)

Rename SHA3 -> Keccak256

Ethereum doesn't do "official" sha3, we do keccak256, so rename as needed to reflect that reality.

Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
pull/3734/head
Danno Ferrin 3 years ago committed by GitHub
parent 12a06d546d
commit 1693db9849
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      CHANGELOG.md
  2. 4
      evm/src/main/java/org/hyperledger/besu/evm/MainnetEVMs.java
  3. 2
      evm/src/main/java/org/hyperledger/besu/evm/gascalculator/ConstantinopleGasCalculator.java
  4. 13
      evm/src/main/java/org/hyperledger/besu/evm/gascalculator/FrontierGasCalculator.java
  5. 6
      evm/src/main/java/org/hyperledger/besu/evm/gascalculator/GasCalculator.java
  6. 6
      evm/src/main/java/org/hyperledger/besu/evm/log/LogsBloomFilter.java
  7. 8
      evm/src/main/java/org/hyperledger/besu/evm/operation/Keccak256Operation.java

@ -7,6 +7,9 @@
## 22.4.0-RC2
### Breaking Changes
- In the Besu EVM Library all references to SHA3 have been renamed to the more accurate name Kecack256, including class names and comment. [#3749](https://github.com/hyperledger/besu/pull/3749)
### Additions and Improvements
- Onchain node permissioning - log the enodeURL that was previously only throwing an IllegalStateException during the isPermitted check [#3697](https://github.com/hyperledger/besu/pull/3697)
- \[EXPERIMENTAL\] Add snapsync `--sync-mode="X_SNAP"` (only as client) [#3710](https://github.com/hyperledger/besu/pull/3710)

@ -64,6 +64,7 @@ import org.hyperledger.besu.evm.operation.IsZeroOperation;
import org.hyperledger.besu.evm.operation.JumpDestOperation;
import org.hyperledger.besu.evm.operation.JumpOperation;
import org.hyperledger.besu.evm.operation.JumpiOperation;
import org.hyperledger.besu.evm.operation.Keccak256Operation;
import org.hyperledger.besu.evm.operation.LogOperation;
import org.hyperledger.besu.evm.operation.LtOperation;
import org.hyperledger.besu.evm.operation.MLoadOperation;
@ -95,7 +96,6 @@ import org.hyperledger.besu.evm.operation.SStoreOperation;
import org.hyperledger.besu.evm.operation.SarOperation;
import org.hyperledger.besu.evm.operation.SelfBalanceOperation;
import org.hyperledger.besu.evm.operation.SelfDestructOperation;
import org.hyperledger.besu.evm.operation.Sha3Operation;
import org.hyperledger.besu.evm.operation.ShlOperation;
import org.hyperledger.besu.evm.operation.ShrOperation;
import org.hyperledger.besu.evm.operation.SignExtendOperation;
@ -155,7 +155,7 @@ public abstract class MainnetEVMs {
registry.put(new XorOperation(gasCalculator));
registry.put(new NotOperation(gasCalculator));
registry.put(new ByteOperation(gasCalculator));
registry.put(new Sha3Operation(gasCalculator));
registry.put(new Keccak256Operation(gasCalculator));
registry.put(new AddressOperation(gasCalculator));
registry.put(new BalanceOperation(gasCalculator));
registry.put(new OriginOperation(gasCalculator));

@ -41,7 +41,7 @@ public class ConstantinopleGasCalculator extends ByzantiumGasCalculator {
public long create2OperationGasCost(final MessageFrame frame) {
final long initCodeLength = clampedToLong(frame.getStackItem(2));
final long numWords = clampedAdd(initCodeLength, 31) / Bytes32.SIZE;
final long initCodeHashCost = clampedMultiply(SHA3_OPERATION_WORD_GAS_COST, numWords);
final long initCodeHashCost = clampedMultiply(KECCAK256_OPERATION_WORD_GAS_COST, numWords);
return clampedAdd(createOperationGasCost(frame), initCodeHashCost);
}

@ -98,9 +98,9 @@ public class FrontierGasCalculator implements GasCalculator {
private static final long SELFDESTRUCT_OPERATION_GAS_COST = 0L;
private static final long SHA3_OPERATION_BASE_GAS_COST = 30L;
private static final long KECCAK256_OPERATION_BASE_GAS_COST = 30L;
static final long SHA3_OPERATION_WORD_GAS_COST = 6L;
static final long KECCAK256_OPERATION_WORD_GAS_COST = 6L;
private static final long SLOAD_OPERATION_GAS_COST = 50L;
@ -394,9 +394,14 @@ public class FrontierGasCalculator implements GasCalculator {
}
@Override
public long sha3OperationGasCost(final MessageFrame frame, final long offset, final long length) {
public long keccak256OperationGasCost(
final MessageFrame frame, final long offset, final long length) {
return copyWordsToMemoryGasCost(
frame, SHA3_OPERATION_BASE_GAS_COST, SHA3_OPERATION_WORD_GAS_COST, offset, length);
frame,
KECCAK256_OPERATION_BASE_GAS_COST,
KECCAK256_OPERATION_WORD_GAS_COST,
offset,
length);
}
@Override

@ -26,13 +26,13 @@ import org.hyperledger.besu.evm.operation.ExtCodeCopyOperation;
import org.hyperledger.besu.evm.operation.ExtCodeHashOperation;
import org.hyperledger.besu.evm.operation.ExtCodeSizeOperation;
import org.hyperledger.besu.evm.operation.JumpDestOperation;
import org.hyperledger.besu.evm.operation.Keccak256Operation;
import org.hyperledger.besu.evm.operation.LogOperation;
import org.hyperledger.besu.evm.operation.MLoadOperation;
import org.hyperledger.besu.evm.operation.MStore8Operation;
import org.hyperledger.besu.evm.operation.MStoreOperation;
import org.hyperledger.besu.evm.operation.SLoadOperation;
import org.hyperledger.besu.evm.operation.SelfDestructOperation;
import org.hyperledger.besu.evm.operation.Sha3Operation;
import org.hyperledger.besu.evm.precompile.ECRECPrecompiledContract;
import org.hyperledger.besu.evm.precompile.IDPrecompiledContract;
import org.hyperledger.besu.evm.precompile.RIPEMD160PrecompiledContract;
@ -329,14 +329,14 @@ public interface GasCalculator {
long selfDestructOperationGasCost(Account recipient, Wei inheritance);
/**
* Returns the cost for executing a {@link Sha3Operation}.
* Returns the cost for executing a {@link Keccak256Operation}.
*
* @param frame The current frame
* @param offset The offset in memory where the data to be hashed exists
* @param length The hashed data length
* @return the cost for executing the memory byte store operation
*/
long sha3OperationGasCost(MessageFrame frame, long offset, long length);
long keccak256OperationGasCost(MessageFrame frame, long offset, long length);
/**
* Returns the cost for executing a {@link SLoadOperation}.

@ -29,7 +29,7 @@ import org.apache.tuweni.bytes.MutableBytes;
/*
* Bloom filter implementation for storing persistent logs, describes a 2048-bit representation of
* all log entries of a transaction, except data. Sets the bits of the 2048 byte array, where
* indices are given by: The lower order 11-bits, of the first three double-bytes, of the SHA3, of
* indices are given by: The lower order 11-bits, of the first three double-bytes, of the KECCAK256, of
* each value. For instance the address "0x0F572E5295C57F15886F9B263E2F6D2D6C7B5EC6" results in the
* KECCAK256 hash "bd2b01afcd27800b54d2179edc49e2bffde5078bb6d0b204694169b1643fb108", of which the
* corresponding double-bytes are: bd2b, 01af, cd27, corresponding to the following bits in the
@ -145,8 +145,8 @@ public class LogsBloomFilter extends DelegatingBytes {
}
/**
* Discover the low order 11-bits, of the first three double-bytes, of the SHA3 hash, of each
* value and update the bloom filter accordingly.
* Discover the low order 11-bits, of the first three double-bytes, of the KECCAK256 hash, of
* each value and update the bloom filter accordingly.
*
* @param hashValue The hash of the log item.
*/

@ -28,10 +28,10 @@ import java.util.OptionalLong;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.units.bigints.UInt256;
public class Sha3Operation extends AbstractOperation {
public class Keccak256Operation extends AbstractOperation {
public Sha3Operation(final GasCalculator gasCalculator) {
super(0x20, "SHA3", 2, 1, 1, gasCalculator);
public Keccak256Operation(final GasCalculator gasCalculator) {
super(0x20, "KECCAK256", 2, 1, 1, gasCalculator);
}
@Override
@ -39,7 +39,7 @@ public class Sha3Operation extends AbstractOperation {
final long from = clampedToLong(frame.popStackItem());
final long length = clampedToLong(frame.popStackItem());
final long cost = gasCalculator().sha3OperationGasCost(frame, from, length);
final long cost = gasCalculator().keccak256OperationGasCost(frame, from, length);
if (frame.getRemainingGas() < cost) {
return new OperationResult(
OptionalLong.of(cost), Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS));
Loading…
Cancel
Save