Layer 2 Blockchain Analysis

Ljh
Metadium
Published in
11 min readNov 9, 2022

The second article discussed blockchain types and Layer 1 solutions to the blockchain scalability problem. In this article, I would like to explore what Layer 2 solutions are and analyze the characteristics of each solution.

1. Layer 2 concept

Fig 1. Layer 2 concept

Layer 2 refers to an auxiliary framework or protocol built on top of an existing blockchain. To confirm a transaction that occurred in a specific framework/protocol, it can be defined as a Layer 2 solution by referencing the data of the existing blockchain (Layer 1) or when transaction data recording is required in Layer 1 for transaction confirmation.

The chain can solve the scalability problem by reducing the data burden given to Layer 1 because the chain records only the result value in Layer 1 after performing calculation/transaction record/transaction verification in a separate layer above the Layer 1 blockchain.

For example, in Fig 1., the user does not record their transaction (100 USDC remittance) directly in Layer 1 but performs the transaction in Layer 2, and a third aggregator communicates with other transactions. Records Layer 2 transactions in Layer 1 in compressed form (the recording method differs depending on the Layer 2 solution method).

Layer 2 solutions can be broadly classified into Channels, Sidechains, and Rollups. In this post, we will analyze each Layer 2 solution.

2. Layer 2 solution

2. 1 Channel

A channel creates a private channel between parties carrying out transactions, conducting transactions on that channel, and recording the final transaction result value in Layer 1. In addition, a set of rules needs to be predefined for transaction reliability.

Channels can be classified into two main categories: status channels and payment channels, which are generalized versions, while payment channels are limited to payment-related applications. Figure 2 is an example of a state channel.

Fig 2. Example of channel

Assume that a channel that performs round 2 is opened. At this time, Bob sends 100 USDC in Round 1 and receives 70 FTM; in Round 2 sends 40 FTM and receives 50 USDC. Finally, 50 USDC and 30 FTM become the state values for Bob, and 50 USDC and 40 FTM become the state values for Alice. Even though two transactions have occurred, the intermediate transaction process is entrusted to the private channel, and only the final transaction result value is recorded in the Layer 1 blockchain.

Since transaction reliability is fully obtained through an agreement between the channel parties, securing transaction reliability within the channel is essential. In addition, since it is necessary to establish a private trading channel between participants, it is difficult for many participants to participate.

2.1 SideChains

Sidechains transfer assets/states in Layer 1 to Sidechains and perform transactions within the sidechain. For example, assuming you have 100 ETH in the Ethereum chain, transfer 50 ETH to the Sidechain and complete the transaction within the Sidechain. When the transaction in Sidechain is closed, the remaining assets can be transferred back to Layer 1 after the transaction is closed. For this, a bridge is required to allow the mutual movement of assets. Fig 3. is an example of a Sidechain.

Fig 3. Example of SideChains

In Fig 3., Bob moves 100 USDC in Layer 1 to his sidechain account. The above deposit transaction is written in Layer 1, and Bob’s assets in Layer 1 decrease. Referring to Fig 3., the above-deposited USDC is sent to Alice in the sidechain, and 150 USDC is received from Alice afterward, so Bob has 50 USDC in the sidechain. After that, 50 USDC can be withdrawn to Layer 1.

As mentioned above, moving Layer 1 assets to Layer 2 and performing transactions is called a sidechain. A sidechain is characterized by the need for trust in the sidechain, just like the state channel. The difference is that while rules agreed upon by the parties determine the state channel’s reliability, the sidechain is determined by the consensus algorithm of each chain.

2.3 Rollup

Suppose the state channel and sidechain were a method of processing the intermediate process of a specific transaction at Layer 2 and recording the final result value at Layer 1. In that case, the rollup records all transactions occurring at Layer 2 in a compressed form at Layer 1.

For example, all transactions in Layer 2 are committed to a short value (ex. SHA256 Hash function) cryptographically, and only compressed commitments and final state values are periodically recorded in Layer 1. At this time, the reliability of transaction aggregation is required to ensure that the correct Layer 2 transaction is recorded in Layer 1, which can be classified into Optimistic Rollup and zk-Rollup depending on how the above reliability is guaranteed.

Optimistic Rollup

Optimistic Rollup is a method of trusting the results of Layer 2 transaction compression and post-validating by participants for invalid rollups. Optimistic Rollup does not require much computing cost to compress transactions. However, the disadvantage is that it requires more than a week to finalize transactions because it requires time to post verification for invalid rollups.

