Mark Friedenbach [ARCHIVE] on Nostr: đź“… Original date posted:2018-01-09 đź“ť Original message:The use of the alt stack ...
đź“… Original date posted:2018-01-09
đź“ť Original message:The use of the alt stack is a hack for segwit script version 0 which has the clean stack rule. Anticipated future improvements here are to switch to a witness script version, and a new segwit output version which supports native MAST to save an additional 40 or so witness bytes. Either approach would allow getting rid of the alt stack hack. They are not part of the proposal now because it is better to do things incrementally, and because we anticipate usage of MAST to better inform these less generic changes.
Your suggestion of “single blob on the stack” seems to be exactly this proposal afaict? Note the witness data needs to be passed separately because signatures can’t be included in that single blob if that blob is hashed and compared against something in the scriptPubKey.
The sigop and opcode limit drop can be justified with some back of the envelope calculations. Non-scriptPubKey scripts are fundamentally limited by blocksize/weight and the most damage you can do, as an adversary, is limited by space. The most expensive thing you can do check a signature. Our assumptions about block size safety are basically due to how much computation you can stuff in a block with checksigs — all the analysis there applies.
My suggestion is to limit the number of checksigs allowed in a script to size(script+witness)/64, but I wanted this to come up in review rather than complicate the code right off the bat.
I will make a strong assertion: static analyzing the number of opcodes and sigops gets us absolutely nothing. It is cargo cult safety engineering. No need to perpetuate it when it is now in the way.
Sent from my iPhone
> On Jan 9, 2018, at 8:22 PM, Rusty Russell <rusty at rustcorp.com.au> wrote:
>
> I've just re-read BIP 117, and I'm concerned about its flexibility. It
> seems to be doing too much.
>
> The use of altstack is awkward, and makes me query this entire approach.
> I understand that CLEANSTACK painted us into a corner here :(
>
> The simplest implementation of tail recursion would be a single blob: if
> a single element is left on the altstack, pop and execute it. That
> seems trivial to specify. The treatment of concatenation seems like
> trying to run before we can walk.
>
> Note that if we restrict this for a specific tx version, we can gain
> experience first and get fancier later.
>
> BIP 117 also drops SIGOP and opcode limits. This requires more
> justification, in particular, measurements and bounds on execution
> times. If this analysis has been done, I'm not aware of it.
>
> We could restore statically analyzability by rules like so:
> 1. Only applied for tx version 3 segwit txs.
> 2. For version 3, top element of stack is counted for limits (perhaps
> with discount).
> 3. The blob popped off for tail recursion must be identical to that top
> element of the stack (ie. the one counted above).
>
> Again, future tx versions could drop such restrictions.
>
> Cheers,
> Rusty.
Published at
2023-06-07 18:09:38Event JSON
{
"id": "101080448acc130691815775f3943828467a72eae424dd479c2e2bbe26190d69",
"pubkey": "1c61d995949cbfaf14f767784e166bde865c7b8783d7aa3bf0a1d014b70c0069",
"created_at": 1686161378,
"kind": 1,
"tags": [
[
"e",
"da21dfc12dad201077b712a466fd7c6d92ad2242c5c649a8737f1423ddae6784",
"",
"root"
],
[
"e",
"9f3178365705d403246429a153039bc643490d86f9aad98a3a4c13a861f3bdf3",
"",
"reply"
],
[
"p",
"13bd8c1c5e3b3508a07c92598647160b11ab0deef4c452098e223e443c1ca425"
]
],
"content": "📅 Original date posted:2018-01-09\n📝 Original message:The use of the alt stack is a hack for segwit script version 0 which has the clean stack rule. Anticipated future improvements here are to switch to a witness script version, and a new segwit output version which supports native MAST to save an additional 40 or so witness bytes. Either approach would allow getting rid of the alt stack hack. They are not part of the proposal now because it is better to do things incrementally, and because we anticipate usage of MAST to better inform these less generic changes.\n\nYour suggestion of “single blob on the stack” seems to be exactly this proposal afaict? Note the witness data needs to be passed separately because signatures can’t be included in that single blob if that blob is hashed and compared against something in the scriptPubKey.\n\nThe sigop and opcode limit drop can be justified with some back of the envelope calculations. Non-scriptPubKey scripts are fundamentally limited by blocksize/weight and the most damage you can do, as an adversary, is limited by space. The most expensive thing you can do check a signature. Our assumptions about block size safety are basically due to how much computation you can stuff in a block with checksigs — all the analysis there applies.\n\nMy suggestion is to limit the number of checksigs allowed in a script to size(script+witness)/64, but I wanted this to come up in review rather than complicate the code right off the bat.\n\nI will make a strong assertion: static analyzing the number of opcodes and sigops gets us absolutely nothing. It is cargo cult safety engineering. No need to perpetuate it when it is now in the way.\n\nSent from my iPhone\n\n\u003e On Jan 9, 2018, at 8:22 PM, Rusty Russell \u003crusty at rustcorp.com.au\u003e wrote:\n\u003e \n\u003e I've just re-read BIP 117, and I'm concerned about its flexibility. It\n\u003e seems to be doing too much.\n\u003e \n\u003e The use of altstack is awkward, and makes me query this entire approach.\n\u003e I understand that CLEANSTACK painted us into a corner here :(\n\u003e \n\u003e The simplest implementation of tail recursion would be a single blob: if\n\u003e a single element is left on the altstack, pop and execute it. That\n\u003e seems trivial to specify. The treatment of concatenation seems like\n\u003e trying to run before we can walk.\n\u003e \n\u003e Note that if we restrict this for a specific tx version, we can gain\n\u003e experience first and get fancier later.\n\u003e \n\u003e BIP 117 also drops SIGOP and opcode limits. This requires more\n\u003e justification, in particular, measurements and bounds on execution\n\u003e times. If this analysis has been done, I'm not aware of it.\n\u003e \n\u003e We could restore statically analyzability by rules like so:\n\u003e 1. Only applied for tx version 3 segwit txs.\n\u003e 2. For version 3, top element of stack is counted for limits (perhaps\n\u003e with discount).\n\u003e 3. The blob popped off for tail recursion must be identical to that top\n\u003e element of the stack (ie. the one counted above).\n\u003e \n\u003e Again, future tx versions could drop such restrictions.\n\u003e \n\u003e Cheers,\n\u003e Rusty.",
"sig": "accd592ad5825572fe8bd64a069b25ec000b92cdf244a0764b44b4252b0cf15756f3fd1f72880e76b34310f5319096961ea80705ba96d74b33f0c2ceb8e0b20a"
}