Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontrunning issue with gas: 'auto' vs gas: number ( neither works like in prev hardhat version ) #4471

Closed
moneyDev1111 opened this issue Oct 12, 2023 · 4 comments
Assignees
Labels
status:needs-more-info There's not enough information to start working on this issue

Comments

@moneyDev1111
Copy link

moneyDev1111 commented Oct 12, 2023

Version of Hardhat

2.17.3

What happened?

I'm simulating a frontrunning attack using one of the latest hardhat version ( yes, I've found the closed issue here, when it only allows a single tx to be in a block, without gas 'auto' in the config ( BUT it presents some new issue )).

In short, if I use gas: 'auto', frontrunning logic doesn't work... I have only 3 txs: contract deployment, victim tx and the attacker tx, and the evm_mine call at the end of the code.. ( I will provide it if you need it, but it seems like the problem should be clear for you hopefully even without it ).
So, when using gas auto, I don't even see my transaction, tho I'm using the victims tx data and sending it with the bigger gasPrice or maxPriorityFeePerGas ( I tried both ) amount. It seems like tho the block is not mined yet, hardhat is already decided that the victim's tx should be first, cause it's higher in the code or sth, and then the attacker tx is just being reverted cause the victim's tx already got ETH from the contract.

But when gas: number is used everything seems to work. BUT ONLY IF there's little amount of tx and they are not too complex. I can't get it work either way when I have lots of tx that I need to sort through to find the victim's tx.... Could you please explain why so and what's the proper way to 'fix' it if there's sth to fix in the first place. Thank you

Minimal reproduction steps

comparing behavior using gas: auto vs gas: number in the config

Search terms

No response

@github-project-automation github-project-automation bot moved this to Ready in Hardhat Oct 12, 2023
@moneyDev1111 moneyDev1111 changed the title gas: 'auto' vs gas: number frontrunning issue with gas: 'auto' vs gas: number ( neither works like in the prev verisons ) Oct 12, 2023
@moneyDev1111 moneyDev1111 changed the title frontrunning issue with gas: 'auto' vs gas: number ( neither works like in the prev verisons ) frontrunning issue with gas: 'auto' vs gas: number ( neither works like in prev hardhat verison ) Oct 12, 2023
@moneyDev1111 moneyDev1111 changed the title frontrunning issue with gas: 'auto' vs gas: number ( neither works like in prev hardhat verison ) frontrunning issue with gas: 'auto' vs gas: number ( neither works like in prev hardhat version ) Oct 12, 2023
@fvictorio
Copy link
Member

Hey @moneyDev1111, I'm not sure I understand your problem. If you are trying to simulate a frontrunning attack, then I guess you are disabling automining, sending a tx 1, and then sending a tx 2 with a higher gas price. Then, if you send a hardhat_mine method, both should be mined and tx 2 should be included first in the block. Is this what you are saying? I'm not sure what gas: "auto" has to do with this because that's related to the gas limit, not the gas price.

@fvictorio fvictorio added status:needs-more-info There's not enough information to start working on this issue and removed status:triaging labels Oct 20, 2023
@moneyDev1111
Copy link
Author

moneyDev1111 commented Oct 25, 2023

gas: 'auto' or gas: number changes the behavior of hardhat!!! the transactions order

@moneyDev1111
Copy link
Author

moneyDev1111 commented Oct 25, 2023

@fvictorio I will record a video a bit later for a better explanation, non of the settings allow frontrunning

@moneyDev1111
Copy link
Author

moneyDev1111 commented Oct 31, 2023

@fvictorio I've found the working settings for the newer version, If mining interval set to 0 seconds, everything works. If to 10 seconds - doesn't work. Could you please explain why such behavior? Thank you

50 seconds also works...
20 seconds also works
15 seconds DOESN'T
16 works

I see I needed to read the docs more carefully, the right answer is to use 0 seconds interval....

@github-project-automation github-project-automation bot moved this from Backlog to Done in Hardhat Oct 31, 2023
@moneyDev1111 moneyDev1111 reopened this Oct 31, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status:needs-more-info There's not enough information to start working on this issue
Projects
Archived in project
Development

No branches or pull requests

2 participants