summaryrefslogtreecommitdiff
path: root/f3/a7d04edeff9bf2f52b47fbfbd35189cf283dd5
blob: baae4e6ade6a4c649c5365e5480ee32908af8d93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191]
	helo=mx.sourceforge.net)
	by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76)
	(envelope-from <tier.nolan@gmail.com>) id 1YpjcB-0006oy-DB
	for bitcoin-development@lists.sourceforge.net;
	Tue, 05 May 2015 20:38:51 +0000
Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of gmail.com
	designates 209.85.220.172 as permitted sender)
	client-ip=209.85.220.172; envelope-from=tier.nolan@gmail.com;
	helo=mail-qk0-f172.google.com; 
Received: from mail-qk0-f172.google.com ([209.85.220.172])
	by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128)
	(Exim 4.76) id 1YpjcA-0006YO-3V
	for bitcoin-development@lists.sourceforge.net;
	Tue, 05 May 2015 20:38:51 +0000
Received: by qku63 with SMTP id 63so114732051qku.3
	for <bitcoin-development@lists.sourceforge.net>;
	Tue, 05 May 2015 13:38:44 -0700 (PDT)
MIME-Version: 1.0
X-Received: by 10.140.38.167 with SMTP id t36mr3572227qgt.69.1430858324709;
	Tue, 05 May 2015 13:38:44 -0700 (PDT)
Received: by 10.140.85.241 with HTTP; Tue, 5 May 2015 13:38:44 -0700 (PDT)
In-Reply-To: <CABm2gDqcD4ENex3LzKfeGqaotoO-XxLHhLzOEPwk92SaiD8snQ@mail.gmail.com>
References: <20141001130826.GM28710@savin.petertodd.org>
	<55075795.20904@bluematt.me>
	<20150421075912.GA25282@savin.petertodd.org>
	<5546D653.4070404@bluematt.me>
	<CABm2gDqcD4ENex3LzKfeGqaotoO-XxLHhLzOEPwk92SaiD8snQ@mail.gmail.com>
Date: Tue, 5 May 2015 21:38:44 +0100
Message-ID: <CAE-z3OVrHqK1gyxCimz3ATBV3ojuyBNO-Jj6bzmcxMgfWe9jkg@mail.gmail.com>
From: Tier Nolan <tier.nolan@gmail.com>
Cc: Bitcoin Dev <bitcoin-development@lists.sourceforge.net>
Content-Type: multipart/alternative; boundary=001a11c12ce42b173b05155baaa8
X-Spam-Score: 1.8 (+)
X-Spam-Report: Spam Filtering performed by mx.sourceforge.net.
	See http://spamassassin.org/tag/ for more details.
	-1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for
	sender-domain
	0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider
	(tier.nolan[at]gmail.com)
	-0.0 SPF_PASS               SPF: sender matches SPF record
	1.2 MISSING_HEADERS        Missing To: header
	1.0 HTML_MESSAGE           BODY: HTML included in message
	-0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from
	author's domain
	0.1 DKIM_SIGNED            Message has a DKIM or DK signature,
	not necessarily valid
	-0.1 DKIM_VALID Message has at least one valid DKIM or DK signature
	1.2 MALFORMED_FREEMAIL Bad headers on message from free email service
X-Headers-End: 1YpjcA-0006YO-3V
Subject: Re: [Bitcoin-development] Relative CHECKLOCKTIMEVERIFY (was CLTV
	proposal)
X-BeenThere: bitcoin-development@lists.sourceforge.net
X-Mailman-Version: 2.1.9
Precedence: list
List-Id: <bitcoin-development.lists.sourceforge.net>
List-Unsubscribe: <https://lists.sourceforge.net/lists/listinfo/bitcoin-development>,
	<mailto:bitcoin-development-request@lists.sourceforge.net?subject=unsubscribe>
