LogoLogo
Threshold WebsitetBTC v2 DocsTACo Docs
  • What is the Threshold Network?
  • THRESHOLD DASHBOARD
    • tBTC Minting Walkthrough
  • Applications
    • tBTC Bitcoin Bridge
      • Fees
      • Wallet Generation
      • Wallet Signing
      • The Path to Permissionlessness
      • Sweeping
      • Coverage Pool
    • Threshold USD
      • Overview of thUSD
      • Borrowing
      • Stability Pool and Liquidations
      • Redemptions and thUSD Price Stability
      • Recovery Mode
      • Bootstrapping
        • Initial Protocol Loan
      • B. Protocol
      • thUSD on Build on Bitcoin (BOB)
        • Connecting to BOB Network
        • Bridging Collateral to BOB Network
        • Opening Collateral Vaults and Minting thUSD
  • Governance
    • Threshold DAO
      • 🗳️Governance Process
      • 🙋‍♀️Guilds
      • 💰Threshold Multisigs
      • Threshold DAO Rules
    • Vote Delegation
      • Liquid Token Delegation
  • Staking & Running a Node
    • tBTC v2 Node Setup
      • Operator Account
      • Application Authorization & Operator Registration
      • Network Configuration
      • Data Storage
      • Installation
        • Docker Installation
        • Binary Installation
      • Updating tBTC v2 Node
      • Advanced Options
        • Alternatives to Dashboard
        • Logging
        • Config File
        • CLI Options
        • Client Info
      • Frequently Asked Questions
      • Sepolia Testnet
        • Testnet tBTC v2 node Setup
    • tBTC Beta Stakers Program
  • App Development
    • DAO Contracts
      • DAO Contracts API
        • BaseTokenholderGovernor
        • Checkpoints
        • GovernorParameters
        • IApplication
        • ILegacyTokenStaking
        • IStaking
        • IVotesHistory
        • KeepStake
        • PercentUtils
        • ProxyAdminWithDeputy
        • SafeTUpgradeable
        • StakerGovernor
        • StakerGovernorVotes
        • T
        • TokenholderGovernor
        • TokenholderGovernorVotes
        • TokenStaking
        • VendingMachine
    • Random Beacon
      • Random Beacon API
        • AltBn128
        • BeaconAuthorization
        • BeaconDkg
        • BeaconDkgValidator
        • BeaconInactivity
        • BLS
        • BytesLib
        • Callback
        • Governable
        • Groups
        • IRandomBeacon
        • IRandomBeaconConsumer
        • ModUtils
        • RandomBeacon
        • RandomBeaconChaosnet
        • RandomBeaconGovernance
        • Reimbursable
        • ReimbursementPool
        • Relay
    • tBTC
      • tBTC SDK
        • Quickstart
        • Architecture
        • Guides
          • Initialize SDK
            • Ethereum and Bitcoin mainnet
            • Ethereum and Bitcoin testnet
            • Crosschain
            • Custom mode
          • Deposit and mint
          • Unmint and redeem
        • API Reference
      • tBTC Contracts API
        • Bridge API
          • Bank
          • BitcoinTx
          • Bridge
          • BridgeGovernance
          • BridgeGovernanceParameters
          • BridgeState
          • Deposit
          • DepositSweep
          • DonationVault
          • EcdsaLib
          • Fraud
          • GovernanceUtils
          • Heartbeat
          • IReceiveBalanceApproval
          • IRelay
          • IVault
          • L2TBTC
          • L2WormholeGateway
          • LightRelay
          • LightRelayMaintainerProxy
          • MaintainerProxy
          • MovingFunds
          • Redemption
          • TBTC
          • TBTCOptimisticMinting
          • TBTCVault
          • VendingMachine
          • VendingMachineV2
          • VendingMachineV3
          • WalletCoordinator
          • Wallets
        • ECDSA API
          • EcdsaAuthorization
          • EcdsaDkg
          • EcdsaDkgValidator
          • EcdsaInactivity
          • IWalletOwner
          • IWalletRegistry
          • WalletRegistry
          • WalletRegistryGovernance
          • Wallets
  • Resources
    • T Token
    • Contract Addresses
      • Mainnet
        • Threshold DAO
        • tBTC
        • thUSD
        • Legacy
      • Görli Testnet
      • Sepolia Testnet
    • tBTC Pools
    • Upgrade NU & KEEP to T
    • Contribution
    • Security
    • Brand Assets
    • Links
