{"eip":3332,"title":"MEDGASPRICE Opcode","description":"An opcode for getting the median gas price of the parent block.","authors":["Justice Hudson (@jchancehud)"],"status":"Withdrawn","type":"Standards Track","category":"Core","created":"2021-03-05","discussionsTo":"https://ethereum-magicians.org/t/medgasprice-opcode-eip/5480","repo":"EIPs","label":"EIP-3332","officialUrl":"https://eips.ethereum.org/EIPS/eip-3332","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3332.md","url":"https://eips.huatuo.xyz/eip-3332/","tldr":{"en":"A withdrawn proposal for a MEDGASPRICE opcode returning the parent block's median gas price, so contracts could cap the gas price of incoming calls and blunt front-running.","ja":"親ブロックのガス価格の中央値を返す MEDGASPRICE オペコードの、取り下げられた提案。コントラクトが受け付ける呼び出しのガス価格に上限を設け、フロントランニングを鈍らせることができる。","ko":"부모 블록의 가스 가격 중앙값을 반환하는 MEDGASPRICE 오퍼코드에 대한, 철회된 제안. 컨트랙트가 들어오는 호출의 가스 가격에 상한을 두어 프런트러닝을 무디게 할 수 있다.","zh":"一项已撤回的提案：新增 MEDGASPRICE 操作码，返回父区块的 gas 价格中位数，让合约可以为传入调用的 gas 价格设上限，削弱抢跑。"},"tags":["evm","opcode","gas","mev","withdrawn"],"explainers":{"en":{"lang":"en","tldr":"A withdrawn proposal for a MEDGASPRICE opcode returning the parent block's median gas price, so contracts could cap the gas price of incoming calls and blunt front-running.","tags":["evm","opcode","gas","mev","withdrawn"],"related":[3198,1559,1344],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-3332/","markdown":"## What problem does it solve?\n\nSome actions pay a reward to whoever does them first, for example submitting a fraud proof to an optimistic rollup. A bot watching the mempool can copy such a transaction, attach a much higher gas price and steal the reward. That discourages honest participants from doing the actual verification work.\n\nA natural defence is to reject calls that pay \"too much\" for gas, so a copycat cannot simply outbid. But a contract needs a reference price to set that cap. The options were a hard-coded constant (soon outdated) or an admin who updates it (trust, extra transactions). EIP-3332 proposed letting the EVM report a market price directly.\n\n## How it works\n\n- New opcode `MEDGASPRICE` at `0x46`, 0 inputs, 1 output, cost 8 gas.\n- It pushes the **median gas price of the parent block**. It looks at the parent because the current block is still being built.\n- After [EIP-1559](/eip-1559/), it was meant to return the median `effective_gas_price` of the previous block. Combined with `BASEFEE` from [EIP-3198](/eip-3198/), a contract could subtract the base fee to bound the priority fee instead.\n\nThe intended pattern from the spec:\n\n```solidity\nfunction submitFraudProof(bytes calldata proof) public {\n    require(tx.gasprice \u003c= maxGasPrice());\n    // verify and reward\n}\n\nfunction maxGasPrice() public view returns (uint) {\n    return 3 * block.medgasprice; // hypothetical binding for MEDGASPRICE\n}\n```\n\n## Sample code\n\n`MEDGASPRICE` never existed. With today's opcodes, a contract can apply the same idea by capping the **priority fee** relative to the base fee:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract CappedReward {\n    uint256 public constant MAX_TIP = 2 gwei;\n\n    function submitFraudProof(bytes calldata proof) external {\n        // tx.gasprice is the effective price paid; block.basefee comes from EIP-3198.\n        require(tx.gasprice - block.basefee \u003c= MAX_TIP, \"tip too high\");\n        // ... verify proof and pay reward ...\n    }\n}\n```\n\n## Things to know\n\n- Status: **Withdrawn**. It was never adopted.\n- Opcode `0x46` was already assigned to `CHAINID` by [EIP-1344](/eip-1344/) (Istanbul), so the proposed number could not have been used as written.\n- The spec itself lists the limits of gas-price caps: they only help if block producers order equal-price transactions fairly, and they can be defeated simply by reordering. A rapidly changing median can also make honest transactions fail or become vulnerable again.\n- Today most front-running happens through private order flow and block builders, where a gas price cap gives little protection. Commit-reveal schemes or binding the reward to the submitter's identity are more robust.\n"},"ja":{"lang":"ja","tldr":"親ブロックのガス価格の中央値を返す MEDGASPRICE オペコードの、取り下げられた提案。コントラクトが受け付ける呼び出しのガス価格に上限を設け、フロントランニングを鈍らせることができる。","tags":["evm","opcode","gas","mev","withdrawn"],"related":[3198,1559,1344],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-3332/","markdown":"## 何を解決するのか\n\n最初に行った人に報酬が支払われる行為があります。たとえば Optimistic ロールアップへの不正証明の提出です。mempool を監視するボットは、そうしたトランザクションをコピーし、はるかに高いガス価格を付けて報酬を奪えます。これは、正直な参加者が実際の検証作業を行う意欲をそぎます。\n\n当然の防御策は、ガス代を「払いすぎ」の呼び出しを拒否することで、真似をする側が単純に高値で競り勝てないようにすることです。しかし、その上限を設定するには、コントラクトに基準となる価格が必要です。選択肢は、ハードコードされた定数（すぐに時代遅れになる）か、更新する管理者（信頼と余分なトランザクションが必要）でした。EIP-3332 は、EVM に市場価格を直接報告させることを提案しました。\n\n## 仕組み\n\n- 新しいオペコード `MEDGASPRICE` を `0x46` に追加します。入力 0、出力 1、コストは 8 ガスです。\n- **親ブロックのガス価格の中央値**をプッシュします。現在のブロックはまだ構築中のため、親ブロックを見ます。\n- [EIP-1559](/eip-1559/) の後は、前のブロックの `effective_gas_price` の中央値を返すことが意図されていました。[EIP-3198](/eip-3198/) の `BASEFEE` と組み合わせれば、コントラクトはベースフィーを引いて、代わりにプライオリティフィーに上限を設けることもできました。\n\n仕様が想定しているパターン:\n\n```solidity\nfunction submitFraudProof(bytes calldata proof) public {\n    require(tx.gasprice \u003c= maxGasPrice());\n    // verify and reward\n}\n\nfunction maxGasPrice() public view returns (uint) {\n    return 3 * block.medgasprice; // hypothetical binding for MEDGASPRICE\n}\n```\n\n## サンプルコード\n\n`MEDGASPRICE` は存在したことがありません。現在のオペコードでも、ベースフィーに対する**プライオリティフィー**に上限を設けることで、同じ考え方をコントラクトに適用できます。\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract CappedReward {\n    uint256 public constant MAX_TIP = 2 gwei;\n\n    function submitFraudProof(bytes calldata proof) external {\n        // tx.gasprice is the effective price paid; block.basefee comes from EIP-3198.\n        require(tx.gasprice - block.basefee \u003c= MAX_TIP, \"tip too high\");\n        // ... verify proof and pay reward ...\n    }\n}\n```\n\n## 知っておくべきこと\n\n- ステータス: **Withdrawn**。採用されたことはありません。\n- オペコード `0x46` は、すでに [EIP-1344](/eip-1344/)（Istanbul）によって `CHAINID` に割り当てられていたため、提案された番号は、書かれたままでは使えませんでした。\n- 仕様自体が、ガス価格の上限の限界を挙げています。上限が役立つのは、ブロックプロデューサーが同じ価格のトランザクションを公平に並べる場合だけで、並べ替えるだけで無力化できます。中央値が急速に変化すると、正直なトランザクションが失敗したり、再び脆弱になったりすることもあります。\n- 現在のフロントランニングの大半は、プライベートなオーダーフローとブロックビルダーを通じて行われており、ガス価格の上限はほとんど防御になりません。コミット・リビールの方式や、報酬を提出者の身元に結び付けることのほうが堅牢です。\n"},"ko":{"lang":"ko","tldr":"부모 블록의 가스 가격 중앙값을 반환하는 MEDGASPRICE 오퍼코드에 대한, 철회된 제안. 컨트랙트가 들어오는 호출의 가스 가격에 상한을 두어 프런트러닝을 무디게 할 수 있다.","tags":["evm","opcode","gas","mev","withdrawn"],"related":[3198,1559,1344],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-3332/","markdown":"## 어떤 문제를 해결하나요?\n\n어떤 행동은 가장 먼저 한 사람에게 보상을 줍니다. 예를 들어 옵티미스틱 롤업에 사기 증명을 제출하는 경우입니다. 멤풀을 감시하는 봇은 이런 트랜잭션을 복사해 훨씬 높은 가스 가격을 붙여 보상을 가로챌 수 있습니다. 이는 정직한 참여자가 실제 검증 작업을 하려는 의욕을 꺾습니다.\n\n자연스러운 방어책은 가스비를 \"너무 많이\" 내는 호출을 거부하는 것으로, 따라 하는 쪽이 단순히 더 높은 가격으로 이길 수 없게 합니다. 하지만 컨트랙트가 그 상한을 정하려면 기준 가격이 필요합니다. 선택지는 하드코딩된 상수(곧 낡아짐)나 갱신하는 관리자(신뢰와 추가 트랜잭션 필요)였습니다. EIP-3332는 EVM이 시장 가격을 직접 알려 주자고 제안했습니다.\n\n## 어떻게 동작하나요?\n\n- 새 오퍼코드 `MEDGASPRICE`가 `0x46`에 추가되며 입력 0, 출력 1, 비용 8 가스입니다.\n- **부모 블록의 가스 가격 중앙값**을 푸시합니다. 현재 블록은 아직 만들어지는 중이므로 부모 블록을 봅니다.\n- [EIP-1559](/eip-1559/) 이후에는 이전 블록의 `effective_gas_price` 중앙값을 반환하도록 의도되었습니다. [EIP-3198](/eip-3198/)의 `BASEFEE`와 함께 쓰면 컨트랙트는 베이스 피를 빼서 대신 우선 수수료에 상한을 둘 수 있었습니다.\n\n명세가 의도한 패턴:\n\n```solidity\nfunction submitFraudProof(bytes calldata proof) public {\n    require(tx.gasprice \u003c= maxGasPrice());\n    // verify and reward\n}\n\nfunction maxGasPrice() public view returns (uint) {\n    return 3 * block.medgasprice; // hypothetical binding for MEDGASPRICE\n}\n```\n\n## 샘플 코드\n\n`MEDGASPRICE`는 존재한 적이 없습니다. 오늘날의 오퍼코드로도 컨트랙트는 베이스 피에 대한 **우선 수수료**에 상한을 두는 방식으로 같은 아이디어를 적용할 수 있습니다.\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract CappedReward {\n    uint256 public constant MAX_TIP = 2 gwei;\n\n    function submitFraudProof(bytes calldata proof) external {\n        // tx.gasprice is the effective price paid; block.basefee comes from EIP-3198.\n        require(tx.gasprice - block.basefee \u003c= MAX_TIP, \"tip too high\");\n        // ... verify proof and pay reward ...\n    }\n}\n```\n\n## 알아둘 점\n\n- 상태: **Withdrawn**. 채택된 적이 없습니다.\n- 오퍼코드 `0x46`은 이미 [EIP-1344](/eip-1344/)(Istanbul)에서 `CHAINID`에 할당되어 있었으므로, 제안된 번호는 쓰인 그대로는 사용할 수 없었습니다.\n- 명세 자체가 가스 가격 상한의 한계를 나열합니다. 상한은 블록 생산자가 가격이 같은 트랜잭션을 공정하게 정렬할 때만 도움이 되고, 순서를 바꾸는 것만으로 무력화될 수 있습니다. 중앙값이 급격히 변하면 정직한 트랜잭션이 실패하거나 다시 취약해질 수도 있습니다.\n- 오늘날 대부분의 프런트러닝은 프라이빗 오더 플로와 블록 빌더를 통해 일어나며, 가스 가격 상한은 거의 보호가 되지 않습니다. 커밋-리빌 방식이나 보상을 제출자의 신원에 묶는 방식이 더 견고합니다.\n"},"zh":{"lang":"zh","tldr":"一项已撤回的提案：新增 MEDGASPRICE 操作码，返回父区块的 gas 价格中位数，让合约可以为传入调用的 gas 价格设上限，削弱抢跑。","tags":["evm","opcode","gas","mev","withdrawn"],"related":[3198,1559,1344],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-3332/","markdown":"## 它解决什么问题？\n\n有些操作会向最先完成的人支付奖励，例如向 optimistic rollup 提交欺诈证明。监视内存池的机器人可以复制这样的交易，附上高得多的 gas 价格，从而抢走奖励。这会打击诚实参与者去做真正验证工作的积极性。\n\n一种自然的防御方式是拒绝为 gas 支付\"过高\"价格的调用，这样模仿者就无法简单地出更高价。但合约需要一个参考价格来设定这个上限。可选方案要么是硬编码的常量（很快就会过时），要么是由管理员更新（需要信任，还要额外的交易）。EIP-3332 提议让 EVM 直接报告市场价格。\n\n## 它如何运作\n\n- 新操作码 `MEDGASPRICE`，位于 `0x46`，0 个输入，1 个输出，成本 8 gas。\n- 它压入**父区块的 gas 价格中位数**。之所以看父区块，是因为当前区块仍在构建中。\n- 在 [EIP-1559](/eip-1559/) 之后，它本意是返回上一个区块 `effective_gas_price` 的中位数。结合 [EIP-3198](/eip-3198/) 的 `BASEFEE`，合约可以减去基础费用，转而为优先费设上限。\n\n规范中设想的用法：\n\n```solidity\nfunction submitFraudProof(bytes calldata proof) public {\n    require(tx.gasprice \u003c= maxGasPrice());\n    // verify and reward\n}\n\nfunction maxGasPrice() public view returns (uint) {\n    return 3 * block.medgasprice; // hypothetical binding for MEDGASPRICE\n}\n```\n\n## 示例代码\n\n`MEDGASPRICE` 从未存在过。用如今的操作码，合约可以通过相对于基础费用限制**优先费**来实现同样的想法：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract CappedReward {\n    uint256 public constant MAX_TIP = 2 gwei;\n\n    function submitFraudProof(bytes calldata proof) external {\n        // tx.gasprice is the effective price paid; block.basefee comes from EIP-3198.\n        require(tx.gasprice - block.basefee \u003c= MAX_TIP, \"tip too high\");\n        // ... verify proof and pay reward ...\n    }\n}\n```\n\n## 需要注意\n\n- 状态：**Withdrawn**。它从未被采纳。\n- 操作码 `0x46` 已经被 [EIP-1344](/eip-1344/)（Istanbul）分配给 `CHAINID`，因此所提议的编号按原样根本无法使用。\n- 规范本身列出了 gas 价格上限的局限：只有区块生产者公平地排列同价交易时它才有用，而且仅靠重新排序就能使其失效。快速变化的中位数还可能让诚实的交易失败，或再次变得易受攻击。\n- 如今大多数抢跑通过私有订单流和区块构建者进行，gas 价格上限几乎起不到保护作用。承诺-揭示（commit-reveal）方案，或把奖励与提交者的身份绑定，更加稳健。\n"}}}
