Skip to content
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 @@ -21,7 +21,6 @@
import java.util.Objects;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.bouncycastle.util.BigIntegers;

public record EthTxData(
byte[] rawTx,
Expand Down Expand Up @@ -111,6 +110,20 @@ public static int getTransactionType(byte[] data) {
}
}

/// Returns an unsigned byte[] representation of a BigInteger, dropping the leading zero byte
/// if present. Adopted from org.bouncycastle.util.BigIntegers.asUnsignedByteArray().
public static byte[] asUnsignedByteArray(final BigInteger value) {
final byte[] bytes = value.toByteArray();

if (bytes[0] == 0 && bytes.length != 1) {
final byte[] tmp = new byte[bytes.length - 1];
System.arraycopy(bytes, 1, tmp, 0, tmp.length);
return tmp;
}

return bytes;
}

public EthTxData replaceCallData(final byte[] newCallData) {
return new EthTxData(
null,
Expand Down Expand Up @@ -770,9 +783,9 @@ private static byte[] deriveChainId(@NonNull final BigInteger vBI) {
// after EIP155 the chain id is equal to CHAIN_ID = (v - {0,1} - 35) / 2.
// asUnsignedByteArray avoids the leading sign byte BigInteger.toByteArray adds when the
// top bit is set — see https://github.com/hashgraph/hedera-services/issues/15953
return BigIntegers.asUnsignedByteArray(BigInteger.valueOf((v - 35) >> 1));
return EthTxData.asUnsignedByteArray(BigInteger.valueOf((v - 35) >> 1));
}
return BigIntegers.asUnsignedByteArray(
return EthTxData.asUnsignedByteArray(
vBI.subtract(BigInteger.valueOf(35)).shiftRight(1));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.HexFormat;
import java.util.List;
import org.bouncycastle.asn1.sec.SECNamedCurves;
import org.bouncycastle.util.BigIntegers;
import org.hiero.base.utility.CommonUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -792,7 +791,7 @@ void bigPositiveValueWithDifferentTypes(final EthTransactionType type) {
@Test
void populateEthTxDataComparedToUnsignedByteArrayNoExtraByteAdded() {
final var subject = EthTxData.populateEthTxData(HexFormat.of().parseHex(RAW_TX_TYPE_0_WITH_CHAIN_ID_11155111));
final byte[] passingChainId = BigIntegers.asUnsignedByteArray(BigInteger.valueOf(11155111L));
final byte[] passingChainId = EthTxData.asUnsignedByteArray(BigInteger.valueOf(11155111L));
assertNotNull(subject);
assertEquals(HexFormat.of().formatHex(subject.chainId()), HexFormat.of().formatHex(passingChainId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Function;
import org.bouncycastle.util.Arrays;
import org.hiero.base.crypto.Hash;
import org.hiero.base.crypto.test.fixtures.CryptoRandomUtils;
import org.hiero.consensus.model.event.ConsensusEvent;
Expand Down Expand Up @@ -2185,7 +2184,7 @@ private PlatformState platformStateWithFreezeTime(@Nullable final Instant freeze

private void mockRound(Instant timestamp, long roundNum) {
given(round.getRoundNum()).willReturn(roundNum);
lenient().when(round.iterator()).thenReturn(new Arrays.Iterator<>(new ConsensusEvent[] {mockEvent}));
lenient().when(round.iterator()).thenReturn(List.of(mockEvent).iterator());
lenient().when(round.getConsensusTimestamp()).thenReturn(timestamp);
}

Expand Down Expand Up @@ -2217,7 +2216,7 @@ private void mockRoundWithTxnTimestamp(Instant timestamp, long roundNum) {
txn.setConsensusTimestamp(timestamp);
lenient()
.when(mockEvent.consensusTransactionIterator())
.thenReturn(new Arrays.Iterator<>(new ConsensusTransaction[] {txn}));
.thenReturn(List.<ConsensusTransaction>of(txn).iterator());
}

@Test
Expand Down
Loading