Проверенный контрактЧастичноеLicenseRef-DCL-1.0
AddressRegistry
Адрес0xe2b4c27224ddefff7d2b3b0e66e3955ab4e2466a
- Баланс
0 ETH
- Транзакций
1
- Компилятор
solc 0.8.25
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.8.25+commit.b61c2a91
- Язык
- solidity
- Оптимизация
- Да, 100 000 прогонов
- Версия EVM
- cancun
- Лицензия
- LicenseRef-DCL-1.0
- Совпадение
- Частичноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 26 134 922
- Транзакция создания
- 0xf270d4c997…74592d8cd4
2 файла
- src/concrete/AddressRegistry.solглавный5,52 КБ
- src/interface/IAddressRegistryV1.sol6,82 КБ
src/concrete/AddressRegistry.sol
// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity =0.8.25;
import {IAddressRegistryV1} from "../interface/IAddressRegistryV1.sol";
/// @dev The only account that may bind a name. A compile-time constant rather
/// than storage, so it can never be rotated, and part of the creation code, so
/// changing it changes the deterministic deploy address and code hash of
/// `AddressRegistry` on every network.
///
/// Rotating it is an ordinary source change that moves the creation code, and
/// therefore the deploy address, the code hash, the snapshot `script/Build.sol`
/// generates and the release that carries them.
address constant ADDRESS_REGISTRY_ROOT = 0x0b300013CD54a8F1aC40981f80FaaA18b8Cc1E4c;
/// @title AddressRegistry
/// @notice The whole of `IAddressRegistryV1`: an immutable root authority binds
/// a `bytes32` name, anyone reads a bound name and gets back the address with
/// the moment it was bound, and a read of an unbound name reverts.
///
/// There is deliberately nothing else. No removal, no upgrade, no pause, and no
/// authority besides root — root is a compile-time constant, so it cannot even
/// hand itself over.
///
/// A binding is mutable because the address it names is. Rotating an owning
/// multisig is ordinary business and has to be expressible without moving
/// anybody's deterministic address, which a binding welded to one address
/// forever would make impossible: the name is in the consumer's creation code,
/// so a new name means new creation code and a new address.
///
/// Mutability costs nothing already deployed. A consumer resolves a name once,
/// in its constructor, and never reads the registry again, so re-binding a name
/// changes what the next deployment resolves and nothing else.
///
/// The moment is reported and nothing more; this contract holds nothing
/// pending. A name's moment strictly increases, so an age derived from it never
/// overstates the time that passed.
contract AddressRegistry is IAddressRegistryV1 {
/// Thrown when `block.timestamp` does not fit the moment's 96 bits, instead
/// of narrowing it. Unreachable on any plausible clock, and kept because
/// the alternative is a truncation that reads as an older binding.
/// @param timestamp The `block.timestamp` that did not fit.
error TimestampOverflow(uint256 timestamp);
/// @dev One binding, packed into one word. Declared in the contract because
/// it is storage layout and no part of anybody's ABI — `get` returns two
/// flat values.
///
/// 96 bits is what is left beside a 160-bit address, and far more than a
/// clock needs: `2**96` seconds is some 2.5e21 years.
struct Binding {
/// Zero if and only if the name is unbound, which is what `register`
/// rejecting the zero address preserves.
address account;
/// The `block.timestamp` of the most recent `register`. Never zero for
/// a bound name.
uint96 registeredAt;
}
/// The bindings. Not `public`: the only reader is `get`, which reverts on an
/// unbound name rather than answering zero.
mapping(bytes32 name => Binding binding) internal sBindings;
/// @inheritdoc IAddressRegistryV1
function register(bytes32 name, address account) external {
if (msg.sender != ADDRESS_REGISTRY_ROOT) {
revert NotRoot(msg.sender);
}
// Rejected so that a name can never be both bound and unreadable.
if (account == address(0)) {
revert ZeroAccount(name);
}
// Both comparisons check the clock against a width or a stored moment,
// never against a deadline, so the validator-nudge hazard the analysers
// flag does not reach them.
// slither-disable-start timestamp
// forge-lint: disable-next-line(block-timestamp)
if (block.timestamp > type(uint96).max) {
revert TimestampOverflow(block.timestamp);
}
// Read after the cheap guards, so a refused call does not pay for it.
uint256 registeredAt = sBindings[name].registeredAt;
// forge-lint has no pair form, so each comparison needs its own
// directive on the line immediately above it.
// forge-lint: disable-next-line(block-timestamp)
if (block.timestamp <= registeredAt) {
revert TimestampNotAfterBinding(name, block.timestamp, registeredAt);
}
// slither-disable-end timestamp
// Assigned whole, so a re-bind replaces the moment in the same write
// that replaces the address.
sBindings[name] = Binding({account: account, registeredAt: uint96(block.timestamp)});
emit Register(name, account);
}
/// @inheritdoc IAddressRegistryV1
/// @dev Bound-ness is read off `account`, not the moment: the address is the
/// binding and the moment is metadata about when it was written.
function get(bytes32 name) external view returns (address, uint256) {
Binding memory binding = sBindings[name];
// Slither reaches this because `account` shares a struct with a value
// written from `block.timestamp`. There is no time in it.
// slither-disable-start timestamp
if (binding.account == address(0)) {
revert NameNotRegistered(name);
}
// slither-disable-end timestamp
return (binding.account, binding.registeredAt);
}
}
src/interface/IAddressRegistryV1.sol
// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity ^0.8.25;
/// @title IAddressRegistryV1
/// @notice A registry of `bytes32` names to addresses with exactly two
/// operations: an immutable root authority binds a name (`register`), and
/// anyone reads a bound name (`get`). Root may re-bind a name it has already
/// bound. There is no removal, no upgrade and no authority beyond root, and an
/// implementation MUST NOT add any.
///
/// Names are opaque 32-byte values. This interface says nothing about how a
/// name is derived — hashed from a string, a raw ASCII literal, a counter — and
/// an implementation MUST NOT constrain it. Two callers agreeing on a name is
/// entirely their business.
///
/// Bindings are mutable because the addresses they name are. Rotating an owning
/// multisig is ordinary business, and a binding that could never change would
/// make it impossible: the name a consumer resolves is in that consumer's
/// creation code, so a name welded to one address forever would force a new
/// name — and therefore new creation code and a new deterministic address — for
/// a routine rotation. That is the problem the registry exists to remove, not a
/// property worth keeping.
///
/// A binding moving never moves anything already deployed. A consumer resolves
/// a name once, at construction, and stores the answer; it never consults the
/// registry again. So re-binding a name changes what the *next* deployment
/// resolves and nothing else, which is exactly what makes a rotation a
/// deliberate migration rather than a silent, retroactive change to live
/// contracts.
///
/// A compromised root therefore cannot touch anything deployed. It can point a
/// name at an address it controls, so that a deployment made after the
/// compromise snapshots that address. That is caught by verifying a deployment
/// after deploying it and before anything depends on it: the deployed contract
/// has already snapshotted the value, so checking it is checking settled state.
/// A poisoned deploy is a burned deterministic address, discovered before use.
///
/// `get` also answers with the moment a binding was made, because an address
/// alone cannot say that it has just moved. The registry reports the moment
/// and imposes nothing on it: a fresh binding is live at once, and an
/// implementation MUST NOT withhold one. What counts as too fresh belongs to
/// the caller.
interface IAddressRegistryV1 {
/// Thrown when an account that is not the root authority calls `register`.
/// @param sender The `msg.sender` that was not root.
error NotRoot(address sender);
/// Thrown when `register` is called with the zero address. The zero address
/// is how an unbound name reads, so binding it would produce a name that is
/// both bound and unreadable. A name cannot be unbound once bound; the
/// closest thing is binding it somewhere deliberately inert.
/// @param name The name that was being bound to the zero address.
error ZeroAccount(bytes32 name);
/// Thrown by `get` when a name has never been bound, so that a caller
/// cannot silently proceed on the zero address by forgetting to check.
/// @param name The name that is not bound.
error NameNotRegistered(bytes32 name);
/// Thrown by `register` when the clock is not strictly after the moment the
/// name already carries.
///
/// Behind it would lower the moment, and a caller measuring
/// `block.timestamp -` it would then read an age larger than the time that
/// passed. Equal to it means a re-bind that changes the address while
/// leaving the moment identical, which a caller cannot detect. An unbound
/// name reads as a moment of zero, so a bind at a clock of zero is refused
/// too: zero is the field's unset value, and refusing it is what makes a
/// stored moment never zero.
/// @param name The name that was being bound.
/// @param timestamp The clock the bind was attempted at.
/// @param registeredAt The moment the name carries. Zero when unbound.
error TimestampNotAfterBinding(bytes32 name, uint256 timestamp, uint256 registeredAt);
/// Emitted every time `name` is bound, including when it is re-bound. The
/// log is the complete history of the registry and the only way to discover
/// a binding without already knowing the name; the most recent `Register`
/// for a name is its current binding.
///
/// The moment is not a field here, because a log already carries the block
/// it was emitted in.
/// @param name The name that was bound.
/// @param account The address `name` was bound to.
event Register(bytes32 indexed name, address indexed account);
/// Binds `name` to `account`, replacing any address it is already bound to.
///
/// The implementation MUST revert `NotRoot` unless the caller is the root
/// authority, MUST revert `ZeroAccount` if `account` is the zero address,
/// and MUST revert `TimestampNotAfterBinding` unless the clock is strictly
/// after the moment the name carries, so a name's moment strictly
/// increases. On success it MUST emit `Register` and record
/// `block.timestamp` as the moment — including when `account` is the
/// address already bound, which is a bind like any other. The moment dates
/// the write, not the value.
/// @param name The name to bind.
/// @param account The address to bind it to.
function register(bytes32 name, address account) external;
/// The address `name` is currently bound to, and when it was bound.
///
/// The implementation MUST revert `NameNotRegistered` when `name` is
/// unbound, rather than returning zeros, so that no caller has to remember
/// to check. It MUST NOT expose any other reader that returns the zero
/// address for an unbound name, as that reintroduces exactly the mistake
/// this reverting read exists to prevent. An implementation storing the
/// moment narrower than `block.timestamp` MUST reject what does not fit
/// rather than truncate it, since a truncated moment reads as older.
///
/// Answers with the current binding: whatever root has bound most
/// recently, and the moment it was bound. A caller that stores the result
/// keeps that value; one that reads again gets whatever is current then.
/// @param name The name to read.
/// @return The address bound to `name`. Never the zero address.
/// @return The `block.timestamp` of the most recent `register` for `name`.
/// Never zero, so zero in this field means unbound and nothing else.
function get(bytes32 name) external view returns (address, uint256);
}
Настройки компилятораПоказать
{
"viaIR": false,
"metadata": {
"appendCBOR": false,
"bytecodeHash": "none",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 100000,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"forge-std-1.17.0/=dependencies/forge-std-1.17.0/",
"rain-lib-memkv-0.2.0/=dependencies/rain-lib-memkv-0.2.0/",
"rain-sol-codegen-0.1.39/=dependencies/rain-sol-codegen-0.1.39/"
]
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.