Fig 4. Optimistic Rollup

Optimistic Rollup verifies the compression results afterward, so the rollup node that performed the invalid compression is penalized, and the user who finds the illegal transaction gets a certain reward.

zk-Rollup

Unlike Optimistic Rollup, zk-Rollup does not post-verify the Rollup results but is a method of recording after verification. Zk-Rollup uses Zero-knowledge proof technology that can prove the validity of the information without revealing the information.

A simple example of proof of knowledge is to prove that I can pay 10,000 won, but whether I have ten 1,000 won bills or two 5,000 won bills. It should be understood as a technique for proving without revealing. Replacing the proposition “I have 10,000 won” with the request “If you compress all Layer 2 transactions, you will get the A state value” is proof of Rollup.

Zk-Rollup is performed as follows. When a transaction first occurs at Layer 2, the Rollup node responsible for Rollup performs transaction compression and generates a zero-knowledge proof value for the entire chain of compression processes. Specifically, the input is layer 2 of a specific period, and the output is a SHA256 hash value that proves a function expression using zero-knowledge proof technology.

Rollup verification does not check all transaction results like Optimistic Rollup but verifies the attached zero-knowledge proof, so immediate transaction confirmation is possible. However, it has the disadvantage of requiring a lot of computing cost since it requires proof values for the compression process.

Figure 5 is an example of a zk-rollup.

Fig 5. zk-Rollup

Referring to Fig. 5, the Rollup server in charge of Rollup compresses Layer 2 transactions and generates zero-knowledge proofs for all compression processes. A miner who records a rollup transaction in Layer 1 can check the validity of the zero-knowledge proof and record the compression result and the zero-knowledge proof value in Layer 1.

In this article, we have covered various Layer 2 solutions. Although each solution has advantages and disadvantages, research on Rollup is generally being actively conducted. Rollup technology differs from other solutions because it can compress and process multiple transactions into one transaction and ensure data availability. Among them, zk-Rollup is attracting more attention because it can ensure rapid transaction confirmation and expand the stage of transaction compression to the compression of the blockchain itself.

Research groups such as Polygon and Starkware are researching the modularization of blockchain and blockchain capacity compression through zk-Rollup. Modularization and capacity compression, as described above, are expected to be efficient ways to solve the scalability problem in Ethereum. Therefore, Metadium is considering R&D on Layer 2 blockchain applications through close cooperation with the zk-Rollup research group.

References

두번째 포스트에서 블록체인의 각 유형 및 블록체인의 확장성 문제 해결을 위한 Layer 1 솔루션에 대해 다루었다. 본 포스트에서는 Layer 2 솔루션으로 어떤 것들이 있는지 알아보고, 각 솔루션의 특징을 분석하고자 한다.

1. Layer 2 concept

Fig 1. Layer 2 concept

Layer 2는 기존 블록체인 위에 구축된 보조 프레임워크 또는 프로토콜을 의미한다. 특정 프레임워크 / 프로토콜에서 발생한 거래가 확정되기 위해 기존의 블록체인(Layer 1)의 데이터를 참고하거나, 또는 거래 확정을 위해 Layer 1에 거래 데이터 기록이 필요한 경우 이를 Layer 2 솔루션으로 정의할 수 있다.

Layer 2 블록체인은 Layer 1 블록체인 위의 별도의 계층에서 연산 수행/거래기록/거래검증 한 후, 결과값만 Layer 1에 기록하기 때문에 Layer 1에 주어지는 데이터 부담을 줄여 확장성 문제를 해결 할 수 있다.

예를 들어보면 Fig 1.에서 사용자는 자신의 거래(100 usdc 송금)를 직접 Layer 1에 기록하는 것이 아니라, 거래를 Layer 2 계층에서 거래를 수행하고 제 3의 정제자(Aggregator)가 다른 거래와 함께 압축(Layer 2 솔루션 방식에 따라 기록 방법이 다름)된 형태로 Layer 2의 거래를 Layer 1에 기록한다.

Layer 2 솔루션은 크게 채널(Channel), 사이드체인(Sidechains), 롤업(Rollup) 등으로 분류할 수 있다. 본 포스트에서는 각각의 Layer 2 솔루션에 대해 분석하고자 한다.

2. Layer 2 솔루션

2.1 채널 (Channel)

