Is JavaScript the future of smart contracts? – The new battery

As we pointed out in our article The Web3 Stack, a considerable amount of front-end development in Web3 is done with a technology very familiar to Web 2.0 developers: JavaScript. This means that the approximately 16 million JavaScript developers worldwide have many opportunities to participate in building the next phase of the web. Now, Agoric, a layer-1 stack proof blockchain, is making a big bet that JavaScript can also be used for smart contracts, which are fundamental for the decentralized trust that is at the heart of Web3 decentralized application development. Until now, smart contracts were mainly programmed using languages ​​such as Solidity or Rust.

What is a smart contract?

Smart contracts predate blockchain by decades, although they have become synonymous with blockchain and Web3 technologies. Like Dean Tribble d’Agoric said in an interview with The New Stack, “At its core, a smart contract is software that enforces the terms of an agreement, such as a legal contract between third parties.”

Some familiar examples might be something like Uber using software to connect you to an unknown driver who agrees to take you to a pre-selected destination; it’s a kind of smart contract. The transaction requires a trusted intermediary, in this case a centralized software company, which has privileged access to information such as your credit card and payment-side location, and driver availability. The software connects the two sides, giving you a ride and the driver a fee.

“Blockchains bring replicated execution,” Tribble said, “where you have machines in multiple jurisdictions and administrative domains that all vote to agree on what happens. or government cannot compromise the integrity of the execution.

This allows for things like financial transactions that cross borders in a more complicated trust than a driver and passenger located in the same city. Agoric’s goal is to allow a large part of the commercial world to work in this environment, which means that it must be programmable by more than a few thousand developers. So there’s nothing better than a language understood by 16 million developers, allowing them to use a familiar development environment.

Currently, blockchain smart contract programming is limited to the relatively small number of people who know how to program with Solidity, the smart contract language for Ethereum and its layer 2 sidechains, or other languages ​​like Rust on Solana. Agoric helps JavaScript developers quickly overcome obstacles to implementing smart contracts, the same way React made it easy to build JavaScript applications using reusable components.

Disadvantages of Using JavaScript for Smart Contracts

I asked Tribble about the potential downsides, and he started with a concise response, saying, “There are probably downsides, but that doesn’t matter. Github did an analysis and 97% of the code in [applications on Github] comes from third-party libraries.

But he followed up with a bit more detail.

“There are a lot of downsides to specific component models,” he said. “You really want a language, framework, and libraries that minimize security risks while making them easy to assemble. React is a good example of this because the model had the means and solved the right challenges to tie things together. There were a lot of UX frameworks before React, but React got it right. Our components are like React components and our framework supports using our components and composing an application with other components.

What about security?

Agoric uses hardened JavaScript in its component model to create composable smart contracts, which limits what a JavaScript runtime can do.

“Reinforced JavaScript lets you lock down your JavaScript so that it can’t do things you don’t want it to do,” Tribble explained. “The authority that goes into a program is entirely controlled by the scope that program runs in. We control the scope. You run with exactly the access and authority that we provide, so [that] we get true confined execution of arbitrary JavaScript.

Agoric has a detailed exploration of hardened JavaScript, which included this sample image:

The Solidity programming model, on the other hand, has security risks and issues with things like reentrancy. Reentrancy has been a problem with synchronous programming models for as long as there have been synchronous programs. This occurs when a program can effectively repeat the same request to another program several times before the requester receives an acknowledgment that the original request has been made. This means, for example, that you can request the same amount of ETH repeatedly and keep getting more before the program you are requesting it from has time to recognize that you have received your money. Will Shahda offers a good example of this on Medium.

According to Tribble, the risk of these reentrancy attacks was highlighted by Agoric lead engineer Brian Warner in a security review of Ethereum before it went live. He also acknowledged that it was potentially the right compromise to make at the time. Switching to an asynchronous model allows you to avoid a reentrancy problem, but since this is a fundamental feature of Ethereum’s design, it is not something that can be fixed.

Reduced user fees

One of the biggest complaints about Ethereum is the gas charges associated with proof of work. At the heart of this problem is a fundamental misalignment between people who want to increase activity on the Ethereum network and miners who want to increase fees. As Tribble puts it, “Miners are the slum lords and Ethereum is the building. The only way for the landlord to get more money is to raise the rent.

In addition to being a Layer 1 proof-of-stake network, Agoric seeks to address this economic incompatibility in order to align their blockchain network priorities with the dynamics of a functioning economy. As a result, they separated their governance token, BLD, and their fee token, RUN, with the goal of RUN being a stable token that does not fluctuate.

Tribble explains the reasoning this way: “Think of gas costs like your rent or electric bill. Ethereum is like paying your rent with Apple shares. It’s not great from a business planning perspective. It is difficult to compare whether the rent has increased or decreased from month to month. What you want instead is to pay a stablecoin for the gas, which means it has to be intrinsic to the chain and shouldn’t go into validators’ pockets – there’s no therefore no incentive to increase the rent. ”

This is where RUN comes in. “RUN which is used in execution goes into FX reserves to provide stability and execution growth for the chain,” Tribble said. “All fees for validators come from the RUN borrowing fee, not the run payment. This means that as the economy grows, as I send you more checks, as as I buy more NFTs, as I lock more tokens, the amount of RUN in circulation increases and a small fraction goes to BLD holders for staking and delegation, so their reward increases as the economy is growing.

JavaScript as the future of smart contracts

It remains to be seen whether Agoric will be successful in driving mass adoption of its composable JavaScript smart contract components, but React certainly seems like a successful blueprint for building a component-based framework. The overlay of a predictable cost control framework will also play a role in helping decentralized applications understand the cost of doing business. Agoric also provides for interoperability, making it possible to connect with Ethereum and Cosmos via the Inter-Blockchain communication protocol and the Chainlink oracle network.

What seems very logical is to allow JavaScript developers who already have deep experience, in the financial industry in particular, to leverage that knowledge as well as their experience in adhering to financial compliance guidelines and standards. of security. This particular segment of developers also tends to have a solid track record of implementing apps for hundreds of thousands of users with varying degrees of tech proficiency, so pairing their UX knowledge with an easy way to compose smart contracts could be a winning combination.

Featured image from DepositPhotos by peshkova.

Comments are closed.