New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

EIP-7543 Adding Decimal Float Math to the EVM | Imi Kim

Ethereum DenverWed, Oct 9, 2024, 12:00 AM

APPLICATIONS FOR ETHDenver 2024: #YearOfTheSpork ARE OPEN APPLY NOW https://ethdenver.com/apply

Transcript

[Music] all right hello everyone my name is Amy and I will be presenting EIP 7543 for decimal math now I'm going to make this basic enough for lots of people to get something from this and hopefully also interesting enough for advanced listeners an EIP is an ethereum improvement proposal so this year is an idea on how to improve in fact all evm based systems of course ethereum is the main one and we're going to be talking about how to add decimal math which is very useful and fundamental for a lot of calculations applications use cases around the world in fact I'm going to be making the case that this Improvement adding decimal math to the evm will allow a lot of people to develop much easier and more sophisticated and complex applications and that is going to invite several communities very large Industries into the evm world so that's represented by the pile of value coming into to the evm and if we get entire Industries coming in and using the evm thanks to whatever reason then that value of course gets gets reflected in a skyrocketing of all evm projects now I want to start and go to the very depth of you know what is the evm first of all the M the evm is a ethereum virtual machine so the m is a machine and machines are very useful because we can use them to do tasks for us and do them in parallel this gives a developer a lot of power and machines at their core understand numbers everything at its very core in machines is a number in fact if you go to a and look at blockchain smart contracts that you've probably seen then this here is a representation of a smart contract and it's all numbers numbers represent data that we want to manipulate and numbers also repres present algorithms change of data how the data should be manipulated to get some desired result and you see these numbers here some some people would say think kind of strange numbers because there's also letters in between you see a c d f Etc these are in fact numbers with the basis 16 hexad decimal numbers um typically we use decimal numbers basis 10 that means that there are 10 different digits 0 1 2 3 4 5 6 7 8 nine that's the digits available to represent any number in a decimal system in a hexa decimal system you have 16 digits available to represent any number that goes from 0 to 9 and then a b c d f and there's also the binary number system which uses only two letters to represent any number zeros and ones and in fact it doesn't matter which system you use the decimal the binary the hex each number is a number and can be represented in any of these systems but the representation will be different and computers at their very core are binary there's transistors in the chips we use which which essentially have a on and off that's binary one or zero that is why at the very Core computers implement everything in binary first and developers use binary numbers and binary algorithms and procedures to do more complex calculations however there is a problem for example 0.1 here you see 0.1 on the left side base 10 that is 0.1 the number that a lot of people will know and enjoy in various situations in life whether you're doing Finance 10% is a very often used number whether you're doing science in a lot of situations one out of 10 is crucial number to have interestingly in binary system if you want to represent that number you need infinite many digits that's what this bar across the 011 means it means that if you want to represent 0.1 decimal the normal 0.

1 in binary you would have to have 0.011 0011 0011 to infinity and you would need infinite many digits in binary to exactly represent 0.1 such a simple and basic number yet in binary with a finite amount of memory which is always true any computer use we only have access to finite amount of resources we can never represent 0.1 exactly and that is a problem for anyone wanting to do any kind of application that uses finance that wants to use numerical math science to compute the kinds of calculations that Myriad of applications use the solution to this or the solution proposed in this EIP is to represent a a decimal using two numbers this is very simple currently if you're coding a smart contract you're probably using solidity solidity gets compiled to bite code and typically you have access to numbers they live on the stack that's where you get access to them that's a area of memory essentially and instead of using each number on its own if we combine them in a certain way in this way then we can represent every decimal number exactly that is C * 10^ q c a coefficient so and Q the exponent if we wanted to represent 0.1 we would have C as 1 and Q as minus 1 1 * 10 ^ of minus1 gives 0.

