Skip to content

micropayment channel example with two chapters #4212

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

Merged
merged 12 commits into from
Jul 10, 2018

Conversation

jvmaia
Copy link
Contributor

@jvmaia jvmaia commented May 31, 2018

fixes #4131

@chriseth
Copy link
Contributor

Thanks for the pull request! I Have not yet looked into it in detail, but some remarks that will also help in the review process:

  • please split long lines, it makes it much easier to comment on specific parts of a paragraph
  • note that all code in the documentation is compiled during the CI run, so please either create full contracts or - there is some way to mark it but I cannot look it up right now, sorry.

@jvmaia
Copy link
Contributor Author

jvmaia commented May 31, 2018

hey @chriseth, i don't know what is better here, write the full contracts or mark the pieces of code to not be compiled? what do you think about?

@jvmaia
Copy link
Contributor Author

jvmaia commented Jun 3, 2018

i'm going to write the full contracts and use the comments to explain what the code does and it importance

and the sender is sent the rest via a *selfdestruct*.
You can see the *close* function in the full contract.

Channel Expriration
Copy link
Member

Choose a reason for hiding this comment

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

Expiration*

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, fixing it now!

@jvmaia
Copy link
Contributor Author

jvmaia commented Jun 6, 2018

Any update is needed here?

Copy link
Contributor

@chriseth chriseth left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the detailed tutorial!
I will review the rest later, but could you please correct typos in the rest of the text first? Thanks!

@@ -645,4 +645,499 @@ Safe Remote Purchase
Micropayment Channel
********************

To be written.
Creating and verifying signatures
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it would be good to have 1-2 sentences before the first subsection to explain the individual components of a micropayment channel, i.e. what is the perpose of the various subsections and what are we going to do in the "micropayment channel" section?

=================================

Signatures are used to authorize transactions,
and they're a general tool that's available to
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please change the style to not use contractions (i.e. `they are a general tool that is available...') as in most of the rest of the documentation?


Signatures are used to authorize transactions,
and they're a general tool that's available to
smart contracts. In this chapter we'll use it to
Copy link
Contributor

Choose a reason for hiding this comment

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

prove (...) that a certain account approved a certain message - isn't that the most general form of the purpose of a signature (and still, the sentence starts with "in this chapter...")?

smart contracts. In this chapter we'll use it to
prove to a smart contract that a certain account
approved a certain message. We'll build a simple
smart contract that lets me transmit ether, but
Copy link
Contributor

Choose a reason for hiding this comment

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

Using we and I at the same time might be confusing. Perhaps it would be better to introduce people like Alice and Bob?

prove to a smart contract that a certain account
approved a certain message. We'll build a simple
smart contract that lets me transmit ether, but
in a unsual way, instead of calling a function myself
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: unsual

but some of them are incompatible. We'll use the new standard
way to do that `EIP-762 <https://github.com/ethereum/EIPs/pull/712>`_,
it provides a number of other security benefits.
Is recommended to stick with the most standard format of signing,
Copy link
Contributor

Choose a reason for hiding this comment

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

This sentence is a little weird

web3.personal.sign(hash, web3.eth.defaultAccount, function () {...});


Remind that the prefix includes the length of the message.
Copy link
Contributor

Choose a reason for hiding this comment

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

Which prefix? Also: "Note that..."?


1. The recipient's address
2. The amount to be transferred
3. An additional data to protects agains replay attacks
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: to protects - agains

2. The amount to be transferred
3. An additional data to protects agains replay attacks

To avoid replay attacks we'll use the same as in Ethereum transactions
Copy link
Contributor

Choose a reason for hiding this comment

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

Did this documentation already explain what a replay attack is at some point?

3. An additional data to protects agains replay attacks

To avoid replay attacks we'll use the same as in Ethereum transactions
themselves, a nonce. And our smart contract will check if that nonce is reused.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should explain the term "nonce".


::

pragma solidity ^0.4.20;
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, it would be great if we make it for latest compiler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updating the code right now!

@jvmaia
Copy link
Contributor Author

jvmaia commented Jun 19, 2018

Any update?

@vs77bb
Copy link

vs77bb commented Jun 25, 2018

Hi @chriseth mind providing an update here? Hope you're doing well 🙂

bytes32 s;
uint8 v;

assembly {
Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't mind an explanation here this code is from https://gist.github.com/axic/5b33912c6f61ae6fd96d6c4a47afde6d, but in a real implementation a more tested library should be used, such as openzepplin's fork of this code: https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/ECRecovery.sol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I will put the explanation and original/fork links.

Copy link
Contributor Author

@jvmaia jvmaia Jun 25, 2018

Choose a reason for hiding this comment

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

I don't know if I can use the library inside this docs section, then I put a note below the contract.

@chriseth
Copy link
Contributor

Not sure what went wrong here. Tests are fine locally, so I will force-merge.

@chriseth chriseth merged commit 4547b32 into ethereum:develop Jul 10, 2018
@axic
Copy link
Member

axic commented Jul 11, 2018

This should have been squashed piror to merging 😉

``claimPayment`` function.


The full contract
Copy link
Member

Choose a reason for hiding this comment

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

"complete contract"

function isValidSignature(contractAddress, amount, signature, expectedSigner) {
var message = prefixed(constructPaymentMessage(contractAddress, amount));
var signer = recoverSigner(message, signature);
return signer.toLowerCase() ==
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be === as part of latest JS standards, but in this case it sohuldn't matter too much.

@axic axic mentioned this pull request Jul 24, 2018
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.

Payment channel tutorial
6 participants