Skip to content

Instantly share code, notes, and snippets.

@trapp
Last active July 19, 2016 22:07
Show Gist options
  • Save trapp/845e9a0a52542e33e8ae3a1a3be03a11 to your computer and use it in GitHub Desktop.
Save trapp/845e9a0a52542e33e8ae3a1a3be03a11 to your computer and use it in GitHub Desktop.
ReplaySafeProxy
contract ReplaySafeProxy {
// Tracks if the contract should work on this chain or not.
bool enabled = false;
// Fork oracle to use
AmIOnTheFork amIOnTheFork = AmIOnTheFork(0x2bd2326c993dfaef84f696526064ff22eba5b362);
address target;
// _target is the address this contract will forward all funds to.
// forked specifies if it should work on ETH (true) or ETHC (false)
// Any value transfer to this contract will fail on the other network.
function ReplaySafeProxy (address _target, bool forked) {
if (amIOnTheFork.forked() == forked) {
enabled = true;
}
target = _target;
}
// Forward value transfers.
function() {
if (enabled == false || msg.value == 0 || !target.send(msg.value)) {
throw;
}
}
}
@ethers
Copy link

ethers commented Jul 19, 2016

Hi, why not give the function a name? https://gist.github.com/trapp/845e9a0a52542e33e8ae3a1a3be03a11#file-replaysafeproxy-sol-L19

This would then be consistent with 2 main recommendations [1,2], instead of going against them.
Using a fallback function can help if send() can be used, as in rsproxy.send(1 ether). But since this current fallback function uses more than 2300 gas, this breaks send() and now rsproxy.call.value(1 ether)() has to be used. Given that's the case, why not make it a normal function, say transfer(uint numberOfWei), and then rsproxy.transfer(1 ether) can be used.

[1] https://github.com/ethereum/wiki/wiki/safety#keep-fallback-functions-simple
[2] https://github.com/ethereum/wiki/wiki/safety#use-send-avoid-callvalue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment