Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

StakeTableV3

Git Source

Inherits: StakeTableV2

Title: StakeTableV3 - Adds x25519 key and p2p address to validator registration.

V3 adds:

  1. x25519 encryption key tracking with uniqueness enforcement
  2. p2p address (host:port) validation and registration
  3. registerValidatorV3 replaces registerValidatorV2 (which is now deprecated)
  4. updateX25519Key, updateP2pAddr, and updateNetworkConfig for updating network configuration All new functions are virtual. Deprecated overrides are not virtual (same pattern as V2).

All functions are marked as virtual so that future upgrades can override them.

Constants

MAX_P2P_ADDR_LENGTH

Maximum length for p2p address strings (in bytes)

uint256 public constant MAX_P2P_ADDR_LENGTH = 512

State Variables

x25519Keys

x25519 keys that have been registered

Ensures uniqueness of x25519 keys across validators

mapping(bytes32 x25519Key => bool used) public x25519Keys

Functions

constructor

Constructor

Disables initializers to prevent implementation contract from being initialized

constructor() ;

initializeV3

Reinitialize the contract for V3

function initializeV3() public virtual onlyOwner reinitializer(3);

getVersion

Get the version of the contract

function getVersion()
    public
    pure
    virtual
    override
    returns (uint8 majorVersion, uint8 minorVersion, uint8 patchVersion);

validateP2pAddr

Validate a p2p address in host:port format.

Minimal validation to catch common misconfiguration errors early. The contract cannot verify that the address is actually reachable.

function validateP2pAddr(string memory p2pAddr) public pure virtual;

Parameters

NameTypeDescription
p2pAddrstringThe p2p address to validate

registerValidatorV3

Register a validator with x25519 key and p2p address

function registerValidatorV3(
    BN254.G2Point memory blsVK,
    EdOnBN254.EdOnBN254Point memory schnorrVK,
    BN254.G1Point memory blsSig,
    bytes memory schnorrSig,
    uint16 commission,
    string memory metadataUri,
    bytes32 x25519Key,
    string memory p2pAddr
) external virtual whenNotPaused;

Parameters

NameTypeDescription
blsVKBN254.G2PointThe BLS verification key
schnorrVKEdOnBN254.EdOnBN254PointThe Schnorr verification key
blsSigBN254.G1PointThe BLS signature that authenticates the BLS VK
schnorrSigbytesThe Schnorr signature that authenticates the Schnorr VK
commissionuint16in % with 2 decimals, from 0.00% (value 0) to 100% (value 10_000)
metadataUristringThe metadata URI for the validator
x25519Keybytes32The x25519 encryption key for the validator
p2pAddrstringThe p2p address (host:port) for the validator

registerValidatorV2

Deprecate registerValidatorV2

Users must call registerValidatorV3 instead

function registerValidatorV2(
    BN254.G2Point memory,
    EdOnBN254.EdOnBN254Point memory,
    BN254.G1Point memory,
    bytes memory,
    uint16,
    string memory
) external pure override;

updateX25519Key

Update the x25519 encryption key. The key must be unique (never previously used). To also update the p2p address, use updateNetworkConfig instead.

function updateX25519Key(bytes32 x25519Key) external virtual whenNotPaused;

Parameters

NameTypeDescription
x25519Keybytes32The new x25519 encryption key (must be unique, never previously used)

updateP2pAddr

Update the p2p address. Use for operational changes like server migration.

function updateP2pAddr(string memory p2pAddr) external virtual whenNotPaused;

Parameters

NameTypeDescription
p2pAddrstringThe new p2p address (host:port)

updateNetworkConfig

Update x25519 key and p2p address for an active validator. Primary use: initial configuration for validators registered before V3. Also usable to rotate the x25519 key. The x25519 key must be new (never used before); the p2p address may be the same as the current one. Emits both X25519KeyUpdated and P2pAddrUpdated.

function updateNetworkConfig(bytes32 x25519Key, string memory p2pAddr)
    external
    virtual
    whenNotPaused;

Parameters

NameTypeDescription
x25519Keybytes32The new x25519 encryption key (must be unique, never previously used)
p2pAddrstringThe p2p address (host:port)

Events

ValidatorRegisteredV3

A validator is registered with x25519 key and p2p address

event ValidatorRegisteredV3(
    address indexed account,
    BN254.G2Point blsVK,
    EdOnBN254.EdOnBN254Point schnorrVK,
    uint16 commission,
    BN254.G1Point blsSig,
    bytes schnorrSig,
    string metadataUri,
    bytes32 x25519Key,
    string p2pAddr
);

X25519KeyUpdated

A validator updated their x25519 encryption key

event X25519KeyUpdated(address indexed validator, bytes32 x25519Key);

Parameters

NameTypeDescription
validatoraddressThe address of the validator
x25519Keybytes32The new x25519 key

P2pAddrUpdated

A validator updated their p2p address

event P2pAddrUpdated(address indexed validator, string p2pAddr);

Parameters

NameTypeDescription
validatoraddressThe address of the validator
p2pAddrstringThe new p2p address

Errors

InvalidX25519Key

The x25519 key is bytes32(0)

error InvalidX25519Key();

X25519KeyAlreadyUsed

The x25519 key has been previously registered

error X25519KeyAlreadyUsed();

InvalidP2pAddr

The p2p address validation failed

error InvalidP2pAddr();