Skip to content

Commit

Permalink
fix: eth_call deserialization to correctly ignore unknown fields in…
Browse files Browse the repository at this point in the history
… the transaction object (#7323)

* fix: Use Builder for JsonCallParameter
* changelog
* add additional unit tests
* fix: Update builder to withGas to match the json eth_call
---------

Signed-off-by: Usman Saleem <usman@usmans.info>
  • Loading branch information
usmansaleem authored Jul 16, 2024
1 parent 223f1bc commit 3366f79
Show file tree
Hide file tree
Showing 15 changed files with 725 additions and 692 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Implement gnark-crypto for eip-2537 [#7316](https://github.com/hyperledger/besu/pull/7316)

### Bug fixes
- Fix `eth_call` deserialization to correctly ignore unknown fields in the transaction object. [#7323](https://github.com/hyperledger/besu/pull/7323)

## 24.7.0

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ public void shouldSucceedWhenCreateAccessListMultipleReads() {
"0x0000000000000000000000000000000000000000000000000000000000000003"))));

final JsonCallParameter callParameter =
createAccessListJsonCallParameters(
"0x658bdf435d810c91414ec09147daa6db62406379",
"0xbb00000000000000000000000000000000000000",
null);
new JsonCallParameter.JsonCallParameterBuilder()
.withFrom(Address.fromHexString("0x658bdf435d810c91414ec09147daa6db62406379"))
.withTo(Address.fromHexString("0xbb00000000000000000000000000000000000000"))
.withAccessList(null)
.build();

assertAccessListExpectedResult(callParameter, expectedAccessListEntryList, expectedGasUsed);
}
Expand All @@ -101,10 +102,11 @@ public void shouldSucceedWhenCreateAccessListMultipleReads_withAccessListParam()
"0x0000000000000000000000000000000000000000000000000000000000000003"))));

final JsonCallParameter callParameter =
createAccessListJsonCallParameters(
"0x658bdf435d810c91414ec09147daa6db62406379",
"0xbb00000000000000000000000000000000000000",
expectedAccessListEntryList);
new JsonCallParameter.JsonCallParameterBuilder()
.withFrom(Address.fromHexString("0x658bdf435d810c91414ec09147daa6db62406379"))
.withTo(Address.fromHexString("0xbb00000000000000000000000000000000000000"))
.withAccessList(expectedAccessListEntryList)
.build();

assertAccessListExpectedResult(callParameter, expectedAccessListEntryList, expectedGasUsed);
}
Expand All @@ -115,10 +117,11 @@ public void shouldSucceedWhenCreateAccessListSimpleTransfer() {
final List<AccessListEntry> expectedAccessListEntryList = new ArrayList<>();

final JsonCallParameter callParameter =
createAccessListJsonCallParameters(
"0x658bdf435d810c91414ec09147daa6db62406379",
"0x0100000000000000000000000000000000000000",
expectedAccessListEntryList);
new JsonCallParameter.JsonCallParameterBuilder()
.withFrom(Address.fromHexString("0x658bdf435d810c91414ec09147daa6db62406379"))
.withTo(Address.fromHexString("0x0100000000000000000000000000000000000000"))
.withAccessList(expectedAccessListEntryList)
.build();

assertAccessListExpectedResult(callParameter, expectedAccessListEntryList, expectedGasUsed);
}
Expand All @@ -129,19 +132,20 @@ public void shouldSucceedWhenCreateAccessListSimpleContract() {
final List<AccessListEntry> expectedAccessListEntryList = new ArrayList<>();

final JsonCallParameter callParameter =
createAccessListJsonCallParameters(
"0x658bdf435d810c91414ec09147daa6db62406379",
"0xaa00000000000000000000000000000000000000",
null);
new JsonCallParameter.JsonCallParameterBuilder()
.withFrom(Address.fromHexString("0x658bdf435d810c91414ec09147daa6db62406379"))
.withTo(Address.fromHexString("0xaa00000000000000000000000000000000000000"))
.withAccessList(null)
.build();

assertAccessListExpectedResult(callParameter, expectedAccessListEntryList, expectedGasUsed);
}

