If we make for example a smart contract with a require function that is always false and we execute it tons of times (knowing that we will get our gas back cause of the revert function)will we be able to jam the eth network for free?
1 Answer
Not for free, since you only get the remaining gas back.
Here is a short test for illustrating that:
Solidity Contract:
pragma solidity 0.6.12;
contract MyContract {
function test() public {
revert();
}
}
Truffle 5.x Test:
contract("test", function (accounts) {
it("test", async function () {
const myContract = await artifacts.require("MyContract").new();
const balanceBefore = web3.utils.toBN(await web3.eth.getBalance(accounts[0]));
try {
await myContract.test();
}
catch (error) {
}
const balanceAfter = web3.utils.toBN(await web3.eth.getBalance(accounts[0]));
console.log(web3.utils.fromWei(balanceBefore.sub(balanceAfter)).toString());
});
});
The printout indicates that the sender account has spent 0.00042366 ether.