{"id":10753,"date":"2025-04-06T22:42:02","date_gmt":"2025-04-06T20:42:02","guid":{"rendered":"https:\/\/wsj-crypto.com\/?p=10753"},"modified":"2025-04-06T22:42:02","modified_gmt":"2025-04-06T20:42:02","slug":"revamping-the-serpent-exciting-new-enhancements","status":"publish","type":"post","link":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/","title":{"rendered":"Revamping the Serpent: Exciting New Enhancements!"},"content":{"rendered":"<p><\/p>\n<div id=\"\">\n<p class=\"chakra-text css-gi02ar\">Throughout the last fortnight, our main objective has been to ensure all clients are upgraded to PoC5 compatibility, and it has undeniably been a lengthy journey. Among the modifications to the VM are:<!-- --><\/p>\n<p><!-- --><\/p>\n<ul role=\"list\" class=\"css-1onhfjo\">\n<li class=\"css-cvpopp\"><b>The novel init\/code mechanism<!-- --><\/b>: essentially, upon creating a contract, the supplied code will run instantly, and the return value of that code will define the contract\u2019s actual code. This enables us to incorporate contract initialization code while maintaining the same format of [nonce, price, gas, to, value, data] for both transactions and contract establishment, also simplifying the process of generating new contracts via forwarding contracts<!-- --><\/li>\n<li class=\"css-cvpopp\"><b>Reordering transaction and contract information<!-- --><\/b>: the sequence is now [nonce, price, gas, to, value, data] for transactions and [gas, to, value, datain, datainsz, dataout, dataoutsz] for messages. It\u2019s important to note that Serpent keeps the send(to, value, gas), o = msg(to, value, gas, datain, datainsz) and o = msg(to, value, gas, datain, datainsz, dataoutsz) parameters intact.<!-- --><\/li>\n<li class=\"css-cvpopp\"><b>Fee revisions<!-- --><\/b>: creating a transaction now incurs a fee of 500 gas, and numerous other fees have been modified.<!-- --><\/li>\n<li class=\"css-cvpopp\"><b>The CODECOPY and CALLDATACOPY opcodes<!-- --><\/b>: CODECOPY takes code_index, mem_index, len as inputs, and duplicates the code from code_index &#8230; code_index+len-1 to memory mem_index &#8230; mem_index+len-1. These are particularly valuable when paired with init\/code. Additionally, CODESIZE has been introduced.<!-- --><\/li>\n<\/ul>\n<p>The most significant alterations, however, have pertained to the architecture surrounding the protocol. On the GUI front, the C++ and Go clients are progressing swiftly, and we can expect more updates from that arena soon. If you have been closely monitoring Ethereum, you may have spotted <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/www.youtube.com\/watch?v=ldJcw7JPHz0\">Denny\u2019s Lotto<!-- --><\/a>, a complete implementation of a lottery, along with a GUI, crafted and executed inside the C++ client. Moving forward, the C++ client will pivot towards being more developer-centric, whereas the Go client will begin to concentrate on being a user-facing application (or more accurately, a meta-application). On the compiler front, Serpent has experienced a variety of notable enhancements.<br \/>\n<!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">To start, the code. You can inspect the inner workings of the Serpent compiler and will notice <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/ethereum\/serpent\/blob\/master\/serpent\/compiler.py#L44\">all the functions<!-- --><\/a> available, accompanied by their accurate translations into EVM code. For instance, we have:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">72: \u00a0\u00a0\u00a0\u00a0[&#8216;access&#8217;, 2, 1,<br \/>\n73: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0[&#8221;, &#8221;, 32, &#8216;MUL&#8217;, &#8216;ADD&#8217;, &#8216;MLOAD&#8217;]],<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">This indicates that what access(x,y) truly performs under the surface is it recursively compiles whatever x and y may actually represent, then loading the memory at index x + y * 32; thus, x acts as the pointer to the beginning of the array, while y serves as the index. This code architecture has existed since PoC4, but I have now enhanced the meta-language used to articulate translations even further, to encompass even if, while, and init\/code in this formulation (previously they were special instances); now, only set and seq persist as special cases, and if desired, I could even eliminate seq by re-implementing it as a <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/ethereum\/serpent\/blob\/master\/serpent\/compiler.py#L203\">rewrite rule<!-- --><\/a>.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">The most considerable changes thus far have been related to PoC5 compatibility. For example, upon executing serpent compile_to_assembly &#8216;return(msg.data[0]*2)&#8217;, you would observe:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">[&#8220;<!-- --><span class=\"math math-inline\"><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>b<!-- --><\/mi><mi>e<!-- --><\/mi><mi>g<!-- --><\/mi><mi>i<!-- --><\/mi><mi>n<!-- --><\/mi><mi>c<!-- --><\/mi><mi>o<!-- --><\/mi><mi>d<!-- --><\/mi><msub><mi>e<!-- --><\/mi><mn>0<!-- --><\/mn><\/msub><mi mathvariant=\"normal\">.<!-- --><\/mi><mi>e<!-- --><\/mi><mi>n<!-- --><\/mi><mi>d<!-- --><\/mi><mi>c<!-- --><\/mi><mi>o<!-- --><\/mi><mi>d<!-- --><\/mi><msub><mi>e<!-- --><\/mi><mn>0<!-- --><\/mn><\/msub><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mo separator=\"true\">,<!-- --><\/mo><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mi>D<!-- --><\/mi><mi>U<!-- --><\/mi><mi>P<!-- --><\/mi><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mo separator=\"true\">,<!-- --><\/mo><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mi>M<!-- --><\/mi><mi>S<!-- --><\/mi><mi>I<!-- --><\/mi><mi>Z<!-- --><\/mi><mi>E<!-- --><\/mi><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mo separator=\"true\">,<!-- --><\/mo><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mi>S<!-- --><\/mi><mi>W<!-- --><\/mi><mi>A<!-- --><\/mi><mi>P<!-- --><\/mi><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mo separator=\"true\">,<!-- --><\/mo><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mi>M<!-- --><\/mi><mi>S<!-- --><\/mi><mi>I<!-- --><\/mi><mi>Z<!-- --><\/mi><mi>E<!-- --><\/mi><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mo separator=\"true\">,<!-- --><\/mo><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><\/mrow><annotation encoding=\"application\/x-tex\">begincode_0.endcode_0&#8243;, &#8220;DUP&#8221;, &#8220;MSIZE&#8221;, &#8220;SWAP&#8221;, &#8220;MSIZE&#8221;, &#8220;<!-- --><\/annotation><\/semantics><\/math><\/span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.8889em;vertical-align:-0.1944em\"\/><span class=\"mord mathnormal\">b<!-- --><\/span><span class=\"mord mathnormal\">e<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.03588em\">g<!-- --><\/span><span class=\"mord mathnormal\">in<!-- --><\/span><span class=\"mord mathnormal\">co<!-- --><\/span><span class=\"mord mathnormal\">d<!-- --><\/span><span class=\"mord\"><span class=\"mord mathnormal\">e<!-- --><\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3011em\"><span style=\"top:-2.55em;margin-left:0em;margin-right:0.05em\"><span class=\"pstrut\" style=\"height:2.7em\"\/><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\">0<!-- --><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<!-- --><\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.15em\"><span\/><\/span><\/span><\/span><\/span><\/span><span class=\"mord\">.<!-- --><\/span><span class=\"mord mathnormal\">e<!-- --><\/span><span class=\"mord mathnormal\">n<!-- --><\/span><span class=\"mord mathnormal\">d<!-- --><\/span><span class=\"mord mathnormal\">co<!-- --><\/span><span class=\"mord mathnormal\">d<!-- --><\/span><span class=\"mord\"><span class=\"mord mathnormal\">e<!-- --><\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3011em\"><span style=\"top:-2.55em;margin-left:0em;margin-right:0.05em\"><span class=\"pstrut\" style=\"height:2.7em\"\/><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\">0<!-- --><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<!-- --><\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.15em\"><span\/><\/span><\/span><\/span><\/span><\/span><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mpunct\">,<!-- --><\/span><span class=\"mspace\" style=\"margin-right:0.1667em\"\/><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.02778em\">D<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.10903em\">U<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.13889em\">P<!-- --><\/span><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mpunct\">,<!-- --><\/span><span class=\"mspace\" style=\"margin-right:0.1667em\"\/><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.05764em\">MS<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.07847em\">I<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.05764em\">ZE<!-- --><\/span><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mpunct\">,<!-- --><\/span><span class=\"mspace\" style=\"margin-right:0.1667em\"\/><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.05764em\">S<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.13889em\">W<!-- --><\/span><span class=\"mord mathnormal\">A<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.13889em\">P<!-- --><\/span><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mpunct\">,<!-- --><\/span><span class=\"mspace\" style=\"margin-right:0.1667em\"\/><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.05764em\">MS<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.07847em\">I<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.05764em\">ZE<!-- --><\/span><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mpunct\">,<!-- --><\/span><span class=\"mspace\" style=\"margin-right:0.1667em\"\/><span class=\"mord\">&#8220;<!-- --><\/span><\/span><\/span><\/span><\/span>begincode_0&#8243;, &#8220;CALLDATACOPY&#8221;, &#8220;RETURN&#8221;, &#8220;~begincode_0&#8221;, &#8220;#CODE_BEGIN&#8221;, 2, 0, &#8220;CALLDATALOAD&#8221;, &#8220;MUL&#8221;, &#8220;MSIZE&#8221;, &#8220;SWAP&#8221;, &#8220;MSIZE&#8221;, &#8220;MSTORE&#8221;, 32, &#8220;SWAP&#8221;, &#8220;RETURN&#8221;, &#8220;#CODE_END&#8221;, &#8220;~endcode_0&#8221;]<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">The actual script present is simply:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">[2, 0, &#8220;CALLDATALOAD&#8221;, &#8220;MUL&#8221;, &#8220;MSIZE&#8221;, &#8220;SWAP&#8221;, &#8220;MSIZE&#8221;, &#8220;MSTORE&#8221;, 32, &#8220;SWAP&#8221;, &#8220;RETURN&#8221;]<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">To understand what is occurring here, let&#8217;s assume that an incoming message has its initial value as 5. Thus, we have:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">2 -&gt; Stack: [2]<br \/>\n0 -&gt; Stack: [2, 0]<br \/>\nCALLDATALOAD -&gt; Stack: [2,5]<br \/>\nMUL -&gt; Stack: [10]<br \/>\nMSIZE -&gt; Stack: [10, 0]<br \/>\nSWAP -&gt; Stack: [0, 10]<br \/>\nMSIZE -&gt; Stack: [0, 10, 0]<br \/>\nMSTORE -&gt; Stack: [0], Memory: [0, 0, 0 &#8230; 10]<br \/>\n32 -&gt; Stack: [0, 32], Memory: [0, 0, 0 &#8230; 10]<br \/>\nSWAP -&gt; Stack: [32, 0], Memory: [0, 0, 0 &#8230; 10]<br \/>\nRETURN<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">The final RETURN outputs the 32 memory bytes starting from 0, or [0, 0, 0 &#8230; 10], which represents the number 10.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Next, let&#8217;s evaluate the surrounding code.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">[&#8220;<!-- --><span class=\"math math-inline\"><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>b<!-- --><\/mi><mi>e<!-- --><\/mi><mi>g<!-- --><\/mi><mi>i<!-- --><\/mi><mi>n<!-- --><\/mi><mi>c<!-- --><\/mi><mi>o<!-- --><\/mi><mi>d<!-- --><\/mi><msub><mi>e<!-- --><\/mi><mn>0<!-- --><\/mn><\/msub><mi mathvariant=\"normal\">.<!-- --><\/mi><mi>e<!-- --><\/mi><mi>n<!-- --><\/mi><mi>d<!-- --><\/mi><mi>c<!-- --><\/mi><mi>o<!-- --><\/mi><mi>d<!-- --><\/mi><msub><mi>e<!-- --><\/mi><mn>0<!-- --><\/mn><\/msub><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mo separator=\"true\">,<!-- --><\/mo><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mi>D<!-- --><\/mi><mi>U<!-- --><\/mi><mi>P<!-- --><\/mi><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mo separator=\"true\">,<!-- --><\/mo><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mi>M<!-- --><\/mi><mi>S<!-- --><\/mi><mi>I<!-- --><\/mi><mi>Z<!-- --><\/mi><mi>E<!-- --><\/mi><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mo separator=\"true\">,<!-- --><\/mo><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mi>S<!-- --><\/mi><mi>W<!-- --><\/mi><mi>A<!-- --><\/mi><mi>P<!-- --><\/mi><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mo separator=\"true\">,<!-- --><\/mo><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mi>M<!-- --><\/mi><mi>S<!-- --><\/mi><mi>I<!-- --><\/mi><mi>Z<!-- --><\/mi><mi>E<!-- --><\/mi><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><mo separator=\"true\">,<!-- --><\/mo><mi mathvariant=\"normal\">&#8220;<!-- --><\/mi><\/mrow><annotation encoding=\"application\/x-tex\">begincode_0.endcode_0&#8243;, &#8220;DUP&#8221;, &#8220;MSIZE&#8221;, &#8220;SWAP&#8221;, &#8220;MSIZE&#8221;, &#8220;<!-- --><\/annotation><\/semantics><\/math><\/span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.8889em;vertical-align:-0.1944em\"\/><span class=\"mord mathnormal\">b<!-- --><\/span><span class=\"mord mathnormal\">e<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.03588em\">g<!-- --><\/span><span class=\"mord mathnormal\">in<!-- --><\/span><span class=\"mord mathnormal\">co<!-- --><\/span><span class=\"mord mathnormal\">d<!-- --><\/span><span class=\"mord\"><span class=\"mord mathnormal\">e<!-- --><\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3011em\"><span style=\"top:-2.55em;margin-left:0em;margin-right:0.05em\"><span class=\"pstrut\" style=\"height:2.7em\"\/><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\">0<!-- --><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<!-- --><\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.15em\"><span\/><\/span><\/span><\/span><\/span><\/span><span class=\"mord\">.<!-- --><\/span><span class=\"mord mathnormal\">e<!-- --><\/span><span class=\"mord mathnormal\">n<!-- --><\/span><span class=\"mord mathnormal\">d<!-- --><\/span><span class=\"mord mathnormal\">co<!-- --><\/span><span class=\"mord mathnormal\">d<!-- --><\/span><span class=\"mord\"><span class=\"mord mathnormal\">e<!-- --><\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3011em\"><span style=\"top:-2.55em;margin-left:0em;margin-right:0.05em\"><span class=\"pstrut\" style=\"height:2.7em\"\/><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\">0<!-- --><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<!-- --><\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.15em\"><span\/><\/span><\/span><\/span><\/span><\/span><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mpunct\">,<!-- --><\/span><span class=\"mspace\" style=\"margin-right:0.1667em\"\/><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.02778em\">D<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.10903em\">U<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.13889em\">P<!-- --><\/span><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mpunct\">,<!-- --><\/span><span class=\"mspace\" style=\"margin-right:0.1667em\"\/><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.05764em\">MS<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.07847em\">I<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.05764em\">ZE<!-- --><\/span><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mpunct\">,<!-- --><\/span><span class=\"mspace\" style=\"margin-right:0.1667em\"\/><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.05764em\">S<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.13889em\">W<!-- --><\/span><span class=\"mord mathnormal\">A<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.13889em\">P<!-- --><\/span><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mpunct\">,<!-- --><\/span><span class=\"mspace\" style=\"margin-right:0.1667em\"\/><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.05764em\">MS<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.07847em\">I<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.05764em\">ZE<!-- --><\/span><span class=\"mord\">&#8220;<!-- --><\/span><span class=\"mpunct\">,<!-- --><\/span><span class=\"mspace\" style=\"margin-right:0.1667em\"\/><span class=\"mord\">&#8220;<!-- --><\/span><\/span><\/span><\/span><\/span>begincode_0&#8243;, &#8220;CALLDATACOPY&#8221;, &#8220;RETURN&#8221;, &#8220;~begincode_0&#8221;, &#8220;#CODE_BEGIN&#8221;, &#8230;.. , &#8220;#CODE_END&#8221;, &#8220;~endcode_0&#8221;]<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">I omitted the inner code discussed earlier for clarity. The first aspect we observe is the presence of two labels, <!-- --><del class=\"chakra-text css-0\">begincode_0 and<!-- --><\/del>endcode_0, alongside the #CODE_BEGIN and #CODE_END protections. These markers indicate the start and finish of the inner code, while the protections are implemented for subsequent phases of the compiler, which recognizes everything between them as needing to be processed like an independent program. Now, let&#8217;s examine the initial segments of the code. In this example, ~begincode_0 appears at index 10 and ~endcode_0 at index 24 in the ultimate code. <!-- --><span class=\"math math-inline\"><span class=\"katex\"><span class=\"katex-mathml\"><math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><mi>b<!-- --><\/mi><mi>e<!-- --><\/mi><mi>g<!-- --><\/mi><mi>i<!-- --><\/mi><mi>n<!-- --><\/mi><mi>c<!-- --><\/mi><mi>o<!-- --><\/mi><mi>d<!-- --><\/mi><msub><mi>e<!-- --><\/mi><mn>0<!-- --><\/mn><\/msub><mi>a<!-- --><\/mi><mi>n<!-- --><\/mi><mi>d<!-- --><\/mi><\/mrow><annotation encoding=\"application\/x-tex\">begincode_0 and <!-- --><\/annotation><\/semantics><\/math><\/span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"base\"><span class=\"strut\" style=\"height:0.8889em;vertical-align:-0.1944em\"\/><span class=\"mord mathnormal\">b<!-- --><\/span><span class=\"mord mathnormal\">e<!-- --><\/span><span class=\"mord mathnormal\" style=\"margin-right:0.03588em\">g<!-- --><\/span><span class=\"mord mathnormal\">in<!-- --><\/span><span class=\"mord mathnormal\">co<!-- --><\/span><span class=\"mord mathnormal\">d<!-- --><\/span><span class=\"mord\"><span class=\"mord mathnormal\">e<!-- --><\/span><span class=\"msupsub\"><span class=\"vlist-t vlist-t2\"><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.3011em\"><span style=\"top:-2.55em;margin-left:0em;margin-right:0.05em\"><span class=\"pstrut\" style=\"height:2.7em\"\/><span class=\"sizing reset-size6 size3 mtight\"><span class=\"mord mtight\">0<!-- --><\/span><\/span><\/span><\/span><span class=\"vlist-s\">\u200b<!-- --><\/span><\/span><span class=\"vlist-r\"><span class=\"vlist\" style=\"height:0.15em\"><span\/><\/span><\/span><\/span><\/span><\/span><span class=\"mord mathnormal\">an<!-- --><\/span><span class=\"mord mathnormal\">d<!-- --><\/span><\/span><\/span><\/span><\/span>endcode_0 are utilized to indicate these indices, and $begincode_0.endcode_0 denotes the measurement of the range between them, which is 14. Recall that during the contract setup, the call data refers to the code being submitted. Hence, we have:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">14 -&gt; Stack: [14]<br \/>\nDUP -&gt; Stack: [14, 14]<br \/>\nMSIZE -&gt; Stack: [14, 14, 0]<br \/>\nSWAP -&gt; Stack: [14, 0, 14]<br \/>\nMSIZE -&gt; Stack: [14, 0, 14, 0]<br \/>\n10 -&gt; Stack: [14, 0, 14, 0, 10]<br \/>\nCALLDATACOPY -&gt; Stack: [14, 0] Memory: [ &#8230; ]<br \/>\nRETURN<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Observe how the initial segment of the code intelligently arranged the stack to append the inner code into memory positions 0\u202613, and subsequently return that memory chunk. In the completed compiled code,600e515b525b600a37f26002600035025b525b54602052f2, the inner code is neatly placed to the right of the initializer code that merely returns it. In more intricate contracts, initializers may also fulfill roles such as assigning specific storage slots to values, or even invoking or creating additional contracts.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Now, let&#8217;s unveil the latest and most entertaining capability of Serpent: imports. A common scenario in the realm of contracts is the necessity to enable a contract to spawn new contracts. The dilemma arises on how to embed the code for the spawned contracts within the spawner contracts? Previously, the only method involved the cumbersome strategy of compiling the newer contracts first and then placing the compiled code into an array. Now, a more efficient solution exists: import.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Insert the following code into returnten.se:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">x = create(tx.gas &#8211; 100, 0, import(mul2.se))<br \/>\nreturn(msg(x,0,tx.gas-100,[5],1))<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Next, insert this code into mul2.se:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">return(msg.data[0]*2)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Now, when you compile returnten.se using serpent and <!-- --><a class=\"chakra-link css-ug8vf0\" href=\"https:\/\/blog.ethereum.org\/2014\/04\/10\/pyethereum-and-serpent-programming-guide\">execute the contract<!-- --><\/a>, you will find that, ahem, it efficiently returns ten. The rationale for this is clear. The returnten.se contract generates an instance of the mul2.se contract and invokes it using the value 5. As the name implies, mul2.se is a doubling contract, hence it returns 5*2 = 10. Keep in mind that import is not a standard function per se; x = import(&#8216;123.se&#8217;) will result in a failure, and import only operates within the very specific context of create.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Now, let&#8217;s say you are developing a colossal 1000-line contract and wish to partition it into files. To accomplish this, we utilize inset. In outer.se, insert:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">if msg.data[0] == 1:<br \/>\ninset(inner.se)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">And in inner.se, input:<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">return(3)<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">When you execute serpent compile outer.se, you receive a neat piece of compiled code that returns 3 when the msg.data[0] argument is equal to one. And that&#8217;s the entire process.<!-- --><\/p>\n<p><!-- --><\/p>\n<p class=\"chakra-text css-gi02ar\">Future enhancements to Serpent will encompass:<!-- --><\/p>\n<p><!-- --><\/p>\n<ul role=\"list\" class=\"css-1onhfjo\">\n<li class=\"css-cvpopp\">A refinement of this mechanism to prevent double-loading the inner code if you attempt to use import multiple times with the same filename<!-- --><\/li>\n<li class=\"css-cvpopp\">String constants<!-- --><\/li>\n<li class=\"css-cvpopp\">Improvements in space and code efficiency for array literals<!-- --><\/li>\n<li class=\"css-cvpopp\">A debugging decorator (i.e., a compiling function which indicates which lines of Serpent correspond to which bytes of compiled code)<!-- --><\/li>\n<\/ul>\n<p>In the immediate future, however, my efforts will concentrate on bug fixes, a cross-client testing suite, and ongoing work on <!-- --><a target=\"_blank\" rel=\"noopener\" class=\"chakra-link css-ug8vf0\" href=\"https:\/\/github.com\/ethereum\/ethereumjs-lib\">ethereumjs-lib<!-- --><\/a>.<!-- --><\/div>\n<p><br \/>\n<br \/><a href=\"https:\/\/blog.ethereum.org\/en\/2014\/05\/02\/serpent-upgrades-more-fun-stuff\">Source link <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Throughout the last fortnight, our main objective has been to ensure all clients are upgraded to PoC5 compatibility, and it has undeniably been a lengthy journey. Among the modifications to the VM are: The novel init\/code mechanism: essentially, upon creating a contract, the supplied code will run instantly, and the return value of that code<\/p>\n","protected":false},"author":3,"featured_media":8282,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[2022],"class_list":{"0":"post-10753","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-ethereum","8":"tag-return-a-list-of-comma-separated-tags-from-this-title-serpent-upgrades-more-fun-stuff"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Revamping the Serpent: Exciting New Enhancements! - WSJ-Crypto<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Revamping the Serpent: Exciting New Enhancements! - WSJ-Crypto\" \/>\n<meta property=\"og:description\" content=\"Throughout the last fortnight, our main objective has been to ensure all clients are upgraded to PoC5 compatibility, and it has undeniably been a lengthy journey. Among the modifications to the VM are: The novel init\/code mechanism: essentially, upon creating a contract, the supplied code will run instantly, and the return value of that code\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/\" \/>\n<meta property=\"og:site_name\" content=\"WSJ-Crypto\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-06T20:42:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/02\/eth-org.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"2100\" \/>\n\t<meta property=\"og:image:height\" content=\"900\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"wsjcrypto\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Scritto da\" \/>\n\t<meta name=\"twitter:data1\" content=\"wsjcrypto\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo di lettura stimato\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/\",\"url\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/\",\"name\":\"Revamping the Serpent: Exciting New Enhancements! - WSJ-Crypto\",\"isPartOf\":{\"@id\":\"https:\/\/wsj-crypto.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/02\/eth-org.jpeg\",\"datePublished\":\"2025-04-06T20:42:02+00:00\",\"author\":{\"@id\":\"https:\/\/wsj-crypto.com\/#\/schema\/person\/88a93723b30416db1a352d5a0096c4a7\"},\"breadcrumb\":{\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/#primaryimage\",\"url\":\"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/02\/eth-org.jpeg\",\"contentUrl\":\"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/02\/eth-org.jpeg\",\"width\":2100,\"height\":900},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/wsj-crypto.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Revamping the Serpent: Exciting New Enhancements!\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/wsj-crypto.com\/#website\",\"url\":\"https:\/\/wsj-crypto.com\/\",\"name\":\"WSJ-Crypto\",\"description\":\"Just Another Crypto News Website\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/wsj-crypto.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/wsj-crypto.com\/#\/schema\/person\/88a93723b30416db1a352d5a0096c4a7\",\"name\":\"wsjcrypto\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/wsj-crypto.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/86fe8af82ea089646d6639ca2f87e0243d8688d957bd8e3ec22ec3c457cc16d4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/86fe8af82ea089646d6639ca2f87e0243d8688d957bd8e3ec22ec3c457cc16d4?s=96&d=mm&r=g\",\"caption\":\"wsjcrypto\"},\"url\":\"https:\/\/wsj-crypto.com\/index.php\/author\/wsjcrypto\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Revamping the Serpent: Exciting New Enhancements! - WSJ-Crypto","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/","og_locale":"it_IT","og_type":"article","og_title":"Revamping the Serpent: Exciting New Enhancements! - WSJ-Crypto","og_description":"Throughout the last fortnight, our main objective has been to ensure all clients are upgraded to PoC5 compatibility, and it has undeniably been a lengthy journey. Among the modifications to the VM are: The novel init\/code mechanism: essentially, upon creating a contract, the supplied code will run instantly, and the return value of that code","og_url":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/","og_site_name":"WSJ-Crypto","article_published_time":"2025-04-06T20:42:02+00:00","og_image":[{"width":2100,"height":900,"url":"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/02\/eth-org.jpeg","type":"image\/jpeg"}],"author":"wsjcrypto","twitter_card":"summary_large_image","twitter_misc":{"Scritto da":"wsjcrypto","Tempo di lettura stimato":"6 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/","url":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/","name":"Revamping the Serpent: Exciting New Enhancements! - WSJ-Crypto","isPartOf":{"@id":"https:\/\/wsj-crypto.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/#primaryimage"},"image":{"@id":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/#primaryimage"},"thumbnailUrl":"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/02\/eth-org.jpeg","datePublished":"2025-04-06T20:42:02+00:00","author":{"@id":"https:\/\/wsj-crypto.com\/#\/schema\/person\/88a93723b30416db1a352d5a0096c4a7"},"breadcrumb":{"@id":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/"]}]},{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/#primaryimage","url":"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/02\/eth-org.jpeg","contentUrl":"https:\/\/wsj-crypto.com\/wp-content\/uploads\/2025\/02\/eth-org.jpeg","width":2100,"height":900},{"@type":"BreadcrumbList","@id":"https:\/\/wsj-crypto.com\/index.php\/2025\/04\/06\/revamping-the-serpent-exciting-new-enhancements\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/wsj-crypto.com\/"},{"@type":"ListItem","position":2,"name":"Revamping the Serpent: Exciting New Enhancements!"}]},{"@type":"WebSite","@id":"https:\/\/wsj-crypto.com\/#website","url":"https:\/\/wsj-crypto.com\/","name":"WSJ-Crypto","description":"Just Another Crypto News Website","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wsj-crypto.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/wsj-crypto.com\/#\/schema\/person\/88a93723b30416db1a352d5a0096c4a7","name":"wsjcrypto","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/wsj-crypto.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/86fe8af82ea089646d6639ca2f87e0243d8688d957bd8e3ec22ec3c457cc16d4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/86fe8af82ea089646d6639ca2f87e0243d8688d957bd8e3ec22ec3c457cc16d4?s=96&d=mm&r=g","caption":"wsjcrypto"},"url":"https:\/\/wsj-crypto.com\/index.php\/author\/wsjcrypto\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/posts\/10753","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/comments?post=10753"}],"version-history":[{"count":2,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/posts\/10753\/revisions"}],"predecessor-version":[{"id":10755,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/posts\/10753\/revisions\/10755"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/media\/8282"}],"wp:attachment":[{"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/media?parent=10753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/categories?post=10753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wsj-crypto.com\/index.php\/wp-json\/wp\/v2\/tags?post=10753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}