Skip to content
This repository was archived by the owner on Jul 14, 2020. It is now read-only.

Add note to RFC005 highlighting the little-endian encoding of refund_timestamp#100

Merged
thomaseizinger merged 2 commits into
masterfrom
explain-timestamp-reversed
Jul 17, 2019
Merged

Add note to RFC005 highlighting the little-endian encoding of refund_timestamp#100
thomaseizinger merged 2 commits into
masterfrom
explain-timestamp-reversed

Conversation

@thomaseizinger
Copy link
Copy Markdown
Contributor

@thomaseizinger thomaseizinger commented Jul 16, 2019

The PR first converts the RFC to AsciiDoc and then uses admonitions to add the note.

Unfortunately, the conversion is too much for GitHub's git settings to detect that is actually the same file.

You can go check it locally using git diff master -M1 which lowers the similarity setting to 10%.

Fixes #93.

@thomaseizinger thomaseizinger requested review from D4nte and bonomat July 16, 2019 03:41
Copy link
Copy Markdown
Member

@bonomat bonomat left a comment

Choose a reason for hiding this comment

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

👍 Thanks, looks good.

|20
|===

CAUTION: The `refund_timestamp` is of length 4 which means we https://github.com/bitcoin/bitcoin/blob/29082e8f40c360847882553ad1b3900e5e402688/src/script/script.h#L229-L246[have to use] the `OP_PUSHDATA4` op code to keep the script minimal. Data pushed using either `OP_PUSHDATA2` or `OP_PUSHDATA4` MUST be encoded in https://en.bitcoin.it/wiki/Script#Constants[*little-endian*]. Hence, you MUST convert `refund_timestamp` to *little-endian* before constructing the HTLC from its parameters.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The link you posted states: When used as numbers, byte vectors are interpreted as little-endian, so I tried to find why pub-keys are not little-endian but couldn't find a reason. Just this: Public keys (in scripts) are given as 04 <x> <y> where x and y are 32 byte big-endian integers representing the coordinates of a point on the curve or in compressed form given as <sign> <x> where <sign> is 0x02 if y is even and 0x03 if y is odd.

which did not really help at all :S

https://en.bitcoin.it/wiki/Protocol_documentation#Signatures

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I assumed that the OP codes just know how to interpret that data.

Copy link
Copy Markdown
Contributor

@D4nte D4nte left a comment

Choose a reason for hiding this comment

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

I am confused, sometimes you use link: and sometimes not. What is the difference?

All good otherwise.

link:./RFC-003-SWAP-Basic.md[RFC003] requires ledgers have an *identity* type specified to negotiate a SWAP.

The Identity to be used on Bitcoin is the 20-byte *pubkeyhash* which is the result of applying SHA-256 and then RIPEMD-160 to a user's compressed SECP256k1 public key.
The compressed public key is used because it needs to be compatible with segwit transactions (see https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki#Restrictions_on_public_key_type)[BIP143]).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
The compressed public key is used because it needs to be compatible with segwit transactions (see https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki#Restrictions_on_public_key_type)[BIP143]).
The compressed public key is used because it needs to be compatible with segwit transactions (see link:https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki#Restrictions_on_public_key_type)[BIP143]).

```

As required by link:./RFC-003-SWAP-Basic.md[RFC003], this HTLC uses absolute time locks to check whether `refund_timestamp` has been reached.
Specifically, `OP_CHECKLOCKTIMEVERIFY` (see https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki)[BIP65]) is used to compare the time in the block's header to the `refund_timestamp` in the contract.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Specifically, `OP_CHECKLOCKTIMEVERIFY` (see https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki)[BIP65]) is used to compare the time in the block's header to the `refund_timestamp` in the contract.
Specifically, `OP_CHECKLOCKTIMEVERIFY` (see link:https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki)[BIP65]) is used to compare the time in the block's header to the `refund_timestamp` in the contract.

As required by link:./RFC-003-SWAP-Basic.md[RFC003], this HTLC uses absolute time locks to check whether `refund_timestamp` has been reached.
Specifically, `OP_CHECKLOCKTIMEVERIFY` (see https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki)[BIP65]) is used to compare the time in the block's header to the `refund_timestamp` in the contract.

Implementations MUST consider an `refund_timestamp` value below `500000000` for a Bitcoin HTLC to be invalid due to the https://en.bitcoin.it/wiki/Protocol_documentation#tx[`lock_time`] transaction field interpreting values below `500000000` as block heights.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
Implementations MUST consider an `refund_timestamp` value below `500000000` for a Bitcoin HTLC to be invalid due to the https://en.bitcoin.it/wiki/Protocol_documentation#tx[`lock_time`] transaction field interpreting values below `500000000` as block heights.
Implementations MUST consider an `refund_timestamp` value below `500000000` for a Bitcoin HTLC to be invalid due to the link:https://en.bitcoin.it/wiki/Protocol_documentation#tx[`lock_time`] transaction field interpreting values below `500000000` as block heights.

@thomaseizinger
Copy link
Copy Markdown
Contributor Author

thomaseizinger commented Jul 17, 2019

I am confused, sometimes you use link: and sometimes not. What is the difference?

link: is only necessary for non-external links like relative paths to files. ascii-doc detects https just fine.

https://asciidoctor.org/docs/asciidoc-syntax-quick-reference/#links

@thomaseizinger thomaseizinger merged commit c146aa3 into master Jul 17, 2019
@thomaseizinger thomaseizinger deleted the explain-timestamp-reversed branch July 17, 2019 06:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFC003 HTLC for Bitcoin needs expiry timestamp to be little-endian

3 participants