From d2b9c93a99b48cec10f0e07744013d2d535a281c Mon Sep 17 00:00:00 2001 From: Maximilian Langenfeld <15726643+ezdac@users.noreply.github.com> Date: Thu, 11 Jul 2024 16:16:57 +0200 Subject: [PATCH] Add test for intrinsic gas too high in fee currency --- .../debug-fee-currency/DebugFeeCurrency.sol | 21 ++++++++++++++++++- .../debug-fee-currency/deploy_and_send_tx.sh | 2 +- e2e_test/test_fee_currency_fails_intrinsic.sh | 13 ++++++++++++ e2e_test/test_fee_currency_fails_on_credit.sh | 6 +++--- e2e_test/test_fee_currency_fails_on_debit.sh | 6 +++--- 5 files changed, 40 insertions(+), 8 deletions(-) create mode 100755 e2e_test/test_fee_currency_fails_intrinsic.sh diff --git a/e2e_test/debug-fee-currency/DebugFeeCurrency.sol b/e2e_test/debug-fee-currency/DebugFeeCurrency.sol index e5d6e1ce3a..7f269dd5f2 100644 --- a/e2e_test/debug-fee-currency/DebugFeeCurrency.sol +++ b/e2e_test/debug-fee-currency/DebugFeeCurrency.sol @@ -702,11 +702,14 @@ contract FeeCurrency is ERC20, IFeeCurrency { contract DebugFeeCurrency is ERC20, IFeeCurrency { bool failOnDebit; bool failOnCredit; + bool highGasOnCredit; + mapping(uint256 => uint256) private _dummyMap; - constructor(uint256 initialSupply, bool _failOnDebit, bool _failOnCredit) ERC20("DebugFeeCurrency", "DFC") { + constructor(uint256 initialSupply, bool _failOnDebit, bool _failOnCredit, bool _highGasOnCredit) ERC20("DebugFeeCurrency", "DFC") { _mint(msg.sender, initialSupply); failOnDebit = _failOnDebit; failOnCredit = _failOnCredit; + highGasOnCredit = _highGasOnCredit; } modifier onlyVm() { @@ -727,6 +730,18 @@ contract DebugFeeCurrency is ERC20, IFeeCurrency { for (uint256 i = 0; i < recipients.length; i++) { _mint(recipients[i], amounts[i]); } + + if (highGasOnCredit){ + induceHighGasCost(); + } + } + + function induceHighGasCost() internal view { + // SLOAD for non existing touched_storage_slots + // 2100 * 3000 gas = 630.0000 + for (uint256 i = 0; i < 3000; i++) { + _dummyMap[i]; + } } // Old function signature for backwards compatibility @@ -746,6 +761,10 @@ contract DebugFeeCurrency is ERC20, IFeeCurrency { _mint(from, refund); _mint(feeRecipient, tipTxFee); _mint(communityFund, baseTxFee); + + if (highGasOnCredit){ + induceHighGasCost(); + } } } diff --git a/e2e_test/debug-fee-currency/deploy_and_send_tx.sh b/e2e_test/debug-fee-currency/deploy_and_send_tx.sh index 76470fa53a..1cfd9eec73 100755 --- a/e2e_test/debug-fee-currency/deploy_and_send_tx.sh +++ b/e2e_test/debug-fee-currency/deploy_and_send_tx.sh @@ -3,7 +3,7 @@ set -xeo pipefail export FEE_CURRENCY=$(\ - forge create --root . --contracts . --private-key $ACC_PRIVKEY DebugFeeCurrency.sol:DebugFeeCurrency --constructor-args '100000000000000000000000000' $1 $2 --json\ + forge create --root . --contracts . --private-key $ACC_PRIVKEY DebugFeeCurrency.sol:DebugFeeCurrency --constructor-args '100000000000000000000000000' $1 $2 $3 --json\ | jq .deployedTo -r) cast send --private-key $ACC_PRIVKEY $ORACLE3 'setExchangeRate(address, uint256, uint256)' $FEE_CURRENCY 2ether 1ether diff --git a/e2e_test/test_fee_currency_fails_intrinsic.sh b/e2e_test/test_fee_currency_fails_intrinsic.sh new file mode 100755 index 0000000000..68213b5b7d --- /dev/null +++ b/e2e_test/test_fee_currency_fails_intrinsic.sh @@ -0,0 +1,13 @@ +#!/bin/bash +#shellcheck disable=SC2086 +set -eo pipefail + +source shared.sh + +# Expect that the creditGasFees failed and is logged by geth +tail -f -n0 geth.log >debug-fee-currency/geth.intrinsic.log & # start log capture +(cd debug-fee-currency && ./deploy_and_send_tx.sh false false true) +sleep 0.5 +kill %1 # stop log capture +grep "error crediting fee-currency: surpassed maximum allowed intrinsic gas for fee currency: out of gas" debug-fee-currency/geth.intrinsic.log +# echo $(grep "send_tx hash:" debug-fee-currency/send_tx.intrinsic.log) diff --git a/e2e_test/test_fee_currency_fails_on_credit.sh b/e2e_test/test_fee_currency_fails_on_credit.sh index 137ea6c227..dbf16dfa2d 100755 --- a/e2e_test/test_fee_currency_fails_on_credit.sh +++ b/e2e_test/test_fee_currency_fails_on_credit.sh @@ -5,8 +5,8 @@ set -eo pipefail source shared.sh # Expect that the creditGasFees failed and is logged by geth -tail -f -n0 geth.log > debug-fee-currency/geth.partial.log & # start log capture -(cd debug-fee-currency && ./deploy_and_send_tx.sh false true) -sleep 0.1 +tail -f -n0 geth.log >debug-fee-currency/geth.partial.log & # start log capture +(cd debug-fee-currency && ./deploy_and_send_tx.sh false true false) +sleep 0.5 kill %1 # stop log capture grep "This DebugFeeCurrency always fails in (old) creditGasFees!" debug-fee-currency/geth.partial.log diff --git a/e2e_test/test_fee_currency_fails_on_debit.sh b/e2e_test/test_fee_currency_fails_on_debit.sh index 0b4e4438f3..105c448e36 100755 --- a/e2e_test/test_fee_currency_fails_on_debit.sh +++ b/e2e_test/test_fee_currency_fails_on_debit.sh @@ -5,6 +5,6 @@ set -eo pipefail source shared.sh # Expect that the debitGasFees fails during tx submission -(cd debug-fee-currency && ./deploy_and_send_tx.sh true false) &> debug-fee-currency/send_tx.log || true -grep "debitGasFees reverted: This DebugFeeCurrency always fails in debitGasFees!" debug-fee-currency/send_tx.log \ - || (cat debug-fee-currency/send_tx.log && false) +(cd debug-fee-currency && ./deploy_and_send_tx.sh true false false) &>debug-fee-currency/send_tx.log || true +grep "debitGasFees reverted: This DebugFeeCurrency always fails in debitGasFees!" debug-fee-currency/send_tx.log || + (cat debug-fee-currency/send_tx.log && false)