
AdLunam
Loading...
Forums
Talk about anything you want!
Forums › BTC, ETH & Macro Markets › Ethereum › Snake upgrades: more funny things
In the past two weeks, our main goal has been that all customers have updated POC5 compatibility, and this has certainly been a long road. Among the changes to the virtual machine, in particular:
However, the most important changes were with architecture surrounding the protocol. On the graphical interface side, C ++ and Go customers are quickly evolving, and we will see more updates on this side coming very soon. If you have closely followed Ethereum, you have probably seen Denny LottoA complete implementation of a lottery, plus a graphical interface, written and executed inside the C ++ customer. From now on, the C ++ customer will evolve towards a more developer-oriented tool, while the GO customer will start to focus on a user-oriented application (or rather, meta-application). On the compiler side, Snake has undergone a number of substantial improvements.
First, the code. You can take a look in the snake compiler under the hood and you can see All functionsAvailable, as well as their precise translations in EVM code. For example, we have:
72: (‘Access’, 2, 1, 73: (”, ”, 32, ‘Mul’, ‘Add’, ‘MLOAD’),),),),),),)
This means that what access (x, y) really does under the hood is that it compiles recursively what x and y are really, then load the memory in the index x + y * 32; Therefore, X is the pointer towards the start of the table and is the index. This code structure exists from POC4, but now I have upgraded the meta-language used to describe the translations even more, in order to include even if, while and INIT / CODE in this construction (before being special cases); Now, alone and only SEQ remain like special cases, and if I wanted, I could even delete SEQ by reimpling it as rewrite the rule.
Until now, the most important changes have been for POC5 compatibility. For example, if you run SNAPE Compile_to_Se TROUS ‘RETURN (msg.data (0) * 2)’, you will see:
(“BegInCode0.endCode0“”,,“”DUP“”,,“”MSIZE“”,,“”SWAP“”,,“”MSIZE“”,,“”Begincode_0.endcode_0 “,” Dup “,” Msize “,” Swap “,” Msize “,”BegIncode0.endcode0“”,,“”DUP“”,,“”MsIZe“”,,“”SWAP“”,,“”MsIZe“”,,“”Begincode_0 “,” Calldatacopy “,” Return “,” ~ Begincode_0 “,” #Code_Begin “, 2, 0,” Calldataload “,” Mul “,” Msize “,” Swap “,” Msize “,” Mstore “, 32,” Swap “)
The real code is right:
(2, 0, “Calldatalad”, “Mul”, “Msize”, “Swap”, “Msize”, “Mstore”, 32, “Swap”, “Back”)
If you want to see what’s going on here, suppose that a message arrives with its first data 5. We have like this:
2 -> Battery: (2) 0 -> battery: (2, 0) Calldataload -> battery: (2.5) Mul -> battery: (10) Msize -> battery: (10, 0) Swap -> battery: (0, 10) Msize -> battery: (0, 10, 0) MSTORE -> Battery: (0), Memory: (0, 0) -> stack: (32, 0), memory: (0, 0, 0 … 10) return
The last return returns the 32 bytes of memory from 0, or (0, 0, 0 … 10), or number 10.
Now let’s analyze the Wrapper code.
(“BegInCode0.endCode0“”,,“”DUP“”,,“”MSIZE“”,,“”SWAP“”,,“”MSIZE“”,,“”Begincode_0.endcode_0 “,” Dup “,” Msize “,” Swap “,” Msize “,”BegIncode0.endcode0“”,,“”DUP“”,,“”MsIZe“”,,“”SWAP“”,,“”MsIZe“”,,“”Begincode_0 “,” Calldatacopy “,” Return “,” ~ Begincode_0 “,” #code_begin “, …..,” #Code_end “,” ~ Endcode_0 “)
I eliminated the internal code explained above to make things clearer. The first thing we see is two labels, Begincode_0 andEndcode_0 and the guards #Code_Begin and #Code_End. The labels mark the start and end of the internal code, and the guards are there for the subsequent stages of the compiler, which understands that everything between the guards must be compiled as if it were a separate program. Now let’s look at the first parts of the code. In this case, we have ~ begincode_0 in position 10 and ~ endcode_0 in position 24 in the final code. BegInCode0AndBegincode_0 and BegIncode0AdEndcode_0 is used to refer to these positions, and $ begincode_0.endcode_0 refers to the length of the interval between them, 14. Now, do not forget that when the contract is initialized, call data are the code in which you feed. So we have:
14 -> Battery: (14) DUP -> Battery: (14, 14) Msize -> Stack: (14, 14, 0) Swap -> Stack: (14, 0, 14) Msize -> Stack: (14, 0, 14, 0) 10 -> Stack: (14, 0, 14, 0, 0) Calldatacopy -> Stack: (14, 0) MEMORY: (…)
Note how the first half of the code intelligently configures the battery so that it pushes the interior code in the memory indices 0… 13, then immediately returns this piece of memory. In the final compiled code, 600E515B525B600A37F26002600035025B54602052F2, the interior code is well to the right of the initializing code which simply returns it. In more complex contracts, initializers can also serve functions such as the definition of certain storage locations on values, or even the call or the creation of other contracts.
Now let’s introduce the most recent and most funny functionality of snake: Imports. A case of current use in contractual land is that you wish to give a contract the possibility of rejecting new contracts. The problem is, how to put the code for contracts generated in television contracts? Before, the only solution was the uncomfortable approach to compile new contracts first, then put the compiled code in a table. Now we have a better solution: import.
Put the following in ReturnNen.Se:
x = Create (tx.Gas – 100, 0, import (Mul2.se)) Return (msg (x, 0, tx.gas -100, (5), 1))
Now put what follows in Mul2.se:
Return (msg.data (0) * 2)
Now, if you compile Returnern Serpent.se and execute the contractYou notice that, the turn is played, it returns ten years. The reason is obvious. The return contract returned to an instance of the Mul2.se contract, then calls it with the value 5. Mul2.S, as its name suggests, is a doubler, and it therefore returns 5 * 2 = 10. Note that import is not a function in the standard sense; X = import (‘123.se’) will fail and the importation only works in the very specific context of creation.
Now suppose that you create a 1000 line monster contract and want to divide it into files. To do this, we use the insert. Enoute.se, Put:
If msg.data (0) == 1: inet (inner.se)
And in inner.se, put:
Back (3)
The execution of a snake compile exter.Se gives you a nice piece of compiled code which returns 3 if the argument msg.data (0) is equal to one. And that’s all there is.
Snake updates include:
In the short term, however, my own efforts will focus on bugfixes, a series of crossed tests and continuous work on Ethereumjs-Lib.
post url: https://altcoin.observer/snake-upgrades-more-funny-things/
1
Voice
0
Replies