#Ethereum's account-based model & smart contract based on Solidity is a marriage made in hell
Vasil-HFC Event is on the horizon
& its time to unleash synergies of #Cardano's EUTxO model & Plutus
Here's a thread on why EUTxO model & functional programming is what DeFi needs🧵👇
The ultimate goal of #Blockchain
Is to replace the corrupt & centralized traditional financial system
To create an inclusive global financial system to bank the unbanked
But are we going to do it with a system that is more problematic than what we have now?
#Crypto in general & DeFi has seen massive growth in the last decade
DeFi-exploits have also seen proportional or even bigger growth
This makes us realize the fundamental requirement of the system we want to be a part of
A blockchain architecture that offers safety & security
A blockchain architecture that is designed to host mission-critical DApps
And when it comes to simple & elegant design that offers safety & security
There are two examples out there
•UTxO model of #Bitcoin
•& functional programming with #Haskell
#Cardano combines both of these worlds
• By Extending #Bitcoin's EUTxO-model
• #Cardano created the EUTxO-ledger architecture
• Powered by smart contracts based on Plutus
• Which in turn provides a safe, full-stack programming environment based on #Haskell
So why is the combination of
#Bitcoin's UTxO-ledger model & functional programming with #Haskell
A marriage made in heaven!!
When compared to something terrible like
#Ethreum's Accounts-based model & imperative programming based on Solidity
So to understand why #Cardano choose a fundamentally different architecture to #Ethereum
We should understand the synergies between
• UTxO-Model & functional programming
So let's dig a bit deeper !!
To understand the principles behind functional programming
So what is functional programming?
Functional programming is the process of building software
By composing pure functions
Which avoids 👇
• shared state
• mutable data
• & side-effects
So what are pure functions?
In the context of computation,
A pure function is analogous to a mathematical function
Which is the basis for all formal scientific reasoning
It is a function (a block of code)
that always returns the same result if the same arguments are passed
A function must follow four rules to behave like a function in math:
• It must always take an argument
• It must always return a value
• It must not depend on anything that changes
• It must not change anything by itself
A function with such properties is called "Pure"
Pure functions are "Stateless" and "timeless"
Meaning
Pure functions are easily parallelizable since they encourage immutable data structures
Which reduces the side-effects
That makes code hard to run on multiple processors
Just like #Bitcoin's UTxOs
Functions are also just mappings from inputs to outputs
It does not depend on any state or data change during a program’s execution
There are no external states & side effects
This gives certainty & predictability to the behavior of the code
Haskell has 1st-class functions
A programming language is said to have 1st-class functions
When functions are no different from any other variable
Where,
•Functions can be used as arguments
•Can be returned as values from other functions
•& can be assigned to a variable
1st-class functions allow to abstract out
Any repetitive computation from the code
And ultimately enables to write functions that produce other functions
These functions are referred to as higher-order functions
Higher-order functions simply mean
Functions that are operating on other functions
Why is it useful?
1. Higher-order functions raise the level of abstraction
Meaning
It allows to abstract over actions & not just values
Thus, we don’t have to reason about lower-level details
2. Higher-order functions are key to parameterizing code by behavior
Meaning
It allows us to define common programming patterns
And write functions about functions
Having higher-order functions is where a lot of the benefits of functional programming come from
In a nutshell,
•Functional programming uses mathematics-like values & functions
•To yield results that have no outside influence & are well-evaluated throughout
•leading to a more parallelizable transparent & cleaner code
•That helps the user in debugging & maintenance
On the other hand
Programming in a dynamic environment with object-oriented programming
Results in the creation of huge "Dependency Hell"
Resulting in adding abstraction on top of abstraction to modularize complex systems
This results in a "shared mutable state/global state"
When submodules try to access the global state simultaneously
complexity arises & it results in a chaotic programming environment
Just like the Account model of #Ethereum
Where there's Global State & transactions fail in mid-script execution
After taking fees from the user
If we could use our common sense and consider the above-mentioned reasons
A pure functional programming language like #Haskell
should ideally be the go-to programming language for dApps
which are enabling financial transactions north of billions of dollars
Haskell is similar to the UTxOs of #Bitcoin
where the pure function is a mapping from input to output
& #Ethreum's account model is similar to object-oriented programming
Accounts are similar to objects
where they send messages to each other in a dynamic & distributed setup
Although he had the knowledge of the Account-based model
When Satoshi invented #Bitcoin , he choose the UTxO-Model
Because the semantic model of the ledger stays simple
In a complex distributed and dynamic computing environment
The UTxO-model has very limited expressiveness of programmability
This limitation of #Bitcoin is what motivated Vitalik
To choose the Account-based ledger model for #Ethereum
But this resulted in the creation of a "Global state"
& this complicates the programming of dApps
#Cardano took a methodical approach
Extending #Bitcoin's UTxO model with scripts & arbitrary data
& by using #Haskell based Plutus programming language
Where the side-effect free nature of E-UTXO transactions
Maps perfectly into the pure-functional nature of Haskell functions
The arbitrary logic/scripts allow the E-UTxO model to have more expressiveness
The arbitrary data carries with it information about the state of outputs
which enables the contract state to be localized as the state is localized
There is no notion of a ''Global state''
In #Ethereum
to write a smart contract you write the on-chain code in solidity
then a Javascript code for the off-chain part that runs in the wallet
This is inconvenient
As you have to develop an ad-hoc integration between the two pieces of code
Which is Complex and Fragile
#Cardano's Plutus Platform uses Haskell for the off-chain & PlutusTX for the on-chain code
That compiles down to Plutus Core
Enabling the use of same syntax, compiler & data types in both parts of the code
Which translates into an integrated, compact & robust programming model
Meaning
Its a lot easier to reason about the behavior of a smart contract
While programming a smart contract in Plutus
It won't be too difficult to actually prove that
Code will behave exactly how it is supposed to
Enabling easily verifiable code for secure & safe dApps
We cant build the future of open global finance on platforms where multimillion-dollar hacks occur on a weekly basis
It has to be built on a platform
That has put enough work and thought
To build not only scalable but secure & safe dApps
#Cardano is melding the best of both worlds with E-UTxO-model
combining the elegant & simple architecture of #Bitcoin's UTxO-model
that maps perfectly into the pure-functional nature of Haskell functions
bringing
•safety
•security
•& scalability
To the #Blockchain world
If you found this thread valuable:
1. Toss me a follow for more threads on #blockchain technical deep dives
2. Here’s another thread on "EUTxO and Parallelism" that you may find useful :
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.