From: Pieter Wuille <pieter.wuille@gmail.com>
To: bitcoin-development@lists.sourceforge.net
Subject: Re: [Bitcoin-development] Alternative to OP_EVAL
Date: Thu, 29 Dec 2011 20:08:39 +0100 [thread overview]
Message-ID: <20111229190838.GA29609@ulyssis.org> (raw)
In-Reply-To: <alpine.LRH.2.00.1112290111310.22327@theorem.ca>
On Thu, Dec 29, 2011 at 01:55:03AM -0500, roconnor@theorem.ca wrote:
> Gavin asked me to come up with an alternative to OP_EVAL, so here is my
> proposal.
>
> OP_CODEHASH Initial Proposal
If we're again brainstorming about alternatives for OP_EVAL, I'll do my own.
It is called OP_CHECKEDEVAL, and is specified as follows:
* It looks at the two elements most recently (in code position) pushed by a literal,
and not yet consumed by another OP_CHECKEDEVAL. These are S (the serialized script),
and H (its hash). This implies it defines its own literal-only stack, where all
literals push to, and only OP_CHECKEDEVAL pops from. This special stack has the
advantage of allowing static analysis - one does not need to execute any operations
to find out which data will end up on it. Note that "skipped" code (inside the
ignored part of an IF-THEN-ELSE) can still push to the literal stack.
* For the "outer script", it does not have any effect at all, except for:
* 2 elements popped from the literal-only stack
* potentially causing failure
It does not touch the main stack, alt stack or any other part of the execution state
not listed above.
* Failure is caused when either of these conditions hold:
* No two elements remain on the literal-only stack
* The Hash(S) != H
* The inner script execution caused failure
* For the execution of the inner script:
* It is executed in a completely new and independent execution environnement
* It executes the deserialized S
* It inherits the main stack and alt stack (without the serialized script and the hash
themselves) from the outer execution.
This requires OP_CHECKEDEVAL to immediately follow the push of script and hash,
so the code in the pair < <script> OP_CHECKEDEVAL > can be parsed and interpreted as code,
allowing static analysis.
As OP_CHECKEDEVAL has absolutely no effects except for potentially causing failure, it
is very similar to the OP_NOPx it would replace, and guarantees that interpreting
OP_CHECKEDEVAL as OP_NOPx can never cause the script to become invalid if it wasn't
already.
A basic pay-to-script-hash scriptPubKey is very short:
<scriptHash> OP_CHECKEDEVAL
And it is redeemed using:
<script inputs> <script>
Furthermore, the implementation is very similar to what was already done for
OP_EVAL. Modifications:
* EvalScriptInner needs less by-ref arguments, as it cannot modify the parent's state.
* A literal-only stack needs to be maintained.
I believe this combines all advantages:
* Easy spend-to-script-hash (shorter than OP_EVAL)
* Backward compatible (guaranteed by construction, instead of separately enforced like with OP_EVAL)
* Statically analyzable (though it requires deserializing the script data).
* Possibility to introduce a new language inside (not done in this proposal)
Only disadvantages:
* Slightly less flexible than OP_EVAL, as it disallows dynamic interation with serialized scripts.
* Static code analyzers need to deserialize script data.
Credits: gmaxwell for the idea of a literal-only stack
--
Pieter
next prev parent reply other threads:[~2011-12-29 19:08 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-29 6:55 [Bitcoin-development] Alternative to OP_EVAL roconnor
2011-12-29 8:44 ` theymos
2011-12-29 16:42 ` roconnor
2011-12-30 12:01 ` Chris Double
2011-12-30 17:19 ` roconnor
2012-01-02 15:14 ` Stefan Thomas
2012-01-02 15:59 ` Gavin Andresen
2012-01-02 16:42 ` roconnor
2012-01-02 17:10 ` Stefan Thomas
2011-12-31 9:54 ` Joel Joonatan Kaartinen
2011-12-31 17:28 ` Zell Faze
2011-12-29 16:23 ` Gavin Andresen
2011-12-29 17:01 ` roconnor
2011-12-29 17:06 ` Luke-Jr
2011-12-29 18:00 ` Gavin Andresen
2011-12-29 19:54 ` Stefan Thomas
2011-12-29 19:08 ` Pieter Wuille [this message]
2011-12-29 21:00 ` Pieter Wuille
2011-12-29 21:31 ` Alan Reiner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111229190838.GA29609@ulyssis.org \
--to=pieter.wuille@gmail.com \
--cc=bitcoin-development@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox