Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

toknapp/contracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Upvest's smart contracts

CircleCI

Forwarding contract

Background (the why)

While thinking about how to allow users to manage their ERC20 tokens in our platform without knowing anything about the Ethereum blockchain (including having to hold any ether), we stumbled upon the idea that what's really needed is for us to be the transaction originator (paying the gas) while having an intermediate contract talking to the ERC20 contracts (so that it will be the msg.sender in the call).

References

The code (the how)

Pseudo implementation

def forward(self, sig, target, value, input):
    assert(ecrecover(keccak256(self.address + target + value + self.nonce + input), sig) == self.owner)
    self.nonce += 1
    return call(target, value, input)

Notice the fact that the contracts address is included in the signature, in order to prevent the transaction from being replayed to a cloned contract. Consider the scenario with a voting contract: the user votes through his forwarding contract, then without this check a malicious user can deploy copies of the forwarding contract (with the same owner) and replay the voting call.