Skip to content

Commit

Permalink
Fix Antithesis NullPointerException in Evm (#6191)
Browse files Browse the repository at this point in the history
* Copy geth behavior

* Add nullable to data returned from createAccessList because it is creating empty data object that shhould not be there

---------

Co-authored-by: smartprogrammer <[email protected]>
  • Loading branch information
Demuirgos and smartprogrammer93 authored Oct 14, 2023
1 parent ad4a534 commit 9672bae
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ public async Task Eth_call_ok()
Assert.That(serialized, Is.EqualTo("{\"jsonrpc\":\"2.0\",\"result\":\"0x\",\"id\":67}"));
}

[Test]
public async Task Eth_call_create_tx_with_empty_data()
{
using Context ctx = await Context.Create();
TransactionForRpc transaction = new(Keccak.Zero, 1L, 1, new Transaction());
transaction.From = TestItem.AddressA;

string serialized =
await ctx.Test.TestEthRpc("eth_call", ctx.Test.JsonSerializer.Serialize(transaction), "latest");
serialized.Should().BeEquivalentTo("{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32000,\"message\":\"Contract creation without any data provided.\"},\"id\":67}");
}

[Test]
public async Task Eth_call_missing_state_after_fast_sync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public ResultWrapper<TResult> ExecuteTx(

using CancellationTokenSource cancellationTokenSource = new(_rpcConfig.Timeout);
Transaction tx = transactionCall.ToTransaction(_blockchainBridge.GetChainId());
if (tx.IsContractCreation && tx.DataLength == 0)
{
return ResultWrapper<TResult>.Fail("Contract creation without any data provided.",
ErrorCodes.InvalidInput);
}
return ExecuteTx(header.Clone(), tx, cancellationTokenSource.Token);
}

Expand Down Expand Up @@ -106,7 +111,7 @@ public EstimateGasTxExecutor(IBlockchainBridge blockchainBridge, IBlockFinder bl
}
}

private class CreateAccessListTxExecutor : TxExecutor<AccessListForRpc>
private class CreateAccessListTxExecutor : TxExecutor<AccessListForRpc?>
{
private readonly bool _optimize;

Expand All @@ -116,18 +121,18 @@ public CreateAccessListTxExecutor(IBlockchainBridge blockchainBridge, IBlockFind
_optimize = optimize;
}

protected override ResultWrapper<AccessListForRpc> ExecuteTx(BlockHeader header, Transaction tx, CancellationToken token)
protected override ResultWrapper<AccessListForRpc?> ExecuteTx(BlockHeader header, Transaction tx, CancellationToken token)
{
BlockchainBridge.CallOutput result = _blockchainBridge.CreateAccessList(header, tx, token, _optimize);

if (result.Error is null)
{
return ResultWrapper<AccessListForRpc>.Success(new(GetResultAccessList(tx, result), GetResultGas(tx, result)));
return ResultWrapper<AccessListForRpc?>.Success(new(GetResultAccessList(tx, result), GetResultGas(tx, result)));
}

return result.InputError
? GetInputError(result)
: ResultWrapper<AccessListForRpc>.Fail(result.Error, ErrorCodes.ExecutionError, new AccessListForRpc(GetResultAccessList(tx, result), GetResultGas(tx, result)));
: ResultWrapper<AccessListForRpc?>.Fail(result.Error, ErrorCodes.ExecutionError, new AccessListForRpc(GetResultAccessList(tx, result), GetResultGas(tx, result)));
}

private static IEnumerable<AccessListItemForRpc> GetResultAccessList(Transaction tx, BlockchainBridge.CallOutput result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public ResultWrapper<string> eth_call(TransactionForRpc transactionCall, BlockPa
new EstimateGasTxExecutor(_blockchainBridge, _blockFinder, _rpcConfig)
.ExecuteTx(transactionCall, blockParameter);

public ResultWrapper<AccessListForRpc> eth_createAccessList(TransactionForRpc transactionCall, BlockParameter? blockParameter = null, bool optimize = true) =>
public ResultWrapper<AccessListForRpc?> eth_createAccessList(TransactionForRpc transactionCall, BlockParameter? blockParameter = null, bool optimize = true) =>
new CreateAccessListTxExecutor(_blockchainBridge, _blockFinder, _rpcConfig, optimize)
.ExecuteTx(transactionCall, blockParameter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public ResultWrapper<string> eth_call(TransactionForRpc transactionCall, BlockPa
throw new NotSupportedException();
}

public ResultWrapper<AccessListForRpc> eth_createAccessList(TransactionForRpc transactionCall, BlockParameter? blockParameter = null, bool optimize = true)
public ResultWrapper<AccessListForRpc?> eth_createAccessList(TransactionForRpc transactionCall, BlockParameter? blockParameter = null, bool optimize = true)
{
throw new NotSupportedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public interface IEthRpcModule : IRpcModule
EdgeCaseHint = "If your transaction has code executed, then you can generate transaction access list with eth_createAccessList. If you send it with your transaction then it will lower your gas cost on Ethereum",
IsSharable = false,
ExampleResponse = "{\"accessList\":[{\"address\":\"0xfffffffffffffffffffffffffffffffffffffffe\",\"storageKeys\":[\"0x0000000000000000000000000000000000000000000000000000000000000001\",\"0x0000000000000000000000000000000000000000000000000000000000000002\"]},{\"address\":\"0x76e68a8696537e4141926f3e528733af9e237d69\",\"storageKeys\":[]}],\"gasUsed\":\"0xf71b\"}")]
ResultWrapper<AccessListForRpc> eth_createAccessList(
ResultWrapper<AccessListForRpc?> eth_createAccessList(
[JsonRpcParameter(Description = "Transaction's details", ExampleValue = "[\"{\"type\":\"0x1\"]")]
TransactionForRpc transactionCall,
[JsonRpcParameter(Description = "(optional)")]
Expand Down

0 comments on commit 9672bae

Please sign in to comment.