Skip to content

Instantly share code, notes, and snippets.

@izqui

izqui/gas.sol Secret

Last active July 19, 2017 21:38
Show Gist options
  • Save izqui/e5591fc082f5cb0950d8c4a081c73d7e to your computer and use it in GitHub Desktop.
Save izqui/e5591fc082f5cb0950d8c4a081c73d7e to your computer and use it in GitHub Desktop.
Idea of a modifier for functions that call externally to assert the gas consumed in between. Protects against re-entrancy.
contract ConservativeSender {
ERC20 token;
modifier max_gas(uint max_delta) {
uint initialGas = msg.gas;
_;
assert(initialGas - msg.gas < max_delta);
}
function proxyTransfer(address _to, uint _value)
max_gas(110000) {
token.transfer(_to, _value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment