Skip to content

Commit

Permalink
Merge pull request #2267 from greymistcube/refactor/tx-policy
Browse files Browse the repository at this point in the history
🔧 Do not allow negative gas price or negative gas limit
  • Loading branch information
greymistcube authored Dec 4, 2023
2 parents c793c77 + f69be6f commit cc3caab
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Lib9c.Policy/Policy/BlockPolicySource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,21 @@ internal static TxPolicyViolationException ValidateNextBlockTxRaw(
return null;
}
}
if (transaction.MaxGasPrice is null || transaction.GasLimit is null)

if (!(transaction.MaxGasPrice is { } gasPrice && transaction.GasLimit is { } gasLimit))
{
return new TxPolicyViolationException(
"Transaction has no gas price or limit.",
transaction.Id);
}

if (gasPrice.Sign < 0 || gasLimit < 0)
{
return new
TxPolicyViolationException("Transaction has no gas price or limit.",
return new TxPolicyViolationException(
"Transaction has negative gas price or limit.",
transaction.Id);
}

if (transaction.MaxGasPrice * transaction.GasLimit > blockChain.GetBalance(transaction.Signer, Currencies.Mead))
{
return new TxPolicyViolationException(
Expand Down

0 comments on commit cc3caab

Please sign in to comment.