diff --git a/CHANGELOG.md b/CHANGELOG.md index e4486dfbfb2..fde10cc44ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ - Proper support for `pending` block tag when calling `eth_estimateGas` and `eth_createAccessList` [#7951](https://github.com/hyperledger/besu/pull/7951) ### Bug fixes -- Correct default parameters for frontier transactions in `eth_call` and `eth_estimateGas` [#7965](https://github.com/hyperledger/besu/pull/7965) +- Correct default parameters for frontier transactions in `eth_call` and `eth_estimateGas` [#7965](https://github.com/hyperledger/besu/pull/7965) ## 24.12.0 @@ -73,6 +73,7 @@ - Fix registering new metric categories from plugins [#7825](https://github.com/hyperledger/besu/pull/7825) - Fix CVE-2024-47535 [7878](https://github.com/hyperledger/besu/pull/7878) - Fix QBFT prepared block based proposal validation [#7875](https://github.com/hyperledger/besu/pull/7875) +- Correctly parse nonce as hex in `eth_call` account overrides [#7999](https://github.com/hyperledger/besu/pull/7999) ## 24.10.0 diff --git a/datatypes/src/main/java/org/hyperledger/besu/datatypes/AccountOverride.java b/datatypes/src/main/java/org/hyperledger/besu/datatypes/AccountOverride.java index e414e97eb5d..8bbc1d3c05d 100644 --- a/datatypes/src/main/java/org/hyperledger/besu/datatypes/AccountOverride.java +++ b/datatypes/src/main/java/org/hyperledger/besu/datatypes/AccountOverride.java @@ -21,6 +21,7 @@ import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.apache.tuweni.bytes.Bytes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -106,11 +107,11 @@ public Builder withBalance(final Wei balance) { /** * Sets the nonce override * - * @param nonce the nonce override + * @param nonce the nonce override in hex * @return the builder */ - public Builder withNonce(final Long nonce) { - this.nonce = Optional.ofNullable(nonce); + public Builder withNonce(final String nonce) { + this.nonce = Optional.of(Bytes.fromHexStringLenient(nonce).toLong()); return this; } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java index 7de6f65aae2..867d1619aa3 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthCallTest.java @@ -104,7 +104,7 @@ public void noAccountOverrides() { @Test public void someAccountOverrides() { AccountOverrideMap expectedOverrides = new AccountOverrideMap(); - AccountOverride override = new AccountOverride.Builder().withNonce(88L).build(); + AccountOverride override = new AccountOverride.Builder().withNonce("0x9e").build(); final Address address = Address.fromHexString("0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3"); expectedOverrides.put(address, override); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java index 74c04082453..11010202ee0 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthEstimateGasTest.java @@ -116,7 +116,7 @@ public void noAccountOverrides() { @Test public void someAccountOverrides() { AccountOverrideMap expectedOverrides = new AccountOverrideMap(); - AccountOverride override = new AccountOverride.Builder().withNonce(88L).build(); + AccountOverride override = new AccountOverride.Builder().withNonce("0x9e").build(); final Address address = Address.fromHexString("0xd9c9cd5f6779558b6e0ed4e6acf6b1947e7fa1f3"); expectedOverrides.put(address, override); diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/AccountOverrideParameterTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/AccountOverrideParameterTest.java index 1b6d8c1cbe3..1b676e8c5ea 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/AccountOverrideParameterTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/util/AccountOverrideParameterTest.java @@ -52,7 +52,7 @@ public void jsonDeserializesCorrectly() throws Exception { + "\":" + "{" + "\"balance\": \"0x01\"," - + "\"nonce\": 88" + + "\"nonce\": \"0x9e\"" + "}}],\"id\":1}"; final JsonRpcRequestContext request = new JsonRpcRequestContext(readJsonAsJsonRpcRequest(json)); @@ -62,7 +62,7 @@ public void jsonDeserializesCorrectly() throws Exception { final AccountOverride accountOverride = accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX1)); - assertThat(accountOverride.getNonce()).isEqualTo(Optional.of(88L)); + assertThat(accountOverride.getNonce().get()).isEqualTo(158); assertThat(accountOverride.getBalance()).isEqualTo(Optional.of(Wei.of(1))); assertFalse(accountOverride.getStateDiff().isPresent()); } @@ -96,6 +96,34 @@ public void jsonWithCodeDeserializesCorrectly() throws Exception { assertFalse(accountOverride.getStateDiff().isPresent()); } + @Test + public void jsonWithHexNonceDeserializesCorrectly() throws Exception { + final String json = + "{\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{" + + "\"from\":\"0x0\", \"to\": \"0x0\"}, " + + "\"latest\"," + + "{\"" + + ADDRESS_HEX1 + + "\":" + + "{" + + "\"balance\": \"0x01\"," + + "\"nonce\": \"" + + "0x9e" + + "\"" + + "}}],\"id\":1}"; + + final JsonRpcRequestContext request = new JsonRpcRequestContext(readJsonAsJsonRpcRequest(json)); + final AccountOverrideMap accountOverrideParam = + request.getRequiredParameter(2, AccountOverrideMap.class); + + final AccountOverride accountOverride = + accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX1)); + + assertThat(accountOverride.getBalance()).isEqualTo(Optional.of(Wei.of(1))); + assertThat(accountOverride.getNonce().get()).isEqualTo(158); // 0x9e + assertFalse(accountOverride.getStateDiff().isPresent()); + } + @Test public void jsonWithStorageOverridesDeserializesCorrectly() throws Exception { final String json = @@ -107,7 +135,7 @@ public void jsonWithStorageOverridesDeserializesCorrectly() throws Exception { + "\":" + "{" + "\"balance\": \"0x01\"," - + "\"nonce\": 88," + + "\"nonce\": \"0x9E\"," + "\"stateDiff\": {" + "\"" + STORAGE_KEY @@ -124,7 +152,7 @@ public void jsonWithStorageOverridesDeserializesCorrectly() throws Exception { final AccountOverride accountOverride = accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX1)); - assertThat(accountOverride.getNonce()).isEqualTo(Optional.of(88L)); + assertThat(accountOverride.getNonce().get()).isEqualTo(158); assertTrue(accountOverride.getStateDiff().isPresent()); assertThat(accountOverride.getStateDiff().get().get(STORAGE_KEY)).isEqualTo(STORAGE_VALUE); @@ -141,7 +169,7 @@ public void jsonWithMultipleAccountOverridesDeserializesCorrectly() throws Excep + "\":" + "{" + "\"balance\": \"0x01\"," - + "\"nonce\": 88," + + "\"nonce\": \"0x9E\"," + "\"stateDiff\": {" + "\"" + STORAGE_KEY @@ -154,7 +182,7 @@ public void jsonWithMultipleAccountOverridesDeserializesCorrectly() throws Excep + "\":" + "{" + "\"balance\": \"0xFF\"," - + "\"nonce\": 99," + + "\"nonce\": \"0x9D\"," + "\"stateDiff\": {" + "\"" + STORAGE_KEY @@ -171,14 +199,14 @@ public void jsonWithMultipleAccountOverridesDeserializesCorrectly() throws Excep final AccountOverride accountOverride1 = accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX1)); - assertThat(accountOverride1.getNonce()).isEqualTo(Optional.of(88L)); + assertThat(accountOverride1.getNonce().get()).isEqualTo(158); assertThat(accountOverride1.getBalance()).isEqualTo(Optional.of(Wei.fromHexString("0x01"))); assertTrue(accountOverride1.getStateDiff().isPresent()); assertThat(accountOverride1.getStateDiff().get().get(STORAGE_KEY)).isEqualTo(STORAGE_VALUE); final AccountOverride accountOverride2 = accountOverrideParam.get(Address.fromHexString(ADDRESS_HEX2)); - assertThat(accountOverride2.getNonce()).isEqualTo(Optional.of(99L)); + assertThat(accountOverride2.getNonce().get()).isEqualTo(157); assertThat(accountOverride2.getBalance()).isEqualTo(Optional.of(Wei.fromHexString("0xFF"))); assertTrue(accountOverride2.getStateDiff().isPresent()); assertThat(accountOverride2.getStateDiff().get().get(STORAGE_KEY)).isEqualTo(STORAGE_VALUE);