Powered by GitBook
On this page
  • Groups
  • Group
  • Data
  • GroupRegistered
  • validatePublicKey
  • addGroup
  • expireOldGroups
  • terminateGroup
  • selectGroup
  • setGroupLifetime
  • isGroupTerminated
  • groupLifetimeOf
  • isGroupActive
  • getGroup
  • getGroup
  • numberOfActiveGroups
  • shiftByExpiredGroups
  • shiftByTerminatedGroups

Was this helpful?

Export as PDF
  1. App Development
  2. Random Beacon
  3. Random Beacon API

Groups

Groups

This file documents a contract which is not yet deployed to Mainnet.

This library is used as a registry of created groups.

This library should be used along with DKG library that ensures linear groups creation (only one group creation happens at a time). A candidate group has to be popped or activated before adding a new candidate group.

Group

struct Group {
  bytes groupPubKey;
  uint256 registrationBlockNumber;
  bytes32 membersHash;
  bool terminated;
}

Data

struct Data {
  mapping(bytes32 => struct Groups.Group) groupsData;
  bytes32[] groupsRegistry;
  uint64[] activeTerminatedGroups;
  uint64 expiredGroupOffset;
  uint256 groupLifetime;
}

GroupRegistered

event GroupRegistered(uint64 groupId, bytes groupPubKey)

validatePublicKey

function validatePublicKey(struct Groups.Data self, bytes groupPubKey) internal view

Performs preliminary validation of a new group public key. The group public key must be unique and have 128 bytes in length. If the validation fails, the function reverts. This function must be called first for a public key of a group added with addGroup function.

Parameters

Name
Type
Description

self

struct Groups.Data

groupPubKey

bytes

Candidate group public key

addGroup

function addGroup(struct Groups.Data self, bytes groupPubKey, bytes32 membersHash) internal

Adds a new candidate group. The group is stored with group public key and group members, but is not yet activated.

The group members list is stored with all misbehaved members filtered out. The code calling this function should ensure that the number of candidate (not activated) groups is never more than one.

Parameters

Name
Type
Description

self

struct Groups.Data

groupPubKey

bytes

Generated candidate group public key

membersHash

bytes32

Keccak256 hash of members that actively took part in DKG.

expireOldGroups

function expireOldGroups(struct Groups.Data self) internal

Goes through groups starting from the oldest one that is still active and checks if it hasn't expired. If so, updates the information about expired groups so that all expired groups are marked as such.

terminateGroup

function terminateGroup(struct Groups.Data self, uint64 groupId) internal

Terminates group with the provided index. Reverts if the group is already terminated.

Parameters

Name
Type
Description

self

struct Groups.Data

groupId

uint64

Index in the groupRegistry array.

selectGroup

function selectGroup(struct Groups.Data self, uint256 seed) internal returns (uint64)

Returns an index of a randomly selected active group. Terminated and expired groups are not considered as active. Before new group is selected, information about expired groups is updated. At least one active group needs to be present for this function to succeed.

Parameters

Name
Type
Description

self

struct Groups.Data

seed

uint256

Random number used as a group selection seed.

setGroupLifetime

function setGroupLifetime(struct Groups.Data self, uint256 lifetime) internal

Setter for group lifetime.

Parameters

Name
Type
Description

self

struct Groups.Data

lifetime

uint256

Lifetime of a group in blocks.

isGroupTerminated

function isGroupTerminated(struct Groups.Data self, uint64 groupId) internal view returns (bool)

Checks if group with the given index is terminated.

groupLifetimeOf

function groupLifetimeOf(struct Groups.Data self, bytes32 groupPubKeyHash) internal view returns (uint256)

Gets the cutoff time until which the given group is considered to be active assuming it hasn't been terminated before.

isGroupActive

function isGroupActive(struct Groups.Data self, uint64 groupId) internal view returns (bool)

Checks if group with the given index is active and non-terminated.

getGroup

function getGroup(struct Groups.Data self, uint64 groupId) internal view returns (struct Groups.Group)

getGroup

function getGroup(struct Groups.Data self, bytes groupPubKey) internal view returns (struct Groups.Group)

numberOfActiveGroups

function numberOfActiveGroups(struct Groups.Data self) internal view returns (uint64)

Gets the number of active groups. Expired and terminated groups are not counted as active.

shiftByExpiredGroups

function shiftByExpiredGroups(struct Groups.Data self, uint64 selectedIndex) internal view returns (uint64)

Evaluates the shift of a selected group index based on the number of expired groups.

shiftByTerminatedGroups

function shiftByTerminatedGroups(struct Groups.Data self, uint64 selectedIndex) internal view returns (uint64)

Evaluates the shift of a selected group index based on the number of non-expired but terminated groups.

PreviousGovernableNextIRandomBeacon

Last updated 1 year ago

Was this helpful?