Skip to content

Commit

Permalink
Add test for intrinsic gas too high in fee currency
Browse files Browse the repository at this point in the history
  • Loading branch information
ezdac committed Jul 31, 2024
1 parent 107ba04 commit d2b9c93
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
21 changes: 20 additions & 1 deletion e2e_test/debug-fee-currency/DebugFeeCurrency.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand All @@ -746,6 +761,10 @@ contract DebugFeeCurrency is ERC20, IFeeCurrency {
_mint(from, refund);
_mint(feeRecipient, tipTxFee);
_mint(communityFund, baseTxFee);

if (highGasOnCredit){
induceHighGasCost();
}
}
}

2 changes: 1 addition & 1 deletion e2e_test/debug-fee-currency/deploy_and_send_tx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions e2e_test/test_fee_currency_fails_intrinsic.sh
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 3 additions & 3 deletions e2e_test/test_fee_currency_fails_on_credit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions e2e_test/test_fee_currency_fails_on_debit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit d2b9c93

Please sign in to comment.