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
1 change: 1 addition & 0 deletions scripts/known-failing-hive-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ eth_simulateV1/ethSimulate-check-invalid-nonce (nethermind)
eth_simulateV1/ethSimulate-gas-fees-and-value-error-38014-with-validation (nethermind)
eth_simulateV1/ethSimulate-simple-no-funds-with-validation (nethermind)
eth_simulateV1/ethSimulate-simple-no-funds-with-validation-without-nonces (nethermind)
eth_simulateV1/ethSimulate-simple-send-from-contract-with-validation (nethermind)

# graphql

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,4 +702,141 @@ public async Task eth_simulateV1_intrinsic_gas_returns_spec_error_code_and_messa
Assert.That(result.Result!.Error, Is.EqualTo(SimulateErrorMessages.IntrinsicGas));
}

/// <summary>
/// Regression test: eth_simulateV1 with validation:true and a nonce below the account's current
/// nonce must return -38010 (NonceTooLow).
/// </summary>
[Test]
public async Task eth_simulateV1_nonce_too_low_returns_spec_error_code()
{
TestRpcBlockchain chain = await EthRpcSimulateTestsBase.CreateChain();

// Set the account's nonce to 10, then send a tx with nonce 0 (below current).
SimulatePayload<TransactionForRpc> payload = new()
{
BlockStateCalls =
[
new()
{
StateOverrides = new Dictionary<Address, AccountOverride>
{
{ TestItem.AddressA, new AccountOverride { Balance = 1.Ether, Nonce = 10 } }
},
Calls =
[
new LegacyTransactionForRpc
{
From = TestItem.AddressA,
To = TestItem.AddressB,
Value = UInt256.Zero,
Nonce = 0,
GasPrice = UInt256.Zero,
Gas = 21_000
}
]
}
],
Validation = true
};

ResultWrapper<IReadOnlyList<SimulateBlockResult<SimulateCallResult>>> result =
chain.EthRpcModule.eth_simulateV1(payload, BlockParameter.Latest);

Assert.That(result.ErrorCode, Is.EqualTo(ErrorCodes.NonceTooLow));
}

/// <summary>
/// Regression test: eth_simulateV1 with validation:true and a nonce above the account's current
/// nonce must return -38011 (NonceTooHigh).
/// </summary>
[Test]
public async Task eth_simulateV1_nonce_too_high_returns_spec_error_code()
{
TestRpcBlockchain chain = await EthRpcSimulateTestsBase.CreateChain();

// Account nonce is 0; send a tx with nonce 100 (way above current).
SimulatePayload<TransactionForRpc> payload = new()
{
BlockStateCalls =
[
new()
{
StateOverrides = new Dictionary<Address, AccountOverride>
{
{ TestItem.AddressA, new AccountOverride { Balance = 1.Ether } }
},
Calls =
[
new LegacyTransactionForRpc
{
From = TestItem.AddressA,
To = TestItem.AddressB,
Value = UInt256.Zero,
Nonce = 100,
GasPrice = UInt256.Zero,
Gas = 21_000
}
]
}
],
Validation = true
};

ResultWrapper<IReadOnlyList<SimulateBlockResult<SimulateCallResult>>> result =
chain.EthRpcModule.eth_simulateV1(payload, BlockParameter.Latest);

Assert.That(result.ErrorCode, Is.EqualTo(ErrorCodes.NonceTooHigh));
}