List-Archive: <http://sourceforge.net/mailarchive/forum.php?forum_name=bitcoin-development>
List-Post: <mailto:bitcoin-development@lists.sourceforge.net>
List-Help: <mailto:bitcoin-development-request@lists.sourceforge.net?subject=help>
List-Subscribe: <https://lists.sourceforge.net/lists/listinfo/bitcoin-development>,
	<mailto:bitcoin-development-request@lists.sourceforge.net?subject=subscribe>
X-List-Received-Date: Tue, 05 May 2015 20:38:51 -0000

--001a11c12ce42b173b05155baaa8
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

I think that should be greater than in the comparison?  You want it to fail
if the the height of the UTXO plus the sequence number is greater than the
spending block's height.

There should be an exception for final inputs.  Otherwise, they will count
as relative locktime of 0xFFFFFFFF.  Is this check handled elsewhere?

if (!tx.vin[i].IsFinal() && nSpendHeight < coins->nHeight +
tx.vin[i].nSequence)
       return state.Invalid(false, REJECT_INVALID,
"bad-txns-non-final-input");

Is the intention to let the script check the sequence number?

<number> OP_RELATIVELOCKTIMEVERIFY

would check if <number> is less than or equal to the sequence number.

It does make sequence mean something completely different from before.
Invalidating previously valid transactions has the potential to reduce
confidence in the currency.

A workaround would be to have a way to enable it in the sigScript by
extending Peter Todd's suggestion in the other email chain.

<1> OP_NOP2 means OP_CHECKLOCKTIMEVERIFY (absolute)
<2> OP_NOP2 means OP_RELATIVECHECKLOCKTIMEVERIFY

<3> OP_NOP2 means OP_SEQUENCE_AS_RELATIVE_HEIGHT

OP_SEQUENCE_AS_RELATIVE_HEIGHT would cause the script to fail unless it was
the first opcode in the script.  It acts as a flag to enable using the
sequence number as for relative block height.

This can be achieved using a simple pattern match.

bool CScript::IsSequenceAsRelativeHeight() const
{
    // Extra-fast test for pay-to-script-hash CScripts:
    return (this->size() >=3D 4 &&
            this->at(0) =3D=3D OP_PUSHDATA1 &&
            this->at(1) =3D=3D 1 &&
            this->at(2) =3D=3D 0xFF &&
            this->at(3) =3D=3D OP_NOP2);
}

if (!tx.vin[i].IsFinal() &&
tx.vin[i].scriptSig.IsSequenceAsRelativeHeight() && nSpendHeight <
coins->nHeight + tx.vin[i].nSequence)
       return state.Invalid(false, REJECT_INVALID,
"bad-txns-non-final-input");

On Mon, May 4, 2015 at 12:24 PM, Jorge Tim=C3=B3n <jtimon@jtimon.cc> wrote:

> for (unsigned int i =3D 0; i < tx.vin.size(); i++) {
> // ...
>             if (coins->nHeight + tx.vin[i].nSequence < nSpendHeight)
>                 return state.Invalid(false, REJECT_INVALID,
> "bad-txns-non-final-input");
> // ...
> }
>

--001a11c12ce42b173b05155baaa8
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I think that should be greater than in the comparison=
?=C2=A0 You want it to fail if the the height of the UTXO plus the sequence=
 number is greater than the spending block&#39;s height.<br><br></div><div>=
There should be an exception for final inputs.=C2=A0 Otherwise, they will c=
ount as relative locktime of 0xFFFFFFFF.=C2=A0 Is this check handled elsewh=
ere?<br><br> if (!tx.vin[i].IsFinal() &amp;&amp; nSpendHeight &lt; coins-&g=
t;nHeight + tx.vin[i].nSequence)<br>
=C2=A0 =C2=A0 =C2=A0=C2=A0 return state.Invalid(false, REJECT_INVALID, &quo=
t;bad-txns-non-final-input&quot;);<br></div><div><div><div><div class=3D"gm=
ail_extra"><br></div><div class=3D"gmail_extra">Is the intention to let the=
 script check the sequence number?<br><br></div><div class=3D"gmail_extra">=
