> 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/4./undefined.md).

# 유효성 검사

### **유효성 검사 - 1**

EVM을 사용하지 않고, 기본적인 형식 및 서명, 자원 조건을 확인한다.

<table><thead><tr><th width="160">검사 목록 예시</th><th>설명</th></tr></thead><tbody><tr><td><strong>sign 유효성</strong></td><td>v,r,s 값으로 from 주소를 복원할 수 있어야 함</td></tr><tr><td><strong>nonce 일치 여부</strong></td><td>transaction nonce ≥ account nonce를 만족해야 함</td></tr><tr><td><strong>gas price 확인</strong></td><td>maxFeePerGas ≥ base fee를 만족해야 함</td></tr><tr><td><strong>balance 확인</strong></td><td>balance ≥ (gas limit * maxFeePerGas) + msg.value를 만족해야 함</td></tr></tbody></table>

***

### **유효성 검사 - 2**

각 노드에서 EVM을 통해 블록 내의 트랜잭션을 엄밀하게 검증한다.

<table><thead><tr><th width="229">검사 목록 예시</th><th>설명</th></tr></thead><tbody><tr><td><strong>이전 유효성 검사 항목</strong></td><td>블록에 포함된 트랜잭션을 재검증</td></tr><tr><td><strong>계정의 잔액 변화</strong></td><td>트랜잭션 결과대로 송신자, 수신자의 잔액이 변화해야 함</td></tr><tr><td><strong>EOA의 nonce 증가</strong></td><td>트랜잭션 실행 후 nonce 값이 증가해야 함</td></tr><tr><td><strong>컨트랙트 storage 변화</strong></td><td>실행 결과와 상태변수 변화가 일치해야 함</td></tr><tr><td><strong>가스 소모량 변화</strong></td><td>gas used가 gas limit을 넘지 않아야 함</td></tr><tr><td><strong>최종 상태 루트(State Root) 검사</strong></td><td>제안된 블록의 State Root와 EVM 실행에서 얻은 State Root 값이 일치해야 함</td></tr></tbody></table>

2차 유효성 검사를 진행하고 블록이 이상이 없다고 판단하면, 각 노드는 해당 블록을 자신의 체인에 추가한다.

{% hint style="info" %}
만약 유효성 검사가 실패하면 어떻게 되나요?

트랜잭션이 실행되기 직전, EVM은 현재 상태의 스냅샷을 생성하고, 이후 상태 변경 작업은 임시 공간에 적용된다. 만약 트랜잭션이 정상적으로 완료되면 이 변경사항은 실제 블록체인 상태로 반영되지만, 도중에 오류가 발생할 경우에는 해당 스냅샷을 기준으로 상태를 **완전히 되돌린다**. 이를 통해 트랜잭션 실행의 결과가 실패하더라도 블록체인의 이전 상태가 그대로 보존되고, 실행 전과 동일한 상태로 복원된다.
{% endhint %}

[<mark style="background-color:blue;">출처</mark>](https://ethereum.github.io/yellowpaper/paper.pdf)
