diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e899add4b..7739171c1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/evm/src/main/java/org/hyperledger/besu/evm/MainnetEVMs.java b/evm/src/main/java/org/hyperledger/besu/evm/MainnetEVMs.java index 12eca302da..adbe751da5 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/MainnetEVMs.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/MainnetEVMs.java @@ -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)); diff --git a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/ConstantinopleGasCalculator.java b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/ConstantinopleGasCalculator.java index 2bcaa34ee1..c71feab43f 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/ConstantinopleGasCalculator.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/ConstantinopleGasCalculator.java @@ -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); } diff --git a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/FrontierGasCalculator.java b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/FrontierGasCalculator.java index 54f28ca1f9..9e18da6079 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/FrontierGasCalculator.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/FrontierGasCalculator.java @@ -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 diff --git a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/GasCalculator.java b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/GasCalculator.java index 94ed115c74..0d88224845 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/GasCalculator.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/GasCalculator.java @@ -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}. diff --git a/evm/src/main/java/org/hyperledger/besu/evm/log/LogsBloomFilter.java b/evm/src/main/java/org/hyperledger/besu/evm/log/LogsBloomFilter.java index ada4bdf84d..787ae77851 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/log/LogsBloomFilter.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/log/LogsBloomFilter.java @@ -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. */ diff --git a/evm/src/main/java/org/hyperledger/besu/evm/operation/Sha3Operation.java b/evm/src/main/java/org/hyperledger/besu/evm/operation/Keccak256Operation.java similarity index 86% rename from evm/src/main/java/org/hyperledger/besu/evm/operation/Sha3Operation.java rename to evm/src/main/java/org/hyperledger/besu/evm/operation/Keccak256Operation.java index c49cf2c5e7..50b4450661 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/operation/Sha3Operation.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/operation/Keccak256Operation.java @@ -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));