> For the complete documentation index, see [llms.txt](https://whs3-doge5k.gitbook.io/smartcontract-security-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whs3-doge5k.gitbook.io/smartcontract-security-docs/basics/3.-evm/evm-1.md).

# EVM의 구성 요소

EVM은 일반 컴퓨터와 유사한 구조를 가지고 있다. EVM의 구성요소를 크게 세 가지로 분류하면 휘발되는 Machine state, 불변하는 Virtual ROM, 영구적인 World state로 나눌 수 있다.

<figure><img src="https://2462457462-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLf9vwRuaws92ULgGvzTi%2Fuploads%2FI5Gy2PZRR9zKNOgqy3Ib%2Fimage.png?alt=media&amp;token=1926c205-95c4-4210-8d36-fa1f4967bed2" alt=""><figcaption><p><a href="https://ethereum.org/en/developers/docs/evm/">https://ethereum.org/en/developers/docs/evm/</a></p></figcaption></figure>

***

### Machine state

EVM이 트랜잭션을 실행하는 동안 유지되는 일시적인 상태로, 프로그램 카운터, 스택, 메모리, 가스 등의 실행 정보를 포함한다. 트랜잭션 실행이 끝나면 사라진다.

* PC Program Counter
  * 현재 실행중인 명령어 opcode의 위치를 추적
  * 어디까지 실행했는지를 기록
* 스택 Stack
  * 최대 1024개 깊이의 스택 구조를 가짐
  * 각 항목은 256비트 단어로 구성됨
  * 연산은 모두 스택을 통해 이루어짐
* Gas Available
  * 현재 트랜잭션 실행에 남은 가스
  * 모든 연산은 가스를 소모하며, 부족하면 실행이 중단됨
* 메모리 Memory
  * 휘발성 데이터 저장소
  * 트랜잭션 실행 중 임시 데이터 저장 용도
  * 트랜잭션이 끝나면 사라짐

***

### Virtual ROM

EVM 바이트 코드, 즉 스마트 컨트랙트 코드가 저장된 영역이다. 코드는 블록체인에 배포된 후 변경할 수 없으며, 모든 호출에 항상 동일한 코드가 실행된다.

* EVM Code
  * 스마트 컨트랙트의 컴파일 된 바이트 코드.
  * 솔리디티로 쓰인 언어가 컴파일 된 후의 Opcode가 저장되어있다.

***

### World State

블록체인의 전체 상태를 나타내는 구조로, 모든 계정, 잔액, 스마트 컨트랙트 저장소를 포함한다.

* Account Storage
  * 각 스마트 컨트랙트주소별로 분리된 저장소.
  * 키-값 구조로 구성되며, 머클 파트리샤 트라이에 의해 관리된다.

[<mark style="background-color:blue;">출처</mark>](https://www.quicknode.com/guides/ethereum-development/smart-contracts/a-dive-into-evm-architecture-and-opcodes#what-is-the-evm-ethereum-virtual-machine)
