From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0EBE2C0032 for ; Tue, 24 Oct 2023 03:46:11 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id EC3BD6F5BE for ; Tue, 24 Oct 2023 03:46:10 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org EC3BD6F5BE Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=rustcorp.com.au header.i=@rustcorp.com.au header.a=rsa-sha256 header.s=202305 header.b=i1VgH7DS X-Virus-Scanned: amavisd-new at osuosl.org X-Spam-Flag: NO X-Spam-Score: -1.753 X-Spam-Level: X-Spam-Status: No, score=-1.753 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001] autolearn=no autolearn_force=no Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id o8IZWP8UarXC for ; Tue, 24 Oct 2023 03:46:06 +0000 (UTC) X-Greylist: delayed 91960 seconds by postgrey-1.37 at util1.osuosl.org; Tue, 24 Oct 2023 03:46:05 UTC DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org D7D526F5B9 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by smtp3.osuosl.org (Postfix) with ESMTPS id D7D526F5B9 for ; Tue, 24 Oct 2023 03:46:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rustcorp.com.au; s=202305; t=1698119158; bh=ITMMx44TcLykG5QDC0FP/qD4Go+lyEdmoL0Bgbgxp2g=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=i1VgH7DSjGmUc22BD8vbWzPj3mxzOw27rfIfjZIcSWQficl2evIDXTSTRF5tCny3+ PRodJLbtUeybfqUFcFpeNNqt/rfAaLQGb3S2sj1udoOGBpPYH6tvbjTRO0TAYqpGqG U/Sq2PQMf/CVKPgvqEDry1GAHIjl9b+xGq7Dl+WOqaQDcsSP6cUnCPiOOJ4V6SNEXk V3C58BtpvHKsmg+wiljTir8CmdCP2KIwbve1yQdRPpQMYFPRrK9whYZkGmT0Iz7CGh nTmJ1Bx8A/QDRiwVE29E/HYuvwd4ipV6gDHISueEdzEiRWlLQnbSEb1NjdFlDtRHWE ToDW/EyZcKF0A== Received: by gandalf.ozlabs.org (Postfix, from userid 1011) id 4SDydf5wGQz4wdD; Tue, 24 Oct 2023 14:45:58 +1100 (AEDT) From: Rusty Russell To: Andrew Poelstra In-Reply-To: References: <871qdmulvt.fsf@rustcorp.com.au> <871qdku9pj.fsf@rustcorp.com.au> Date: Tue, 24 Oct 2023 14:15:49 +1030 Message-ID: <87r0lksmxe.fsf@rustcorp.com.au> MIME-Version: 1.0 Content-Type: text/plain Cc: Bitcoin Protocol Discussion Subject: Re: [bitcoin-dev] Proposed BIP for OP_CAT X-BeenThere: bitcoin-dev@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Bitcoin Protocol Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Oct 2023 03:46:11 -0000 Andrew Poelstra writes: > I had a similar thought. But my feeling is that replacing the stack > interpreter data structure is still too invasive to justify the benefit. > > Also, one of my favorite things about this BIP is the tiny diff. To be fair, this diff is even smaller than the OP_CAT diff :) Though I had to strongly resist refactoring, that interpreter code needs a good shake! Using a class for the stack is worth doing anyway (macros, really??). diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index dcaf28c2472..2ee2034115f 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -403,6 +403,19 @@ static bool EvalChecksig(const valtype& sig, const valtype& pubkey, CScript::con assert(false); } +// First 520 bytes is free, after than you consume an extra slot! +static size_t effective_size(const std::vector >& stack) +{ + size_t esize = stack.size(); + + for (const auto& v : stack) + { + if (v.size() > MAX_SCRIPT_ELEMENT_SIZE) + esize += (v.size() - 1) / MAX_SCRIPT_ELEMENT_SIZE; + } + return esize; +} + bool EvalScript(std::vector >& stack, const CScript& script, unsigned int flags, const BaseSignatureChecker& checker, SigVersion sigversion, ScriptExecutionData& execdata, ScriptError* serror) { static const CScriptNum bnZero(0); @@ -1239,7 +1252,7 @@ bool EvalScript(std::vector >& stack, const CScript& } // Size limits - if (stack.size() + altstack.size() > MAX_STACK_SIZE) + if (effective_size(stack) + effective_size(altstack) > MAX_STACK_SIZE) return set_error(serror, SCRIPT_ERR_STACK_SIZE); } }