I would like to return partially fees to users of my dApp. Once they have reached X amount in fees, I want to make a function that will pay them ethereum automatically. Now my question: Is that secure? Or can they cheat? The code is following: In the beginning of every function, I call
uint _gasBegin = gasleft();
And in the end
uint _gasEnd = _gasBegin.sub(gasleft()); gasPaid[msg.sender] = gasPaid[msg.sender].add(_gasEnd);
Once they reached for example 0.001 ethereum in gas fees, they can call the funcion
that will transfer gasPaid[msg.sender] to them.
Edit: One way to cheat could be, that a miner sets a very high gas price in hope to empty the wallet. But however, he will not 100% surely mine the block and if it fails, he loses the fees to an other miner. Also I will limit this by allowing a max. price of for example 15 wei to be eligle to get back the fees by using (tx.gasprice <= 15, can be changed).
1) A secure way, without them being able to cheat and
2) maybe improveable?