/// <summary>
/// Regression test: eth_simulateV1 with validation:true and a sender address that has deployed
/// code (EIP-3607) must return -38024 (SenderIsNotEoa).
/// </summary>
[Test]
public async Task eth_simulateV1_sender_is_not_eoa_returns_spec_error_code()
{
OverridableReleaseSpec spec = new(London.Instance) { IsEip3607Enabled = true };
TestSpecProvider specProvider = new(spec) { AllowTestChainOverride = false };
TestRpcBlockchain chain = await TestRpcBlockchain.ForTest(new TestRpcBlockchain()).Build(specProvider);

// Override TestItem.AddressC with contract code — makes it a non-EOA sender.
SimulatePayload<TransactionForRpc> payload = new()
{
BlockStateCalls =
[
new()
{
StateOverrides = new Dictionary<Address, AccountOverride>
{
{
TestItem.AddressC,
new AccountOverride
{
Balance = 1.Ether,
Code = Bytes.FromHexString("0x60006000")
}
}
},
Calls =
[
new LegacyTransactionForRpc
{
From = TestItem.AddressC,
To = TestItem.AddressB,
Value = UInt256.Zero,
GasPrice = UInt256.Zero,
Gas = 21_000
}
]
}
],
Validation = true
};

ResultWrapper<IReadOnlyList<SimulateBlockResult<SimulateCallResult>>> result =
chain.EthRpcModule.eth_simulateV1(payload, BlockParameter.Latest);

Assert.That(result.ErrorCode, Is.EqualTo(ErrorCodes.SenderIsNotEoa));
}

}
23 changes: 19 additions & 4 deletions src/Nethermind/Nethermind.JsonRpc/ErrorCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,28 +122,43 @@ public static class ErrorCodes
/// </summary>
public const int Default = -32000;

/// <summary>
/// Transaction nonce is lower than the account's current nonce — eth_simulateV1 spec error
/// </summary>
public const int NonceTooLow = -38010;

/// <summary>
/// Transaction nonce is higher than the account's current nonce — eth_simulateV1 spec error
/// </summary>
public const int NonceTooHigh = -38011;

/// <summary>
/// Transaction maxFeePerGas is below the block base fee — eth_simulateV1 spec error
/// </summary>
public const int FeeCapBelowBaseFee = -38012;

/// <summary>
/// Transaction gas limit is below the intrinsic gas cost
/// Transaction gas limit is below the intrinsic gas cost — eth_simulateV1 spec error
/// </summary>
public const int IntrinsicGas = -38013;

/// <summary>
/// Not enough value to cover transaction costs
/// Not enough value to cover transaction costs — eth_simulateV1 spec error
/// </summary>
public const int InsufficientFunds = -38014;

/// <summary>
/// Gas limit reached
/// Gas limit reached — eth_simulateV1 spec error
/// </summary>
public const int BlockGasLimitReached = -38015;

/// <summary>
/// EIP-3860. Code size is to big
/// Sender account has deployed code (is not an EOA) — eth_simulateV1 spec error
/// </summary>
public const int SenderIsNotEoa = -38024;

/// <summary>
/// EIP-3860. Code size is too big — eth_simulateV1 spec error
/// </summary>
public const int MaxInitCodeSizeExceeded = -38025;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,11 @@ private static int MapSimulateErrorCode(TransactionResult txResult)
TransactionResult.ErrorType.MaxFeePerGasBelowBaseFee
or TransactionResult.ErrorType.MinerPremiumNegative => ErrorCodes.FeeCapBelowBaseFee,
TransactionResult.ErrorType.NonceOverflow => ErrorCodes.InternalError,
TransactionResult.ErrorType.SenderHasDeployedCode => ErrorCodes.InvalidParams,
TransactionResult.ErrorType.SenderHasDeployedCode => ErrorCodes.SenderIsNotEoa,
TransactionResult.ErrorType.SenderNotSpecified => ErrorCodes.InternalError,
TransactionResult.ErrorType.TransactionSizeOverMaxInitCodeSize => ErrorCodes.MaxInitCodeSizeExceeded,
TransactionResult.ErrorType.TransactionNonceTooHigh => ErrorCodes.InternalError,
TransactionResult.ErrorType.TransactionNonceTooLow => ErrorCodes.InternalError,
TransactionResult.ErrorType.TransactionNonceTooHigh => ErrorCodes.NonceTooHigh,
Comment thread
DarkLord017 marked this conversation as resolved.
TransactionResult.ErrorType.TransactionNonceTooLow => ErrorCodes.NonceTooLow,
_ => ErrorCodes.InternalError
};
}
Expand Down
Loading