Deconstructing Smart Contracts: Why Take Care?

Web3 Antivirus
6 min readNov 1, 2022

--

The third episode of our web3 security sessions gives the gist of smart contracts. Why are they the power engine behind the innovation-driven blockchain environment? Are there reasons to be alert?

Smart contracts, simply explained

Exactly why is Web3 Antivirus focused on checking smart contracts? No top secret — it’s because smart contracts are the busy bees doing the heavy lifting all across blockchain infrastructures. The healthier they are, the more secure our web3 well-being is.

Metaphors aside, smart contracts are programs running on blockchain, enabling efficient data communication and guaranteeing some predefined conditions are met. It’s like we take a traditional contract and augment it with blockchain. From now on, the obligations and rights get distributed between counterparties.

The counterparties settle on what portion of contractual tasks to automate, thus making the agreement either partially or completely self-executed. While reducing human oversight, smart contracts enable provable outcomes by instantly informing sides on contract changes.

All the terms are thought-out prior to engineering so as to be built directly into the contract code.

Essentially, smart contracts are a natural component of dApps, which basically are the majority of blockchain solutions, from games to crypto exchanges. DApps can host as many as hundreds of thousands contracts, all handling complex sets of transactions to ensure smooth functioning.

As opposed to many hype gizmos labeled as “intelligent”, smart contracts have always been fit-for-purpose, not just a buzz to toy with. Forecasts project a fair growth of their market share from $315.1M in 2021 to $1460.3M by 2028, so no doubt the technology is here to stay.

Anatomy of contracts’ procedure

What if we told you that smart contracts still aren’t exactly smart on their own? Scratch their surface — and discover a good old vending machine principle. First, a tech head devises its internal mechanisms, then another living person inserts a dime — and click, some magic happens. Done and done.

Unlike humans, smart contracts cannot make decisions all by themselves. It’s either a real-life engineer or a data feed who dictates. Developers think of them as sort of a cyber if-then statement. Say, the price of a chosen financial asset goes down to a specified level, which enables a DeFi lending protocol to forfeit a pledged collateral.

A critical note. Once a smart contract gets deployed, it can’t be unnoticeably changed. Meaning, overthinking its operating principles, logic, non-conflicted terms, and possible data glitches would do no harm. Instead, it will be a prudent precaution.

Basically, taking care of the contract’s being fit-for-purpose and containing consistent architecture under the hood is the first step of development. The second one centers around its deployment. This involves bytecode compilation, blockchain upload, deployment transaction, and code execution to establish the initial state.

As soon as the majority of nodes approve the block, your smart contract is up and running. Good to go! So, how do you use a smart contract in case you’re looking to, say, purchase a token on OpenSea? From a technical perspective, the workflow will go like this:

  1. Building an unprocessed transaction

First, smart contract function calls transform into unprocessed transactions.

2. Transaction signing

To prove being the account owner, you sign a transaction using a private key.

3. Location-based transaction check

The signed transaction goes to your local Ethereum/MetaMask node to approve being signed by your account address.

4. Transaction transmission to the network

In time with transmission, your local node or MetaMask displays the transaction ID for you to track its status.

5. Transaction processing by a miner node

Miner Node finds a valid block, adds your transaction to other ones, and transmits the block to the network.

6. The new block syncing by a local node

Your local node receives the new block and syncs it with a local blockchain copy while executing all the transactions within the block.

Types of smart contracts: Are there many?

First off, we should tell public and private contracts apart. While the public ones openly welcome new contributors, access to private ones is restricted and requires permission. Meaning, some institutions, mostly financial, educational, and healthcare, prefer customizing smart contracts to their clients’ needs or specific use cases.

Such proprietary contracts enable the removal of barriers for cross-department data exchange and allow accessing common pools of records considered trustworthy. Also, the private contract participants can freely share docs with outbound entities or users.

Further, let’s jump to more detailed distinctions.

Application logic contracts

To ensure unrivaled process automation, system safety, and scalability, all under reduced transaction fees, clients opt for application logic contracts (ALCs). Say, an IoT company needs an extra layer of security. The ALCs host an application-based code that syncs with other contracts, thus making cross-device communication unhindered and hack-averse.

Smart legal contracts

Have to keep a watchful eye on legislation compliance? Here you go. Legally enforceable, these are the contracts implying that a part or a whole set of obligations are to be satisfied in the name of law. Otherwise, the party that fails to fulfill the agreement risks ending up with a lawsuit.

Decentralized autonomous organizations

The open-source decentralized autonomous organizations don’t have central authorities, for they are run communally. Therefore, smart contracts are treated as the very backbone of the entity. To make the community transparent by default, smart contracts encode the foundational rules.

The complexity totally depends on how many stakeholders are to settle their differences. Anyway, the point is to ensure everyone holds on to the agreed-upon decisions. See a misunderstanding creeping in? A value proposition occasioned, needs voting? At any moment, both the rules and the self-enforcing code can be subject to a public audit.

Getting into domain specifics, one can also talk about digital identity smart contracts, alongside government, supply chain management, loan and mortgage ones, and beyond. Yet, by now let’s wrap the differentiation at the major types we’ve just unveiled.

So where are the risks coming from?

Reasonable question. Really, we’ve just got to the bottom of how well-equipped smart contracts are technically. We know there are towers of industry-specific applications — from real estate to gaming, NFT, and metaverse. The promise for business is monumental — far beyond operational efficiency, secure communication, and lower digital service costs.

So why even care about addressing smart contracts with Web3 Antivirus? Why fix what’s seemingly not broken? And we’re back to square one. First, as we’ve noted in our previous article, where there is money, there always are brigades of ill-minded hackers scheming and plotting non-stop. Fakes and frauds get increasingly ingenious over time.

Second, it’s all about the nature of smart contracts. They do their job like clockwork, we’ll give them that. Still, they cannot recognize dangerous transactions by themselves — they just mechanically follow the pre-programmed routines. Meaning, calibrating fraud is still on you.

By you, we mean anyone including established blockchain networks losing up to mind-blowing $615 million in cyberheists. Shatters in two pieces, right?

Exactly because we can’t move past the potential risks, we’re digging into web3 security. To give you the upper hand in seeing every hiccup behind web3 transactions, we’ll provide a firmer grasp of these known unknowns in the next episode of our series.

Never let your guard down, stay safe, and have a time of your life on Web3!

--

--