1 and in fact any decimal value that you can think of any value that you use in any application or that you have encountered which again very likely because we are humans and we use decimal systems because we have 10 fingers makes it easier to count for us any value that you can imagine 2.45 6 you can first forget the decimal value decimal point 2 456 can be C your coefficient and then Q is a value to shift the decimal left or right to represent any decibal value exactly of course it depends on how many resources you have and a very large number number would not be representable still but in fact with this combination the numbers that do exist on the evm can be very large 256 bits means very very large numbers and both combined to represent a decimal like this gives you access uh exactly to all numbers that you would need in a decimal system so now this here is the solution and the proposal to add op codes now what are op codes we saw the contract code earlier a smart contract like this some of this is data and some of these are commands and whether something is a command you can find there's evm do codes website here you will see each number corresponds to some command if it's 0 a it's X and you can scroll through this and you'll see that we go till 7 8 9 10 then a0 A1 these are hexadecimal numbers that's why you see A's and such and you see after the A4 there's space there's nothing starting with a b c d e and then there's some f f one until FF FF means self-destruct this is these are the op codes which are the most basic commands that the evm the machine understands these are suggestions for new OP codes d0 to D6 that allow you to work with and manipulate decimal numbers as we just defined we have arithmetic adding negating multiplying and inversing right and so with inversing and multiplying together you can get division with negation and adding you can get subtraction and these work on the decimal values that is if you have a value a with its coefficient and its exponent representing a decimal a and another decimal B if you put them as inputs you're going to get a decimal c as the answer again with the two components the coefficient and the exponential and you'll notice that most of these up codes have a Precision parameter which is the Precision that you want to keep in your calculations and now additionally to the arithmetic we're adding three power more powerful math functions the exponential that's the prototypical growth the log is a prototypical slow growth and the sign function the basic trigonometric functions all these seven functions combined with each other give all the elementary functions all the numeric functions anyone ever uses in numerical code that is trigonometry rational functions pols essentially everything that is used to calculate integrals differential equations optimizations the entire numerical coding world can be sustained and built based on these seven operators and we do not need more and nor less how are these exponential log and sign by the way calculated perhaps you remember the exponential can be expanded into simpler terms a polom an infinite one but the more steps you make the more Precision you get in your answer hence we have the steps argument which a developer can choose knowing and it is deterministically known how many steps you need to have to reach a certain Precision the same goes for the sign and the log can be done in the same way or more efficiently using continued fractions this is the same thing this is just long fractions going infinitely if you take enough steps of these you will get the Precision that you want and besides that from numerical analysis we know that if you want to have a certain Target Precision for your end result and that depends on your application whether you need four digits or 20 digits then your intermediary calculations and steps should have at least that many actually more Precision available with this the current evm from being like a simple calculator goes to a scientific type of calculator and the use cases and I'm coming to the value mentioned in the very beginning are immense there is an entire trillions of dollars of mathematical Finance think hedge funds Banks they have sophisticated Financial products and all of those require numerical coding integrals have to be calculated differential equations have to be solved all of which currently is very difficult because you have to translate it into into binary machine learning of course a massive subject often referred to as AI although I should warn one day the a prefix will be considered an insult it is intelligence and intelligence run by a machine allows us to do many things and of course if we could bring machine learning into a trustless environment imagine you have code that creates images for you or does governance or anything else that machine learning can do but do do so trustly you can know you know the source code is exactly as intended because everything on chain is open source same goes for science digital art and many many more examples that anything that requires numerical coding uh there was a explosion of developers using things like python or nowadays better alternative Julia to do the simplest kind of calculations in finance if you want to go from a yearly volatility to a daily volatility you have to take the 16th route but even taking a simple route any kind of root is essentially just a power doing all of that currently requires a lot of code so we could write everything that I am suggesting in solidity we could have a solidity Library doing all the math just like I'm suggesting to put into a single op code so D6 to calculate the sign instead of a lot of bite code what is the pro and the con um so what we're doing is we're shifting complexity we're shifting it from the smart contract developer the solidity developer to the node and we are getting rid of overhead of calling a lot of op codes from a higher language like solidity to do complex mathematical calcul ations and in this case we're talking about three fundamental functions of the universe of nature exponential log and sign these are true in the whole universe needed for a l uh any kind of mathematical coding and if available correctly and efficiently as an OP code would remove also bugs from those that are looking to do mathematical development the gas the good news is it is deterministic all these algorithms are deterministic are input dependent they're complex but they can still be precisely calculated and there is a reference implementation for this EIP that does so and currently charges you double the gas which can be improved and thinking of why should one not do this we are asking the question well if you have some complex algorithm functionality should we put all of that as an OP code onto the evm that would be cluttering the evm it's not what we want to do there's only 256 spots available for op codes so we should be really selective the EV VM the v in the E is that it's it is a virtual machine normally op codes that is the low L level language of coding assembly adheres to the restrictions of hardware and Hardware is binary and can do only simple things but when you have a virtual machine then you can do complex things for example there's op Cod for hashing because that is fundamental to Smart contracts on these uh uh machines but what is but for the numerical world what is fundamental is exponential log and sign the the only con that um I can see is perhaps uh design flaw in the evm in that it doesn't contain a version tag in the beginning that means there could be old contracts that have a certain op code that didn't exist yet and it would function in a an unexpected way uh but that is then true and a problem for any new OP code to ever come so that problem is shared and besides that I see no other problems except nothing thank you

Automatic transcript — names and jargon may be misspelled.