Workspace IndexMath › Day 14

EIP-1559 Fee Market (base fee = AIMD) TODO

Math · Day 14 / 52 · August — Game Theory & Protocol Economics (Day 11-17)

Concept

EIP-1559 splits the block fee into a base fee set by the protocol and a priority fee added by the user; the base fee is burned, while only the priority fee goes to the block proposer. The base fee is adjusted by comparing the previous block's gas usage to a target (half of the block gas limit): it rises when usage exceeds the target and falls when usage is below it, with the change per block capped at 1/8, i.e., 12.5%. This feedback loop functions like an AIMD-style congestion controller, designed to converge around the target utilization. From the user's side, the actual amount paid is base fee + priority fee, capped at the max fee, with any excess refunded — this reduces the overbidding incentive that first-price auctions used to create. However, because the adjustment speed is capped, when demand shifts sharply the base fee can only catch up over several blocks, so during short spikes priority-fee competition still drives the price.

If you don't know the base fee's maximum rate of change when writing gas-estimation logic or transaction resubmission policy, you'll either set the max fee too low and get stuck pending, or set it needlessly high.

Code & Formula

# EIP-1559 수수료시장(base fee = AIMD) — 목표 가스 사용량 대비 초과/부족에 따라
# base fee 를 최대 ±12.5%/블록으로 조정하는 AIMD 컨트롤러를 재현한다.

GAS_LIMIT = 30_000_000
TARGET = GAS_LIMIT // 2          # 목표 사용량 = 가스 한도의 절반
MAX_CHANGE_DENOM = 8             # 블록당 최대 변화폭 = 1/8 (12.5%)


def next_base_fee(base_fee: float, gas_used: int) -> float:
    if gas_used == TARGET:
        return base_fee
    delta = base_fee * abs(gas_used - TARGET) // TARGET // MAX_CHANGE_DENOM
    delta = max(delta, 1)  # 스펙상 최소 1 wei는 움직인다
    if gas_used > TARGET:
        return base_fee + delta   # 혼잡 → 인상
    return max(base_fee - delta, 0)  # 여유 → 인하 (0 미만 방지)


# 블록별 실제 가스 사용량 시나리오: 혼잡 → 완화 → 정확히 목표
gas_used_per_block = [30_000_000, 30_000_000, 20_000_000, 10_000_000, 15_000_000, TARGET]

base_fee = 10 ** 9  # 1 gwei
print(f"target gas = {TARGET:,}, initial base fee = {base_fee:,} wei")
for i, used in enumerate(gas_used_per_block, start=1):
    new_fee = next_base_fee(base_fee, used)
    change_pct = (new_fee - base_fee) / base_fee * 100
    print(f"block {i}: gasUsed={used:>10,}  base_fee {base_fee:>12,} -> {new_fee:>12,} wei  ({change_pct:+.2f}%)")
    base_fee = new_fee

print(f"\n최종 base fee: {base_fee:,} wei — 목표 사용량에서는 그대로 유지됨을 확인")

Exercise

Take the base fee and gasUsed from the last few hundred blocks, reproduce the adjustment formula yourself to predict the next block's base fee, and compare it against the actual value.

Practical Connection

