FLOCK 백서

FLOCK

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 16쪽 중 3쪽

steps [here](https://docs.flock.io/flock-products/ai-arena/pages/628PqLScceINNZRrYVWa#step-0-go-to-https-train.flock.io-stake-to-earn-and-connect-your-wallet) to connect your wallet.\ (During the migration phase, we would use `train-v2.flock.io` for V2, and will maintain `train.flock.io` for sometime so that everyone can claim and unstake from V1 easily. After the migration phase, we would re-direct all traffic to `train.flock.io` and it will be upgraded to V2.) ### Step 1: Stake FLOCK to get gmFLOCK Here, you decide the amount of FLOCK you want to stake to get gmFLOCK and the duration of the stake {% hint style="info" %} For every 1 FLOCK staked, you will receive 1 gmFLOCK for staking between 0-30 days. For each additional day before that, you will receive an extra 0.006 gmFLOCK {% endhint %} {% hint style="info" %} NOTE: You will receive gmFLOCK as soon as you stake FLOCK. Once the staking period is reached, you may withdraw your staked FLOCK with a transaction fee of 5.13%. The fee remains the same irrespective of the duration of the stake {% endhint %} <figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2F1p7eoIPEvE2YB9X4vF8C%2Fimage.png?alt=media&amp;token=9b65406b-efbd-4ac5-9401-4f34d981fddb" alt=""><figcaption><p>Step 1.1: Decide the amount of FLOCK to stake and the stake period</p></figcaption></figure> After that, click on "Stake", approve the transaction in the wallet and you've successfully staked FLOCK for gmFLOCK. #### Formulae for exchanging FLOCK with gmFLOCK If a user deposits $$n$$ FLOCK into the gmFLOCK Faucet and chooses a vesting time of $$t$$ days $$(0< t \le t\_1)$$to unlock the tokens, then the number of gmFLOCK minted, $$m$$, is: * if $$0< t \le t\_0$$: $$m=n$$ * if $$t\_0< t \le t\_1$$: $$m = n \times (1+ \epsilon \times \frac{t-t\_0}{t\_1})$$ where $$t$$, $$t\_0$$ and $$\epsilon$$ are the parameters that can be configured by FLOCK DAO. today, $$t\_0=30 days, t\_1=365 days, \epsilon=2.19$$ You can see all your stakes under "My Staking History" <figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FkzlvVKoK6r7np2jgmLhz%2Fimage.png?alt=media&amp;token=8ed136f0-d1f0-4805-9850-40e4d4dd6b32" alt=""><figcaption><p>1.2 You can see all your stakes</p></figcaption></figure> ### Step 2: Use gmFLOCK&#x20; Now that you have gmFLOCK by staking FLOCK, you can use it to stake as a [Delegator](/flock-tokenomics/network-participation/ai-arena/delegator), [Validator](/flock-products/ai-arena/quickstart/validator-guide) or a [Training Node ](/flock-products/ai-arena/quickstart/training-node-guide) ### Step 3: Redeem FLOCK After the stake period has ended, you can choose to exchange gmFLOCK for FLOCK. Click on "Redeem" under My Staking History {% hint style="info" %} NOTE: The amount of FLOCK you receive upon redemption is equal to your original staked FLOCK, minus a fixed 5.13% transaction fee. The redemption amount is not affected by the staking duration or the amount of gmFLOCK minted. {% endhint %} <figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FF3nAFNvdwbD6EDjvfh6D%2Fimage.png?alt=media&amp;token=dd63cdaf-ac5c-4910-862f-fa04d52de6bf" alt=""><figcaption><p>Step 3.1: You can see the Stakes which are avaialble to Redeem</p></figcaption></figure> <figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FoCGMGxkQTAMRZ6coknZh%2Fimage.png?alt=media&amp;token=f309bca0-cc29-4869-8951-3a668154e623" alt=""><figcaption></figcaption></figure> Select all the stakes that you would like to redeem and click on "Redeem".&#x20; At this stage, you've successfully exchanged gmFLOCK for FLOCK! # Task Lifecycle Deep-dive This section offers a deep-dive into a cycle of an AI Arena Task. <figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FcUILw5P8yTjd5Gykj3mc%2Fai-arena-fig3.png?alt=media&amp;token=661a74b7-368a-480d-8ebf-1634f5342afd" alt=""><figcaption><p>Figure3. Workflow of an AI Arena Task.</p></figcaption></figure> ## 1. Task Creation Task creation is the primary stage of the training cycle. Task creators define the desired models and submit tasks to the platform.&#x20; To qualify as a task creator, users must meet one or more of the following criteria:&#x20; • Stake a sufficient amount of FLOCK • Have successfully trained or validated a task previously, as evidenced by on-chain records • Possess a reputation in the ML space or be recognised as a domain expert in relevant fields, as verified by the FLock community ## 2. Training Node and Validator Selection Each participant is required to stake in order to participate either as a training node or a validator. Also, rate limiting is adopted to determine the number of times participants can be eligible as validator for a given task. Essentially, the likelihood of a participant being selected to validate a task submission increases with their stake. However, the rate at which validation frequency increases relative to the staking amount tends to diminish as the staking amount grows. ## 3. Training&#x20; Each training node is given $$\mathcal{D}{\text{local}}$$*, which contains locally sourced data samples, comprising feature set* $$X$$ *and label set* $$Y$$*, with each sample* $$x\_i \in X$$ *corresponding to a label* $$y\_i \in Y$$*. The goal of training is to define a predictive model* $$f$$*, which learns patterns within* $$\mathcal{D}{\text{local}}$$ such that $$f(x\_i) \approx y\_i$$.&#x20; To quantify the success (i.e. ability to predict) of the predictive model $$f$$, we introduce a loss function $$L(f(x\_i), y\_i)$$, assessing the discrepancy between predictions $$f(x\_i)$$ and actual labels $$f(y\_i)$$. A generic expression for this function is: $$\begin{equation\*} L = \frac{1}{N} \sum\_{i=1}^{N} l(f(x\_i), y\_i) \end{equation\*}$$ where $$N$$ denotes the total sample count, and $$l$$ signifies a problem-specific loss function, e.g., mean squared error or cross-entropy loss. Ultimately, the optimisation goal of training is to adjust the model parameters $$\theta$$ to minimise $$L$$, typically through algorithms such as gradient descent.&#x20; ## 4. Validation&#x20; After the training node produces a trained model $$\theta^{task}*p$$, a selected group of validators, denoted as $$V\_j \in V$$, each equipped with the evaluation dataset $$\mathcal{D}*{\text{eval}}$$ from the task creator, will validate the model. The dataset consists of pairs $$(x\_i, y\_i)$$, where $$x\_i$$ represents the features of the $$i-th$$ sample, and $$y\_i$$is the corresponding true label. To assess the performance of the trained model, we use an general evaluation, which is calculated as follows: $$ \begin{equation\*} eval(\theta^{task}p, \mathcal{D}{\text{eval}}) = \frac{1}{|\mathcal{D}{\text{eval}}|} \sum{(x\_i, y\_i) \in \mathcal{D}\_{\text{eval}}} \mathbf{1}(\hat{y}\_i = y\_i) \end{equation\*} $$ Here, $$\mathbf{1}$$ represents the indicator function that returns 1 if the predicted label $$\hat{y}i$$ *matches the true label* $$y\_i$$*, and* $$0$$ *otherwise. The function* $$|\mathcal{D}{\text{eval}}|$$ denotes the total number of samples within the evaluation dataset. Each predicted label $$\hat{y}\_i$$ from the model $$\theta^{task}p$$ *is compared against its corresponding true label* $$y\_i$$ *within the dataset* $$\mathcal{D}{\text{eval}}$$. The calculated metric result (accuracy here) serves as a quantifiable measure of $$\theta^{task}\_p$$'s effectiveness at label prediction across the evaluation dataset. # Smart Contracts Deep-dive This page gives detailed explanation of AI Arena's smart contracts. <figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2Fo3etsLwrTv4IKYydG4GM%2FAI_Arena.png?alt=media&amp;token=ac95c238-6a05-4534-80d0-95f682c4602c" alt=""><figcaption><p>AI Arena Smart Contracts Interactions.</p></figcaption></figure> ## **Protocol Fee Model** Within the reward-distribution flow, the protocol applies a fee when users claim rewards denominated in **FLOCK**. This fee helps sustain ongoing network operations, security, and ecosystem development. The fee model distinguishes between two major participant groups to reflect their different roles in the protocol: * **Training Nodes & Validators:**\ Claims incur an **8% protocol fee**. * **Delegators:**\ Claims incur a **14.5% protocol fee**. ## Core Contracts ### `AdminUpgradeable.sol` **Role**: Base class that provides admin rights and other access-related methods. * Inherits `AccessControlUpgradeable` from OpenZeppelin. * Exposes `onlyAdmin` modifier and `isAdmin` checks. * Allows flexible role management for upgradeable contracts. ### `FlockMiniPool.sol` **Role**: Represents a “mini pool” that supports user delegation, tracks delegations, calculates claimable rewards, and interacts with the protocol’s managers. * Uses mappings to track each delegator’s stake, claims, temporal stakes, etc. * Integrates with `FlockConfig` for config references, calls back into `FlockPoolManager` and `FlockMainManager`. ### `FlockPoolManagerUpgradeable.sol` **Role**: Manages the creation and configuration of `FlockMiniPool` instances. * Tracks all active pools in sets, plus each user’s associated mini pool. * Maintains system-wide parameters (e.g., min/max Sigma, protocol fees). * Acts as a factory for creating new mini pools: `createMiniPool(...)`. * Handles callbacks to update delegations in a user’s mini pool. ### `FlockStakeInfoUpgradeable.sol` **Role**: Central ledger for all stakes across tasks. * Maintains stake amounts, weights, and distribution logic for nodes, validators, and delegators. * Relies on `FlockConfig` references to connect to other managers (e.g. main manager, pool manager). * Example responsibilities include: * `addStakes()` / `removeStakes()`: Called by the main manager to adjust totals. * `taskStakes[]`, `taskWeights[]`: Summaries for each task’s stake distribution. * “Re-tallying” delegations to keep stake info up to date. ### `FlockTaskManagerUpgradeable.sol` **Role**: Orchestrates tasks in the system. * Maintains references to each task (node stakes, validator stakes, distributions). * Aggregates daily minted rewards from `FlockToken`, then calculates how to distribute among nodes, validators, and delegators. * Offers hooks like `afterDelegationUpdate(...)` so that the pool manager can re-tally the user’s delegation. ### `FlockTokenUpgradeable.sol` **Role**: The upgradeable ERC20 for the entire protocol. * Allows “mint” and “burn” operations. * Implements a blacklist mechanism to restrict malicious actors. * Has “admin” only calls for minting, daily mint limits, etc. * Used as the currency for all staking, delegation, and reward flows. ## Libraries ### `LibABDKMathQuad.sol` **Role**: Quadruple-precision (128-bit) floating-point math. * Based on the [ABDK Consulting library](https://github.com/abdk-consulting/abdk-libraries-solidity), enabling IEEE 754-compatible operations with 16-byte `bytes16` floats. * Key functionalities include: * Converting between `int256`/`uint256` and quad precision. * Arithmetic ops (`add`, `sub`, `mul`, `div`). * Logarithms, exponentiation, square roots. * Used when standard fixed-point or 256-bit integer math is insufficient for advanced computations (such as extremely precise reward calculations). ### `LibFlockTask.sol` **Role**: Utility library for certain math and pseudo-randomness within tasks. * Wraps `LibABDKMathQuad` logic for simpler usage in multiplication/division scenarios. * Provides a “random” function (`rand()`), which generates a random number using block/transaction properties. ### `LibMath.sol` **Role**: Additional numeric utilities, focusing on n-th root calculations. * Provides the function `nthRoot()` which approximates the n-th root of a given number. * Useful for advanced arithmetic or reward distribution models needing, for example, “square root” or other root-based weighting logic. # FL Alliance A guide to FLock's federated learning client. <figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FcaSeQSRTKBDvufyQAT3f%2F1313.png?alt=media&amp;token=281506a9-d3fc-45cd-8d4a-4ef81357b888" alt=""><figcaption><p>Overview of FL Alliance </p></figcaption></figure> After AI Arena has optimised the model parameters, they are further refined in FL Alliance with proprietary data. Following our research paper published at IEEE Transactions on Artificial Intelligence (see <https://ieeexplore.ieee.org/abstract/document/10471193>), we provide a robust incentive mechanism incentivise honest behaviours and penalise malicious behaviours of FL participants. The motivation behind this FL Alliance system is to create a decentralised and secure environment for federated learning. By using random functions to allocate roles and a staking mechanism to ensure commitment, the system promotes trust and reliability among participants. The slash and reward mechanism further incentivises honest behaviour, ensuring the collaborative effort results in a high-quality global model. # Participants This sub-section introduces various participants in the FL alliance and their respective roles and workflow. ## 1. Task Creator * Stakes and creates a FL task * Specifies the basic information of a FL task, such as the number of minimum participants, the expected number of rounds, and the initial reward amount in the pool ## 2. FL Nodes FL nodes are participants in a decentralised learning system where multiple entities collaboratively train a shared machine learning model without exchanging their local data. These nodes can be any devices or servers contributing computational resources and data to the training process. FL nodes play critical roles in ensuring the integrity and efficiency of the FL Alliance working process. They are randomly allocated the roles of proposers and voters with the goal of avoiding collusion and other malicious behaviours. By distributing these roles randomly, the system ensures a fair and unbiased approach to model training and evaluation. Specifically, developers join as FL nodes to collaboratively train a global model while using their local data and computing power. They are randomly allocated the following roles: * **Proposers:** Responsible for performing local training using their own data and proposing updates to the global model. * **Voters:** Responsible for aggregating local model updates, evaluating the global model, and casting votes to either support or oppose the proposed updates. # Components This sub-section introduces the three components comprising our FL Alliance. ## 1. FLocKit * Encapsulates task-specific training logic * Offers predefined templates for various tasks, such as LLM fine-tuning, time series prediction, and more * Provides an effortless way to create a federated learning (FL) task (for instance, to create a LLM finetuning FL task, users only need to specify the target model they want to fine-tune in the configuration file, without requiring any changes to the source code) ## 2. FL Client FL Client serves as both an organiser and an orchestrator, facilitating the interaction between smart contracts and federated learning (FL) training tasks. It also manages all necessary system-level environments, ensuring seamless operation and coordination throughout the process. Specifically, FL Client: * Interacts with smart contracts * Allows proposers to train their local models using their own local data * Allows voters to submit scores based on the performance of the proposers * Aggregates scores submitted by voters ## 3. Smart Contracts * Assigns roles to participants randomly * Allows participants to stake and withdraw rewards * Slashes malicious behaviours&#x20; # Task Lifecycle Deep-dive This section gives an in-depth explanation of our FL Alliance. <figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FJNqPRC85RMx76g1bPuQu%2FFL-workflow.png?alt=media&amp;token=ca513599-d434-4d84-9ca8-b0c0d090bcbb" alt=""><figcaption><p>Overview of the workflow of a FLock FL task.</p></figcaption></figure> FLock's FL Alliance is adopted from our [previous work](https://arxiv.org/pdf/2307.00543). During each round, FL clients are randomly selected to act as proposers or voters. Their staked amount can be either rewarded or slashed based on the outcome of the majority voting results. Malicious clients will ultimately be removed from the FL system. # 1. Staking and Role Assignment FLock adopts a distributed voting and a reward-and-slash mechanism to construct secure FL Alliance systems. To participate in the training process, each participant is required to stake a specified quantity of $FLOCK. For each FL Alliance task within the ecosystem, rewards are initially secured by transferring them to the respective FL smart contract, provided the task is still in progress and has not surpassed its maximum allotted lifecycle. This preliminary step ensures that the rewards are earmarked and protected for participants actively engaged in the task. Subsequently, upon meeting these conditions, the FL smart contract autonomously distributes the rewards to the participants, according to their contributions. An FL Alliance task should be derived from a finished AI Arena task. The initiation of an FL task automatically triggers the creation of a new FL contract. The reward for the FL task is determined based on the total reward allocated to the corresponding AI Arena version. Task specific training logic is being uploaded to an off-chain storage platform and encapsulated in a hash. This hash is being used when an instance of the FL Task is being instantiated. Here, training logic refers to specific requirements in relation to the given FL task, such as parameters, epochs of training etc.&#x20; Upon formally joining the training task, each participant’s local dataset is randomly partitioned into a training set and a test set, which will not be shared with other participants at any time. At the beginning of each round in the FL Alliance task, participants are randomly assigned roles as either a proposer or a voter. The random selection of roles for participants is conducted on-chain. A model initialised by one of the proposers is chosen at random temporarily to serve as the pioneering global model. The selected model’s weights or gradients are then distributed to all participants, ensuring a unified starting point for local models. Proposers are responsible for training their local models using their own data and subsequently sharing the updated model weights or gradients with all participants. Voters, on the other hand, aggregate these updates from proposers. They then proceed to validate the aggregated model updates, resulting in the generation of a validation score. # 2. FL Training At the start of each round, proposers initially download the global model, which was finalised in the previous round. Using the proposer’s own local training dataset, proposers then proceed to update the model through local training, and upload the updated model to voters for evaluation. # 3. FL Aggregation and Evaluation Then, each voter gathers the local models from all proposers. These models are then aggregated into the latest global model using a weighted averaging approach. Each voter then proceeds to evaluate the aggregated model, utilising their own local testing datasets. This evaluation phase involves the computation of a l
프로젝트로 돌아가기