채널은 거래를 수행하는 당사자 간 프라이빗 채널을 만들고 해당 채널에서 거래 수행 후, 최종 거래 결과 값을 Layer 1 계층에 기록하는 방법이다. 여기서 거래 신뢰성을 위해 일련의 규칙이 사전에 정의될 필요가 있다.

채널은 주로 상태 채널과 지불 채널의 두 가지로 분류할 수 있는데 상태 채널은 일반화된 버전인 반면 지불 채널은 지불 관련 애플리케이션에 한정된다. Fig 2.는 상태 채널의 예시이다.

Fig 2. Example of channel

Fig 2. 예시에 따라 2번의 라운드를 수행하는 채널이 개설되었다고 가정해보자. 이때 Bob은 Round 1에서 100 USDC를 송금 후 70 FTM을 받고, Round 2에서 40FTM을 송금하고 50 USDC를 받는다. 최종적으로 Bob은 50 USDC , 30 FTM이 상태값이 되고, Alice는 50 USDC, 40 FTM을 상태값이 된다. 즉, 2번의 거래가 발생했음에도 중간 거래과정은 프라이빗 채널에 맡기고, 최종 거래 결과 값만이 Layer 1 블록체인에 기록된다.

채널의 경우 거래 신뢰성을 온전히 채널 당사자간 합의를 통해 얻고 있기 때문에, 채널 내 거래 신뢰도 확보는 필수적이다. 또한 프라이빗한 거래 채널을 참가자 간 구축할 필요가 있기 때문에 다수의 참가자가 참여하는 것이 어려운 단점이 있다.

2.2. 사이드체인 (SideChains)

SideChains은 Layer 1에 있는 자산/상태 등을 SideChains으로 이전하고, 이후 SideChain 내에서 거래를 수행하는 방법이다. 예를 들어 100 ETH를 Ethereum 체인 내에 갖고 있다고 가정 했을때, Sidechain으로 50 ETH를 송금하고 SideChain 내에서 거래를 수행하는 것이다. SideChain 내의 거래가 종료되면 거래 종료 후 남은 자산을 Layer 1으로 다시 이전할 수 있다. 이를 위해 자산의 상호 간 이동이 가능한 브릿지를 필요로 한다. Fig 3.은 SideChain의 예시이다.

Fig 3. Example of SideChains

Fig 3. 에서 Bob은 자신의 사이드체인 계좌로 Layer 1에 있는 100 USDC를 이동시킨다. 위의 입금 거래는 Layer 1에 기록되고, Layer 1 내에 있는 Bob의 자산은 감소한다. 입금된 USDC는 SideChain내에서 Alice에게 전송되고, 이후 Alice에게 150 USDC를 전송받았으므로 Bob은 SideChain내에 50 USDC를 갖게 된다. 이후 50 USDC는 Layer 1으로 인출가능하다.

위와 같이 Layer 2에 Layer 1 자산을 이동시키고 거래를 수행하는 방법을 사이드체인이라 한다. 사이드체인은 상태채널과 마찬가지로 사이드체인에 대한 신뢰성이 필요하다는 특징이 있다. 상태 채널의 신뢰성이 당사자간 합의를 통한 규칙에서 비롯 되었다면, 사이드체인은 각 체인의 합의알고리즘에 기인한다는 차이가 있다.

2.3 롤업 (Rollup)

상태 채널(State channel)과 사이드체인(SideChain)은 특정 거래의 중간 과정을 Layer 2에서 처리하고 최종 결과 값을 Layer 1에 기록하는 방식이었다고 한다면, 롤업은 Layer 2에서 발생하는 모든 거래를 압축된 형태로 Layer 1에 기록하는 방식이다.

예를 들어, Layer 2에서 발생하는 모든 트랜잭션은 암호학적 방법으로 짧은 값으로 커밋되고(ex. SHA256 Hash function) 압축된 커밋먼트(Commitment)와 최종 상태값 만이 주기적으로 Layer 1에 기록되는 방식으로 볼 수 있다. 이때, Layer 1에 올바른 Layer 2거래가 기록되었다는 것을 보장하기 위해서는 거래 압축(Transaction aggregation)에 대한 신뢰성이 필요한데, 위의 신뢰성을 어떻게 보장하는지에 따라 Optimistic Rollup과 zk-Rollup으로 분류할 수 있다.

Optimistic Rollup

