Skip to content

Commit

Permalink
feat: precision besu hedera differences debug
Browse files Browse the repository at this point in the history
Signed-off-by: Mariusz Jasuwienas <[email protected]>
  • Loading branch information
arianejasuwienas committed Nov 13, 2024
1 parent 5bc907e commit a19be1f
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions hedera-node/configuration/compose/bootstrap.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ accounts.blocklist.enabled=false
accounts.blocklist.path=

contracts.knownBlockHash=
contracts.evm.version=v0.30
1 change: 1 addition & 0 deletions hedera-node/configuration/dev/bootstrap.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ staking.fees.nodeRewardPercentage=10
staking.fees.stakingRewardPercentage=10

contracts.knownBlockHash=
contracts.evm.version=v0.30
1 change: 1 addition & 0 deletions hedera-node/configuration/mainnet/bootstrap.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
# This file MUST match application.properties exactly as they are both a replica of file 121 on mainnet and
# this file is utilized by the mono-service config for property overrides whereas application.properties is utilized as
# an override by the hedera-config base config.
contracts.evm.version=v0.30
1 change: 1 addition & 0 deletions hedera-node/configuration/preprod/bootstrap.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ accounts.blocklist.enabled=false
accounts.blocklist.path=

contracts.knownBlockHash=
contracts.evm.version=v0.30
2 changes: 1 addition & 1 deletion hedera-node/configuration/previewnet/bootstrap.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ accounts.blocklist.enabled=false
accounts.blocklist.path=
contracts.evm.version.dynamic=true
contracts.maxNumWithHapiSigsAccess=0

contracts.evm.version=v0.30
contracts.knownBlockHash=
1 change: 1 addition & 0 deletions hedera-node/configuration/testnet/bootstrap.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ ledger.id=0x01
contracts.chainId=296
bootstrap.genesisPublicKey=e06b22e0966108fa5d63fc6ae53f9824319b891cd4d6050dbf2b242be7e13344
contracts.knownBlockHash=
contracts.evm.version=v0.30
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Objects;
import org.apache.commons.codec.binary.Hex;
import org.bouncycastle.jcajce.provider.digest.Keccak;
import org.bouncycastle.util.BigIntegers;

