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

Delegated txs #89

Merged
merged 26 commits into from
May 12, 2018
Merged

Delegated txs #89

merged 26 commits into from
May 12, 2018

Conversation

szerintedmi
Copy link
Member

@szerintedmi szerintedmi commented May 4, 2018

  • added AugmintToken.delegatedTransfer() and delegatedTransferAndNotify() see Transferring A-EUR without ETH #84
  • emit separate Transfer event for transfer fee deduction
  • added web3 v1 to tests and changed them to use it solely (could make tx signature work with web3 v1 only and truffle uses v0.x)

@szerintedmi szerintedmi requested a review from phraktle May 5, 2018 09:15
@szerintedmi szerintedmi changed the title Delegate txs Delegated txs May 5, 2018
/* Transfers based on an offline signed transfer instruction. */
function delegatedTransfer(address from, address to, uint amount, string narrative,
uint minGasPrice, /* client provided gasPrice on which she expects tx to be exec. */
uint maxExecutorFee, /* client provided max fee for executing the tx */
Copy link
Collaborator

@phraktle phraktle May 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specify units of measure (e.g. gas price is in ETH. is fee in ETH or tokens?)

)
external returns(bool) {

require(!noncesUsed[nonce], "nonce already used");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the nonce should be included in a hash along with all other parameters (or just use the signature) and we should store the used hashes (not the nonce). otherwise there's a security issue: I could censor transactions by front-running the nonce from the mem-pool.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, you could get away with much less bits for the nonce then. you just need to avoid collisions between transactions with the same from/to/amount.

Copy link
Member Author

@szerintedmi szerintedmi May 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. nonce was already included in the hash
  2. pushed a change to store hashes used instead of nonce
  3. lower nonce bits: based on my tests passing+keccak256 of uint32 or bytes4 types actually consume slightly more gas than uint256 or bytes32. Maybe keccak256 is padding each param to same size?

external returns(bool) {

require(!noncesUsed[nonce], "nonce already used");
require(tx.gasprice >= minGasPrice, "tx.gasprice must be >= minGasPrice");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we care about the gas price at this point? the transaction is already being processed...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea is that client and "executor" agrees on an executorFee based on a minimum gasPrice. That's what the client signs. This way dishonest executors can't make "extra profit" on submitting tx on lower gas price than the "agreement".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the goal is to minimize the time it takes for my tx to hit the blockchain, not to maximize the profits of miners :) this is not an incentive (or disincentive) for executors.

the only way to ensure that my tx hits the chain in a timely manner is to have some competition between executors. if there's only a single executor for my tx, they may delay my tx for days even if i specified a high gas price. competition would keep them motivated to do their job well.

if an executor was able to have my transaction processed quickly at a lower gas price, they should keep the change. however, if they skimp on the gas too much, competition will beat them to the punch.

(i could also think of more incentives for timely processing, such as expiration dates or rewards diminishing over time.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as for now do you suggest to get rid of minGasprice ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

@@ -26,6 +26,7 @@ contract AugmintTokenInterface is Restricted, ERC20Interface {
mapping(address => mapping (address => uint256)) public allowed; // allowances added with approve()

TransferFeeInterface public feeAccount;
mapping(bytes32 => bool) public noncesUsed; // record nonces used by delegatedTransfer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see a prior comment (store tx hashes, not nonces)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, done

)
external returns(bool) {

require(!noncesUsed[nonce], "nonce already used");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, you could get away with much less bits for the nonce then. you just need to avoid collisions between transactions with the same from/to/amount.

external returns(bool) {

require(!noncesUsed[nonce], "nonce already used");
require(tx.gasprice >= minGasPrice, "tx.gasprice must be >= minGasPrice");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the goal is to minimize the time it takes for my tx to hit the blockchain, not to maximize the profits of miners :) this is not an incentive (or disincentive) for executors.

the only way to ensure that my tx hits the chain in a timely manner is to have some competition between executors. if there's only a single executor for my tx, they may delay my tx for days even if i specified a high gas price. competition would keep them motivated to do their job well.

if an executor was able to have my transaction processed quickly at a lower gas price, they should keep the change. however, if they skimp on the gas too much, competition will beat them to the punch.

(i could also think of more incentives for timely processing, such as expiration dates or rewards diminishing over time.)


bytes32 txHash = keccak256(this, from, target, amount, data, minGasPrice, maxExecutorFeeInToken, nonce);

require(!delegatedTxHashesUsed[txHash], "txHash already used");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest factoring common code between the two delegated... functions.

@szerintedmi szerintedmi merged commit a2f6b11 into staging May 12, 2018
@szerintedmi szerintedmi deleted the delegate_txs branch May 23, 2018 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants