Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spending condition spendable by any wallet #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions contracts/mocks/SpendingCondition.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,37 @@ import "../PlasmaInterface.sol";
import "../Reflectable.sol";

contract SpendingCondition is Reflectable {
uint256 constant nonce = 1234; // nonce, so that signatures can not be replayed
uint constant value = 0;
uint constant mainNetNonce = 12345;
address constant spenderAddr = 0xF3beAC30C498D9E26865F34fCAa57dBB935b0D74;

function fulfil(bytes32 _r, bytes32 _s, uint8 _v, // signature
address _tokenAddr, // inputs
address[] memory _receivers, uint256[] memory _amounts) public { // outputs
require(_receivers.length == _amounts.length);

function fulfil(
bytes32 _nonce, //
uint _gasPrice,
uint _gasLimit,
address _to,
bytes _data,
bytes32 _r,
bytes32 _s,
uint8 _v) public {
// check signature
address signer = ecrecover(bytes32(ripemd160(bytecode(address(this)))), _v, _r, _s);
// if we are on plasma, 'this' is injected sigHash as here: https://github.com/leapdao/leap-node/blob/388aa6c698719e53bf7dee715fe4368c069b6db1/src/tx/applyTx/checkSpendCond.js#L165
// if on main-net, the address off the deployed contract needs to be signed.
// if on main-net, no replay protection after first signature. so spending condition should be emptied with first tx
if (_nonce != this) {
require(_nonce == mainNetNonce);
}
bytes32 hash = keccak256(_nonce, _gasPrice, _gasLimit, value, _to, _data);
address signer = ecrecover(hash, _v, _r, _s);
require(signer == spenderAddr);

// todo: check gasPrice and gasLimit
uint transferAmount = uint(_data); // pseudocode
uint balance = _tokenAddr.balanceOf(this);
require(balance - (_gasPrice * _gasLimit) == transferAmount);

// do transfer
ERC20 token = ERC20(_tokenAddr);
for (uint i = 0; i < _receivers.length; i++) {
token.transfer(_receivers[i], _amounts[i]);
}
_tokenAddr.call(_data);
}

function exitProxy(
Expand Down