Optimistic Rollup은 Layer 2 트랜잭션 압축에 대한 결과를 일단 신뢰하고, 유효하지 않은 Rollup에 대해 참여자가 사후 검증하는 방식이다. Optimistic Rollup을 사용하게 되면 거래들을 압축하는 것에 그다지 큰 컴퓨팅 비용을 요구하지 않지만, 유효하지 않은 Rollup에 대해 사후검증 할 시간이 필요하기 때문에 거래확정(Finalize)에 일주일 이상의 시간을 필요로 한다는 단점이 있다.

Fig 4. Optimistic Rollup

Optimistic Rollup은 기본적으로 압축결과를 사후 검증하기 때문에 유효하지 않은 압축을 수행한 Rollup 노드에게는 페널티가 부과되며, 부정한 트랜잭션을 찾아낸 사용자는 일정 보상을 얻게 된다.

zk-Rollup

zk-Rollup은 Optimistic Rollup과 같이 Rollup 결과를 사후검증 하는 것이 아니라 검증 후 기록하는 방법이다. zk-Rollup은 정보를 드러내지 않고 해당 정보의 유효성을 증명할 수 있는 영지식 증명(Zero-knowledge proof) 기술이 사용된다.

영지식 증명의 간단한 예를 들면, 내가 10000원을 지불할 수 있음을 증명하지만, 내가 갖고 있는 돈이 1000원짜리 10장을 갖고 있는지, 혹은 5000원 2장을 갖고 있는지는 밝히지 않고 증명하는 기술이라고 이해하면 좋을 것이다. 이제 “내가 10000원을 갖고 있다.” 라는 명제를 “모든 Layer 2의 트랜잭션에 대해 압축하면 A 상태값이 나온다.” 라는 명제로 치환하면 Rollup에 대한 증명이 될 수 있는 것이다.

zk-Rollup은 다음과 같이 수행된다. 먼저 Layer 2에서 트랜잭션이 발생하면 Rollup을 담당하는 Rollup 노드는 트랜잭션 압축을 수행하고, 일련의 모든 압축과정에 대해 영지식 증명 값을 생성한다. 구체적으로, 입력으로는 특정 주기의 Layer 2이고, 출력으로 SHA256 hash값이 나오는 형태의 함수식을 영지식 증명 기술로 증명하는 것이다.

Rollup에 대한 검증을 Optimistic Rollup과 같이 모든 트랜잭션 결과를 확인하는 것이 아니라 첨부된 영지식 증명에 대해 검증하면 되기 때문에 즉각적인 거래 확정이 가능하다. 그러나 압축 과정에 대해 증명 값을 필요로 하기 때문에 많은 컴퓨팅 비용을 필요로 한다는 단점이 있다.

Fig 5.은 zk-Rollup의 예이다.

Fig 5. zk-Rollup

Fig 5를 보면, Rollup을 담당하는 Rollup 서버는 Layer 2의 트랜잭션을 압축하고, 모든 압축과정에 대한 영지식 증명을 생성한다. Layer 1에 Rollup 트랜잭션을 기록하는 채굴자는 영지식증명의 유효성을 검사하고, 압축결과와 영지식증명 값을 Layer 1에 기록할 수 있다.

본 포스트에서는 다양한 Layer 2 솔루션에 대해 다뤄보았다. 각 솔루션 별로 장단점이 있지만, 대체적으로 Rollup에 대한 연구가 활발히 진행되고 있다. 특히 Rollup 기술은 다수의 거래를 하나의 거래로 압축하여 처리할 뿐만 아니라 데이터 가용성까지 보장할 수 있다는 점에서 다른 솔루션들과는 차별점을 지닌다. 그 중 zk-Rollup의 경우 빠른 거래 확정을 보장할 수 있고, 트랜잭션 압축의 단계를 블록체인 자체의 압축으로 확장할 수 있다는 점에서 보다 주목을 받고 있다.

실제로 Polygon, Starkware등의 연구그룹에서 특히 zk-Rollup을 통한 블록체인의 모듈화 및 블록체인 용량 압축에 대한 연구를 진행하고 있다. 위와 같은 모듈화 및 용량압축은 Ethereum에서 발생하는 확장성 문제를 해결하는 효율적인 방법이 될 것으로 전망된다. 현재 메타디움은 현재 zk-Rollup 연구 그룹과의 긴밀한 협력을 통해 Layer 2 블록체인 응용에 대한 연구개발을 고려하고 있다.

참고문헌

[1] https://ethereum.org/en/developers/docs/scaling/optimistic-rollups/

[2] https://www.web3.university/article/sidechains-vs-layer2s

작성자: Ljh

--

--