@Test
public void shouldReturnExpectedValueForEmptyCallParameter() {
final JsonCallParameter callParameter =
new JsonCallParameter(
null, null, null, null, null, null, null, null, null, null, null, null, null);
new JsonCallParameter.JsonCallParameterBuilder().build();

final JsonRpcRequestContext request = requestWithParams(callParameter);
final JsonRpcResponse expectedResponse =
new JsonRpcSuccessResponse(null, new CreateAccessListResult(new ArrayList<>(), 0xcf08));
Expand All @@ -154,20 +158,12 @@ public void shouldReturnExpectedValueForEmptyCallParameter() {
@Test
public void shouldReturnExpectedValueForTransfer() {
final JsonCallParameter callParameter =
new JsonCallParameter(
Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"),
Address.fromHexString("0x8888f1f195afa192cfee860698584c030f4c9db1"),
null,
null,
null,
null,
Wei.ZERO,
null,
null,
null,
null,
null,
null);
new JsonCallParameter.JsonCallParameterBuilder()
.withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"))
.withTo(Address.fromHexString("0x8888f1f195afa192cfee860698584c030f4c9db1"))
.withValue(Wei.ZERO)
.build();

final JsonRpcRequestContext request = requestWithParams(callParameter);
final JsonRpcResponse expectedResponse =
new JsonRpcSuccessResponse(null, new CreateAccessListResult(new ArrayList<>(), 0x5208));
Expand All @@ -180,21 +176,13 @@ public void shouldReturnExpectedValueForTransfer() {
@Test
public void shouldReturnExpectedValueForContractDeploy() {
final JsonCallParameter callParameter =
new JsonCallParameter(
Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"),
null,
null,
null,
null,
null,
null,
Bytes.fromHexString(
"0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"),
null,
null,
null,
null,
null);
new JsonCallParameter.JsonCallParameterBuilder()
.withFrom(Address.fromHexString("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b"))
.withInput(
Bytes.fromHexString(
"0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"))
.build();

final JsonRpcRequestContext request = requestWithParams(callParameter);
final JsonRpcResponse expectedResponse =
new JsonRpcSuccessResponse(null, new CreateAccessListResult(new ArrayList<>(), 0x1f081));
Expand All @@ -207,21 +195,16 @@ public void shouldReturnExpectedValueForContractDeploy() {
@Test
public void shouldIgnoreSenderBalanceAccountWhenStrictModeDisabledAndReturnExpectedValue() {
final JsonCallParameter callParameter =
new JsonCallParameter(
Address.fromHexString("0x0000000000000000000000000000000000000000"),
null,
1L,
Wei.fromHexString("0x9999999999"),
null,
null,
null,
Bytes.fromHexString(
"0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"),
null,
false,
null,
null,
null);
new JsonCallParameter.JsonCallParameterBuilder()
.withFrom(Address.fromHexString("0x0000000000000000000000000000000000000000"))
.withGas(1L)
.withGasPrice(Wei.fromHexString("0x9999999999"))
.withInput(
Bytes.fromHexString(
"0x608060405234801561001057600080fd5b50610157806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633bdab8bf146100515780639ae97baa14610068575b600080fd5b34801561005d57600080fd5b5061006661007f565b005b34801561007457600080fd5b5061007d6100b9565b005b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60016040518082815260200191505060405180910390a1565b7fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60026040518082815260200191505060405180910390a17fa53887c1eed04528e23301f55ad49a91634ef5021aa83a97d07fd16ed71c039a60036040518082815260200191505060405180910390a15600a165627a7a7230582010ddaa52e73a98c06dbcd22b234b97206c1d7ed64a7c048e10c2043a3d2309cb0029"))
.withStrict(false)
.build();

final JsonRpcRequestContext request = requestWithParams(callParameter);
final JsonRpcResponse expectedResponse =
new JsonRpcSuccessResponse(null, new CreateAccessListResult(new ArrayList<>(), 0x1f081));
Expand All @@ -234,8 +217,7 @@ public void shouldIgnoreSenderBalanceAccountWhenStrictModeDisabledAndReturnExpec
@Test
public void shouldReturnExpectedValueForInsufficientGas() {
final JsonCallParameter callParameter =
new JsonCallParameter(
null, null, 1L, null, null, null, null, null, null, null, null, null, null);
new JsonCallParameter.JsonCallParameterBuilder().withGas(1L).build();
final JsonRpcRequestContext request = requestWithParams(callParameter);
final JsonRpcResponse expectedResponse =
new JsonRpcSuccessResponse(null, new CreateAccessListResult(new ArrayList<>(), 0xcf08));
Expand All @@ -257,24 +239,6 @@ private void assertAccessListExpectedResult(
assertThat(response).usingRecursiveComparison().isEqualTo(expectedResponse);
}

private JsonCallParameter createAccessListJsonCallParameters(
final String from, final String to, final List<AccessListEntry> accessList) {
return new JsonCallParameter(
Address.fromHexString(from),
Address.fromHexString(to),
null,
null,
null,
null,
null,
null,
null,
null,
accessList,
null,
null);
}

private JsonRpcRequestContext requestWithParams(final Object... params) {
return new JsonRpcRequestContext(new JsonRpcRequest("2.0", "eth_createAccessList", params));
}
Expand Down
Loading

0 comments on commit 3366f79

Please sign in to comment.