---
eip: 1482
label: EIP-1482
title: Define a maximum block timestamp drift
status: Stagnant
type: Standards Track
category: Core
created: 2018-10-09
official: https://eips.ethereum.org/EIPS/eip-1482
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1482.md
canonical: https://eips.huatuo.xyz/zh/eip-1482/
lang: zh
tldr: 提议为区块时间戳写下明确的规则：晚于父区块，且最多比验证者的时钟超前 15 秒，与 Geth 和 Parity 已经执行的规则一致。
tags: [consensus, timestamp, core, specification]
---

# EIP-1482: Define a maximum block timestamp drift

> Include an explicit definition of the acceptable timestamp drift in the protocol specification.

**TL;DR:** 提议为区块时间戳写下明确的规则：晚于父区块，且最多比验证者的时钟超前 15 秒，与 Geth 和 Parity 已经执行的规则一致。

## 它解决什么问题？

黄皮书把区块的时间戳定义为"该区块创建时 Unix time() 的合理输出"。什么算"合理"，从未被明确规定。这让智能合约开发者不确定能在多大程度上信任 `block.timestamp`，原则上也允许不同客户端对哪些区块有效产生分歧。

实际上，当时的两大主流客户端 Geth 和 Parity 已经应用了同样的检查。EIP-1482 提议把这条事实上的规则写入规范。

## 它如何运作

没有新的行为，只是一个明确的定义。在区块验证时，时间戳必须：

1. **严格大于**父区块的时间戳，并且
2. 比验证节点自身的系统时间**超前不超过 15 秒**。

超前太多的区块会被拒绝（客户端可以先保留它，直到它变为有效）。因此区块生产者在选择时间戳上有一定自由，但只能在很窄的窗口内。

## 示例代码

验证规则的伪代码：

```python
MAX_FUTURE_DRIFT = 15  # seconds

def validate_timestamp(block, parent, now):
    if block.timestamp <= parent.timestamp:
        raise InvalidBlock("timestamp not after parent")
    if block.timestamp > now + MAX_FUTURE_DRIFT:
        raise FutureBlock("timestamp too far in the future")
```

这对合约作者意味着什么：请把 `block.timestamp` 视为近似值。

```solidity
// Fine: deadlines measured in minutes, hours or days
require(block.timestamp <= auctionEnd, "auction over");

// Risky: logic that depends on the exact second (e.g. randomness, sub-minute windows)
```

## 需要注意

- 状态是 **Stagnant**；它从未作为正式的规范变更被采纳。
- 规范指出，主网最早期的一些区块可能违反这一规则，因此对历史区块可能需要放宽。
- 自转向权益证明（[EIP-3675](/eip-3675/)）以来，执行层区块的时间戳与信标链固定的槽位时间绑定，生产者不再拥有这个 EIP 试图限制的自由选择权。通用的建议依然成立：永远不要把时间戳当作随机性的来源。
- [EIP-1985](/eip-1985/) 另行提议了 EVM 中时间戳值的上限范围。


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-1482
