Module4 Miss
Module4 Miss
Smart Contracts
Smart Contracts
2. Enforceable : This means that all contract conditions are enforce automatically.
3. Secure: This means that smart contracts are tamper-proof (or tamper resistant)
and run with security guarantees. The underlying blockchain usually provides these
security guarantees; however, the smart contract programing language and the smart
contract code themselves must be correct, valid, and verifi ed.
• The idea is to build standard templates that provide a framework to support legal
agreements for fi nancial instruments.
Christopher D. Clack et al. proposed this idea in their paper published in 2016,
named Smart Contract Templates: Foundations, design landscape and research
directions.
The paper is available at
https://arxiv.org/pdf/1608.00771.pdf.
https://arxiv.org/pdf/1612.04496.pdf .
Research works related
• These languages possess a small set of features that are sufficient and optimized
for a specific domain only.
• Unlike GPLs, they are not suitable for building large general-purpose application
programs.
Domain-specific languages (DSLs)
Eg: Solidity is one such language that has been introduced with the
Ethereum blockchain to write smart contracts.
Eg: Vyper is another language that has been recently introduced for
Ethereum smart contract development.
Domain-specific languages (DSLs)
• Once the fl ow is drawn and completed, it can be emulated fi rst to test it and
then be deployed from the same system to the target platform, which can be a
smart contract on a blockchain or even a complete decentralized application
(DApp).
• This concept is also not new, and a similar approach is already used in a non-
blockchain domain, in the Tibco StreamBase product, which is a Java-based
system used for building event-driven, high-frequency trading systems.
Domain-specific languages (DSLs)
• A java expert can use their skills to write Java code instead of learning a
new language.
• The limitation with smart co ntracts is that they cannot access external data because
blockchains are closed systems witho ut any direct access to the real world.
• This external data might be req uired to control the execution of some b usiness log ic
in the smart co ntract; for example, the stock price of a security p rod uct that is
required by the contract to release divid end p ayments.
• In such situatio ns, o racles can be used to provid e external d ata to smart contracts.
• An o racle can b e defi ned as an interface that delivers d ata from an external source to
smart contracts.
• Oracles are trusted entities that use a secure channel to transfer off -chain data to a
smart contract.
Oracles
2. The request is executed and the required data is requested from the
source. There are various methods of requesting data from the source.
5. The requested data with its proof of authenticity can be optionally saved on a
decentralized storage system such as Swarm or IPFS and can be used by the smart
contract/blockchain for verifi cation. This is especially useful when the proofs of
authenticity are of a large size and sending them to the requesting smart contracts
(storing them on the chain) is not feasible.
6. Finally, the data, with the proof of validity, is sent to the smart contract.
Oracles : working
• The preceding diagram shows the generic data fl ow of a data request from a
smart contract to the oracle.
• The oracle then requests the data from the data source, which is then sent
to the attestation service for notarization.
• Finally, the data is sent to the smart contract with cryptographic proof
(authenticity proof) that the data is valid.
Oracles : working
• Smart contracts can either pull data from oracles, or oracles can push data to
smart contracts.
• It is also necessary that oracles should not be able to manipulate the data they
provide and must be able to provide factual data.
• Even though oracles are trusted (due to the associated proof of authenticity of
data), it may still be possible that, in some cases, the data is incorrect due to
manipulation or a fault in the system.
1. TLSNotary
• The key idea behind using TLSNotary is to utilize the TLS handshake protocol's
feature, which allows the splitting of the TLS master key into three parts. Each part is
allocated to the server, the auditee, and the auditor. The oracle service provider
(https://provable.xyz ) becomes the auditee, whereas an Amazon Web Services
(AWS) instance, which is secure and locked down, serves as the auditor.
Mechanisms to produce cryptographic proof of data
authenticity
• TLS-N based oracles do not need to trust any third-party hardware such as
Intel SGX or TLSNotary type service
Mechanisms to produce cryptographic proof of data
authenticity
1. Android proof
• Hardware attestation validates that the device has the latest version of the OS,
which helps to prevent any exploits that existed due to vulnerabilities in the
previous versions of the OS.
Mechanisms to produce cryptographic proof of data
authenticity
2. Ledger proof
• Two hardware wallets, Ledger Nano S and Ledger Blue, can be used for
these proofs.
With oracles, we are eff ectively trusting a third party to provide us with
the
correct data.
What if these data sources turn malicious, or simply due to a fault start
provide incorrect data to the oracles?
What if the oracle itself fails or the data source stops sending data?
This issue can then damage the whole blockchain trust model.
Types of blockchain oracles
1. Inbound oracles
2. Outbound oracles
Types of blockchain oracles
Inbound oracles: This class represents oracles that receive incoming data from external
services, and feed it into the smart contract.
1. Software oracles
• These oracles are responsible for acquiring information from online services on the
Internet.
• This type of oracle is usually used to source data such as weather information, financial
data (stock prices, for example), travel information and other types of data from third-party
providers.
• The data source can also be an internal enterprise system, which may provide some
enterprise-specific data. These types of oracle can also be called standard or simple oracles.
Types of blockchain oracles
2. Hardware Oracles
• This type of oracle is used to source data from hardware sources such as IoT
devices or sensors.
• This information can be fed into the smart contract dealing with insurance
claims and payouts to decide whether to accept a claim or not.
• Based on the information received from the source hardware sensors, the
smart contract can decide whether to accept or reject the claim.
Types of blockchain oracles
• These oracles are useful in any situation where real-world data from
physical devices is required.
3. Computation oracles
• The use of oracle, in this case, provides data integrity and authenticity guarantees.
• I n t h i s s c e n a r i o , a s i n g l e v a l u e i s s o u rc e d f ro m m a n y d i ff e re n t f e e d s .
• A s a n ex a m p l e , t h i s s i n g l e v a l u e c a n b e t h e p r i c e o f a fi n a n c i a l i n s t r u m e n t , a n d i t c a n b e r i s ky t o
re l y u p o n o n l y o n e f e e d .
• To m i t i g a t e t h i s p ro b l e m , m u l t i p l e d a t a p ro v i d e r s c a n b e u s e d w h e re a l l o f t h e s e f e e d s a re
i n s p e c t e d , a n d fi n a l l y , t h e p r i c e v a l u e t h a t i s re p o r t e d b y m o s t o f t h e f e e d s c a n b e p i c ke d u p .
• T h e a s s u m p t i o n h e re i s t h a t i f t h e m a j o r i t y o f t h e s o u rc e s re p o r t s t h e s a m e p r i c e v a l u e , t h e n i t i s
l i ke l y t o b e c o rre c t .
• T h e c o l l a t i o n m e c h a n i s m d e p e n d s o n t h e u s e c a s e : s o m e t i m e s i t ' s m e re l y a n a v e r a g e o f m u l t i p l e
v a l u e s , s o m e t i m e s a m e d i a n i s t a ke n o f a l l t h e v a l u e s , a n d s o m e t i m e s i t i s t h e m a x i m u m v a l u e .
• Re g a rd l e s s o f t h e a g g re g a t i o n m e c h a n i s m , t h e e s s e n t i a l re q u i re m e n t h e re i s t o g e t t h e v a l u e t h a t
is valid and authentic, which eventually feeds into the system.
Types of blockchain oracles
• This is another way that the blockchain oracle problem can be addressed
where a single source is not trusted.
• Instead, multiple public sources are used to deduce the most appropriate
data eventually.
• In other words, it solves the problem where a single source of data may not
be trustworthy or accurate as expected.
• If there is only one source of data, it can be unreliable and risky to rely on
entirely.
• These sources can be users of the system or even members of the general
public who have access to and have knowledge of some data, for example,
a political event or a sporting event where members of the public know the
results and can provide the required data. Similarly, this data can be
sourced from multiple diff erent news websites.
• This data can then be aggregated, and if a suffi ciently high number of the
same information is received from multiple sources, then there is an
increased likelihood that the data is correct and can be trusted.
Types of blockchain oracles
6. Decentralized oracles
For example, one institution running their private blockchain can publish their data
feed via an oracle that can then be consumed by other blockchains.
Smart oracles
An idea of smart oracle has also been proposed by Ripple labs (codius). Its
https://github.com/codius/codius-wiki/wiki/White-
entities just like oracles, but with the added capability of executing contract
code. Smart oracles proposed by Codius run using Google Native Client,
• On the other hand, it can be argued that if the hardware device is running on
an external blockchain, then to get data from the source chain to the target
chain, undoubtedly, will need some security guarantees that oracle
infrastructure can provide.
• In that case, the outbound oracle would be able to provide blockchain data to
the existing legacy systems.
In a Bitcoin blockchain, the transaction timelocks, such as the nLocktime field, the
CHECKLOCKTIMEVERIFY (CLTV), and the CHECKSEQUENCEVERIFY script
operator in the Bitcoin transaction, can be seen as an enabler of a simple version of a
smart contract.
and Tezos
There are platforms that already support mainstream languages for smart
contract development, such as Lisk, which supports JavaScript.