Last active
July 19, 2016 22:07
-
-
Save trapp/845e9a0a52542e33e8ae3a1a3be03a11 to your computer and use it in GitHub Desktop.
ReplaySafeProxy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 inrsproxy.send(1 ether)
. But since this current fallback function uses more than 2300 gas, this breakssend()
and nowrsproxy.call.value(1 ether)()
has to be used. Given that's the case, why not make it a normal function, saytransfer(uint numberOfWei)
, and thenrsproxy.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