&lt;number&gt; OP_RELATIVELOCKTIMEVERIFY<br><br></div><div class=3D"gmail_e=
xtra">would check if &lt;number&gt; is less than or equal to the sequence n=
umber.<br></div><div class=3D"gmail_extra"><br></div><div class=3D"gmail_ex=
tra">It does make sequence mean something completely different from before.=
=C2=A0 Invalidating previously valid transactions has the potential to redu=
ce confidence in the currency.<br><br></div><div class=3D"gmail_extra">A wo=
rkaround would be to have a way to enable it in the sigScript by extending =
Peter Todd&#39;s suggestion in the other email chain.<br><br></div><div cla=
ss=3D"gmail_extra">&lt;1&gt; OP_NOP2 means OP_CHECKLOCKTIMEVERIFY (absolute=
)<br></div><div class=3D"gmail_extra">&lt;2&gt; OP_NOP2 means OP_RELATIVECH=
ECKLOCKTIMEVERIFY <br></div><div class=3D"gmail_extra"><br>&lt;3&gt; OP_NOP=
2 means OP_SEQUENCE_AS_RELATIVE_HEIGHT<br></div><div class=3D"gmail_extra">=
<br>OP_SEQUENCE_AS_RELATIVE_HEIGHT would cause the script to fail unless it=
 was the first opcode in the script.=C2=A0 It acts as a flag to enable usin=
g the sequence number as for relative block height.<br><br></div><div class=
=3D"gmail_extra">This can be achieved using a simple pattern match.<br><br>=
bool CScript::IsSequenceAsRelativeHeight() const<br>{<br>=C2=A0=C2=A0=C2=A0=
 // Extra-fast test for pay-to-script-hash CScripts:<br>=C2=A0=C2=A0=C2=A0 =
return (this-&gt;size() &gt;=3D 4 &amp;&amp;<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 this-&gt;at(0) =3D=3D OP_PUSHDATA1
 &amp;&amp;<br></div><div class=3D"gmail_extra">=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 this-&gt;at(1) =3D=3D 1 &amp;&amp;<=
br></div><div class=3D"gmail_extra">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 this-&gt;at(2) =3D=3D 0xFF &amp;&amp;<br></div>=
<div class=3D"gmail_extra">=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0 this-&gt;at(3) =3D=3D OP_NOP2);<br>}<br><br></div><div c=
lass=3D"gmail_extra"></div><div class=3D"gmail_extra">if (!tx.vin[i].IsFina=
l() &amp;&amp; tx.vin[i].scriptSig.IsSequenceAsRelativeHeight() &amp;&amp; =
nSpendHeight &lt; coins-&gt;nHeight + tx.vin[i].nSequence)<br>
=C2=A0 =C2=A0 =C2=A0=C2=A0 return state.Invalid(false, REJECT_INVALID, &quo=
t;bad-txns-non-final-input&quot;);</div><div class=3D"gmail_extra"><br></di=
v><div class=3D"gmail_extra"><div class=3D"gmail_quote">On Mon, May 4, 2015=
 at 12:24 PM, Jorge Tim=C3=B3n <span dir=3D"ltr">&lt;<a href=3D"mailto:jtim=
on@jtimon.cc" target=3D"_blank">jtimon@jtimon.cc</a>&gt;</span> wrote:<br><=
blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l=
eft:1px solid rgb(204,204,204);padding-left:1ex"><span class=3D"">for (unsi=
gned int i =3D 0; i &lt; tx.vin.size(); i++) {<br>
// ...<br>
</span>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (coins-&gt;nHeight + tx=
.vin[i].nSequence &lt; nSpendHeight)<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return state.Invali=
d(false, REJECT_INVALID, &quot;bad-txns-non-final-input&quot;);<br>
// ...<br>
}<br></blockquote><div><br>=C2=A0</div></div></div></div></div></div></div>

--001a11c12ce42b173b05155baaa8--