public record EthTxData(
byte[] rawTx,
Expand All @@ -55,7 +56,7 @@ public record EthTxData(
* transactions come in with transfer amounts in units of weibar. Elsewhere in Hedera we use
* units of tinybar (10⁻⁸ of an hbar), and here is the conversion factor:
*/
public static final BigInteger WEIBARS_IN_A_TINYBAR = BigInteger.valueOf(10_000_000_000L);
public static final BigInteger WEIBARS_IN_A_TINYBAR = BigInteger.valueOf(1L);

// Copy of constants from besu-native, remove when next besu-native publishes
static final int SECP256K1_FLAGS_TYPE_COMPRESSION = 1 << 1;
Expand Down Expand Up @@ -385,7 +386,7 @@ private static EthTxData populateLegacyEthTxData(RLPItem rlpItem, byte[] rawTx)
if (vBI.compareTo(BigInteger.valueOf(34)) > 0) {
// after EIP155 the chain id is equal to
// CHAIN_ID = (v - {0,1} - 35) / 2
chainId = vBI.subtract(BigInteger.valueOf(35)).shiftRight(1).toByteArray();
chainId = BigIntegers.asUnsignedByteArray(vBI.subtract(BigInteger.valueOf(35)).shiftRight(1));
} else if (isLegacyUnprotectedEtx(vBI)) {
// before EIP155 the chain id is considered equal to 0
chainId = new byte[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.math.BigInteger;
import java.util.Arrays;
import java.util.List;
import org.bouncycastle.util.BigIntegers;
import org.bouncycastle.util.encoders.Hex;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -46,6 +47,8 @@ class EthTxDataTest {
static final String SIGNATURE_PUBKEY = "033a514176466fa815ed481ffad09110a2d344f6c9b78c1d14afc351c3a51be33d";
static final String RAW_TX_TYPE_0 =
"f864012f83018000947e3a9eaf9bcc39e2ffa38eb30bf7a93feacbc18180827653820277a0f9fbff985d374be4a55f296915002eec11ac96f1ce2df183adf992baa9390b2fa00c1e867cc960d9c74ec2e6a662b7908ec4c8cc9f3091e886bcefbeb2290fb792";
static final String RAW_TX_TYPE_0_WITH_CHAIN_ID_11155111 =
"f86b048503ff9aca0782520f94e64fac7f3df5ab44333ad3d3eb3fb68be43f2e8c830fffff808401546d71a026cf0758fda122862a4de71a82a3210ef7c172ee13eae42997f5d32b747ec78ca03587c5c2eee373b1e45693544edcde8dde883d2be3e211b3f0f3c840d6389c8a";
static final String RAW_TX_TYPE_0_TRIMMED_LAST_BYTES =
"f864012f83018000947e3a9eaf9bcc39e2ffa38eb30bf7a93feacbc18180827653820277a0f9fbff985d374be4a55f296915002eec11ac96f1ce2df183adf992baa9390b2fa00c1e867cc960d9c74ec2e6a662b7908ec4c8cc9f3091e886bcefbeb2290000";
// {
Expand Down Expand Up @@ -601,4 +604,18 @@ void bigPositiveValueWithDifferentTypes(EthTransactionType type) {

assertEquals(bigValue, populateEthTxData.value());
}

@Test
void thatPassesOnBigIntegerByteArray() {
final var subject = EthTxData.populateEthTxData(Hex.decode(RAW_TX_TYPE_0_WITH_CHAIN_ID_11155111));
byte[] passingChainId = BigIntegers.asUnsignedByteArray(BigInteger.valueOf(11155111L));
assertEquals(Hex.toHexString(subject.chainId()), Hex.toHexString(passingChainId));
}

@Test
void thatFailsOnBigIntegerByteArray() {
final var subject = EthTxData.populateEthTxData(Hex.decode(RAW_TX_TYPE_0_WITH_CHAIN_ID_11155111));
byte[] failingChainId = BigInteger.valueOf(11155111L).toByteArray();
assertNotEquals(Hex.toHexString(subject.chainId()), Hex.toHexString(failingChainId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class TestingConstants {

static final byte[] CHAINID_TESTNET = unhex("0128");

static final BigInteger WEIBARS_IN_TINYBAR = BigInteger.valueOf(10_000_000_000L);
static final BigInteger WEIBARS_IN_TINYBAR = BigInteger.valueOf(1L);

static final byte[] TINYBARS_57_IN_WEIBARS =
BigInteger.valueOf(57).multiply(WEIBARS_IN_TINYBAR).toByteArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ public IngestChecker(
*/
public void checkNodeState() throws PreCheckException {
if (currentPlatformStatus.get() != ACTIVE) {
logger.info(
"CURRENT PLATFORM STATUS is {} just before PLATFORM_NOT_ACTIVE error \n\n",
currentPlatformStatus.get().toString());
throw new PreCheckException(PLATFORM_NOT_ACTIVE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static HapiSpec specFrom(@NonNull final DynamicTest test) {
.build();
private static final int BYTES_PER_KB = 1024;
public static final int MAX_CALL_DATA_SIZE = 6 * BYTES_PER_KB;
public static final BigInteger WEIBARS_IN_A_TINYBAR = BigInteger.valueOf(10_000_000_000L);
public static final BigInteger WEIBARS_IN_A_TINYBAR = BigInteger.valueOf(1L);
// Useful for testing overflow scenarios when an ERC-20/721 ABI specifies
// a uint256, but a valid value on Hedera will be an 8-byte long only
public static final BigInteger MAX_UINT256_VALUE =
Expand Down

0 comments on commit a19be1f

Please sign in to comment.