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

Release 23.10.0-RC2 burn in #6002

Merged
merged 1 commit into from
Oct 9, 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
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ public void run() {
out.println(messageFrame.getExceptionalHaltReason().get());
}
if (messageFrame.getRevertReason().isPresent()) {
out.println(new String(messageFrame.getRevertReason().get().toArray(), UTF_8));
out.println(
new String(messageFrame.getRevertReason().get().toArrayUnsafe(), UTF_8));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class BlockchainReferenceTestTools {
params.ignore("blockWithAllTransactionTypes");

// EIP-4788 is still in flux and the current fill is not against the final address
params.ignore("[Cancun]");
params.ignore("\\[Cancun\\]");

// EOF tests are written against an older version of the spec
params.ignore("/stEOF/");
Expand Down
4 changes: 3 additions & 1 deletion evm/src/main/java/org/hyperledger/besu/evm/frame/Memory.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package org.hyperledger.besu.evm.frame;

import org.hyperledger.besu.evm.internal.Words;

import java.util.Arrays;

import org.apache.tuweni.bytes.Bytes;
Expand Down Expand Up @@ -100,7 +102,7 @@ long calculateNewActiveWords(final long location, final long numBytes) {
}

try {
final long byteSize = Math.addExact(Math.addExact(location, numBytes), 31);
final long byteSize = Words.clampedAdd(Words.clampedAdd(location, numBytes), 31);
long wordSize = byteSize / 32;
return Math.max(wordSize, activeWords);
} catch (ArithmeticException ae) {
Expand Down
28 changes: 19 additions & 9 deletions evm/src/main/java/org/hyperledger/besu/evm/internal/Words.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ static int clampedToInt(final long l) {
* @return value of a plus b if no over/underflows or Long.MAX_VALUE/Long.MIN_VALUE otherwise
*/
static long clampedAdd(final long a, final long b) {
try {
return Math.addExact(a, b);
} catch (final ArithmeticException ae) {
long r = a + b;
if (((a ^ r) & (b ^ r)) < 0) {
// out of bounds, clamp it!
return a > 0 ? Long.MAX_VALUE : Long.MIN_VALUE;
} else {
return r;
}
}

Expand All @@ -132,10 +134,15 @@ static long clampedAdd(final long a, final long b) {
* @return value of a times b if no over/underflows or Long.MAX_VALUE/Long.MIN_VALUE otherwise
*/
static long clampedMultiply(final long a, final long b) {
try {
return Math.multiplyExact(a, b);
} catch (final ArithmeticException ae) {
long r = a * b;
long ax = Math.abs(a);
long ay = Math.abs(b);
if (((ax | ay) >>> 31 != 0)
&& (((b != 0) && (r / b != a)) || (a == Long.MIN_VALUE && b == -1))) {
// out of bounds, clamp it!
return ((a ^ b) < 0) ? Long.MIN_VALUE : Long.MAX_VALUE;
} else {
return r;
}
}

Expand All @@ -148,9 +155,12 @@ static long clampedMultiply(final long a, final long b) {
* otherwise
*/
static int clampedMultiply(final int a, final int b) {
try {
return Math.multiplyExact(a, b);
} catch (final ArithmeticException ae) {
long r = (long) a * (long) b;
int ri = (int) r;
if (ri == r) {
return ri;
} else {
// out of bounds, clamp it!
return ((a ^ b) < 0) ? Integer.MIN_VALUE : Integer.MAX_VALUE;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private static BigInteger extractParameter(
if (offset > input.size() || length == 0) {
return BigInteger.ZERO;
}
final byte[] raw = Arrays.copyOfRange(input.toArray(), offset, offset + length);
final byte[] raw = Arrays.copyOfRange(input.toArrayUnsafe(), offset, offset + length);
return new BigInteger(1, raw);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private static BigInteger extractParameter(
if (offset > input.size() || length == 0) {
return BigInteger.ZERO;
}
final byte[] raw = Arrays.copyOfRange(input.toArray(), offset, offset + length);
final byte[] raw = Arrays.copyOfRange(input.toArrayUnsafe(), offset, offset + length);
return new BigInteger(1, raw);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public long gasRequirement(final Bytes input) {
return 0L;
}

final byte[] roundsBytes = copyOfRange(input.toArray(), 0, 4);
final byte[] roundsBytes = copyOfRange(input.toArrayUnsafe(), 0, 4);
final BigInteger rounds = new BigInteger(1, roundsBytes);
return rounds.longValueExact();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.hyperledger.besu.nativelib.arithmetic.LibArithmetic;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.Optional;
import javax.annotation.Nonnull;

Expand Down Expand Up @@ -200,11 +199,16 @@ public static long modulusLength(final Bytes input) {
* @return the big integer
*/
public static BigInteger extractParameter(final Bytes input, final int offset, final int length) {
if (offset > input.size() || length == 0) {
if (offset >= input.size() || length == 0) {
return BigInteger.ZERO;
} else if (offset + length < input.size()) {
return new BigInteger(1, input.slice(offset, length).toArray());
} else {
byte[] raw = new byte[length];
Bytes partial = input.slice(offset);
System.arraycopy(partial.toArray(), 0, raw, 0, partial.size());
return new BigInteger(1, raw);
}
final byte[] raw = Arrays.copyOfRange(input.toArray(), offset, offset + length);
return new BigInteger(1, raw);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public PrecompileContractResult computePrecompile(
return PrecompileContractResult.halt(
null, Optional.of(ExceptionalHaltReason.PRECOMPILE_ERROR));
} else {
byte[] hash = Hash.sha256(commitment).toArray();
byte[] hash = Hash.sha256(commitment).toArrayUnsafe();
hash[0] = 0x01;
if (!versionedHash.equals(Bytes32.wrap(hash))) {
return PrecompileContractResult.halt(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ public void run() {
}
if (messageFrame.getRevertReason().isPresent()) {
out.println(
new String(messageFrame.getRevertReason().get().toArray(), StandardCharsets.UTF_8));
new String(
messageFrame.getRevertReason().get().toArrayUnsafe(), StandardCharsets.UTF_8));
}
}
if (messageFrameStack.isEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=23.10.0-RC
version=23.10.0-RC2

org.gradle.welcome=never
# Set exports/opens flags required by Google Java Format and ErrorProne plugins. (JEP-396)
Expand Down