In a system like Verex where settlement or oracle resolution clusters around specific moments, you need to budget a max-fee buffer (e.g., the equivalent of several blocks' worth of increases) that accounts for the base fee's cap on its rate of increase, so settlement transactions don't stall.

If you study this on a given day, add a note link and a ✅ to this line in the source curriculum (docs/knowledge/math-50-curriculum.md) and this spot will lead straight to the note body. You can also write directly on this page — but regenerating overwrites it, so it's safer to keep anything you want to save as markdown under docs/algorithms/.


한국어

EIP-1559 수수료시장(base fee = AIMD) TODO

Math · Day 14 / 52 · 8월 — 게임이론·프로토콜 경제학 (Day 11–17)

개념

EIP-1559는 블록 수수료를 프로토콜이 정하는 base fee와 사용자가 붙이는 priority fee로 나누고, base fee는 소각하고 priority fee만 블록 제안자에게 준다. base fee는 이전 블록의 가스 사용량을 목표치(블록 가스 한도의 절반)와 비교해 조정되는데, 사용량이 목표보다 많으면 올리고 적으면 내리며 한 블록당 변화폭은 최대 1/8, 즉 12.5%로 제한된다. 이 되먹임은 혼잡 제어의 AIMD 계열 제어기와 같은 역할을 하며, 목표 사용률 주위로 수렴시키는 것이 설계 의도다. 사용자 입장에서 실제 지불액은 base fee + priority fee이되 max fee를 넘지 않고, 초과분은 환불되므로 first-price 경매에서 오던 과다 입찰 유인이 줄어든다. 다만 조정 속도에 상한이 있어 수요가 급변하면 여러 블록에 걸쳐서만 따라잡으므로, 짧은 스파이크 동안은 여전히 priority fee 경쟁이 가격을 결정한다.

가스비 추정 로직이나 트랜잭션 재전송 정책을 짤 때 base fee의 최대 변화율을 모르면 max fee를 너무 낮게 잡아 pending에 묶이거나 필요 이상으로 높게 잡게 된다.

코드 · 수식

# EIP-1559 수수료시장(base fee = AIMD) — 목표 가스 사용량 대비 초과/부족에 따라
# base fee 를 최대 ±12.5%/블록으로 조정하는 AIMD 컨트롤러를 재현한다.

GAS_LIMIT = 30_000_000
TARGET = GAS_LIMIT // 2          # 목표 사용량 = 가스 한도의 절반
MAX_CHANGE_DENOM = 8             # 블록당 최대 변화폭 = 1/8 (12.5%)


def next_base_fee(base_fee: float, gas_used: int) -> float:
    if gas_used == TARGET:
        return base_fee
    delta = base_fee * abs(gas_used - TARGET) // TARGET // MAX_CHANGE_DENOM
    delta = max(delta, 1)  # 스펙상 최소 1 wei는 움직인다
    if gas_used > TARGET:
        return base_fee + delta   # 혼잡 → 인상
    return max(base_fee - delta, 0)  # 여유 → 인하 (0 미만 방지)


# 블록별 실제 가스 사용량 시나리오: 혼잡 → 완화 → 정확히 목표
gas_used_per_block = [30_000_000, 30_000_000, 20_000_000, 10_000_000, 15_000_000, TARGET]

base_fee = 10 ** 9  # 1 gwei
print(f"target gas = {TARGET:,}, initial base fee = {base_fee:,} wei")
for i, used in enumerate(gas_used_per_block, start=1):
    new_fee = next_base_fee(base_fee, used)
    change_pct = (new_fee - base_fee) / base_fee * 100
    print(f"block {i}: gasUsed={used:>10,}  base_fee {base_fee:>12,} -> {new_fee:>12,} wei  ({change_pct:+.2f}%)")
    base_fee = new_fee

print(f"\n최종 base fee: {base_fee:,} wei — 목표 사용량에서는 그대로 유지됨을 확인")

연습

최근 수백 블록의 base fee와 gasUsed를 받아 조정 공식을 직접 재현해 다음 블록 base fee를 예측하고 실제값과 비교해 볼 것.

실무 · Verex 연결

Verex처럼 정산이나 오라클 리졸루션이 특정 시점에 몰리는 시스템은 base fee 상한 상승률을 감안해 max fee 버퍼(예: 몇 블록치 상승분)를 두어야 정산 트랜잭션이 멈추지 않는다.

공부한 날 원본 커리큘럼(docs/knowledge/math-50-curriculum.md)의 이 줄에 노트 링크와 ✅ 를 붙이면, 이 자리는 노트 본문으로 바로 이어집니다. 노트 없이 이 페이지에 바로 적어도 됩니다 — 다만 다시 생성하면 덮어쓰이므로, 남길 글은 docs/algorithms/ 의 마크다운으로 쓰는 편이 안전합니다.

← 13. 메커니즘 디자인(VCG 개념)15. 셸링 포인트 →