Threshold Security (EVM)
This example demonstrates a simple threshold-weighted verification service (BVS) where multiple operators submit a computed result (square of a number). A request is finalized only when the total USD AUM (Assets Under Management) of the operators that agreed on the same result meets a configured threshold.
Key ideas
- Weighted consensus by AUM: Each operator’s vote is weighted by their AUM in USD using
SLAYOracle
. - Finalization threshold: Only when the sum of AUM for the same output reaches the threshold does the request finalize.
- Relationship-gated responses: Only operators with an active relationship to the service can respond.
read more about SLAYOracle
.
Structure
src/BVS.sol
: Core contract maintained by the Service (owner) implementing request/response, AUM weighting via SLAYOracle, and threshold finalization.src/operatorNode.ts
: Minimal Operator node that listens forRequested
and callsrespond
with the square.src/lifecycle.test.ts
: End-to-end lifecycle test that is meant to showcase the flow of threshold security.
How it works (flow)
If you prefer reading code, look at src/lifecycle.test.ts
.
Setups
- The Service deploys
BVS.sol
and register it as a service on the SatLayer Registry. - The Operators register as operators on the SatLayer Registry.
- The Operators creates a Vault.
- The Service enables slashing on the Registry.
- The Service and Operators establish active relationships on the Registry.
Core flow
- The Service requests a work (number to be squared) to the contract through
request(num)
and emitsRequested
. - The Operators listen to
Requested
and respond withrespond(requestId, num*num)
. - For each response, the contract records the response and the operator’s AUM in USD through
SLAYOracle
. - Anyone can call
finalize(requestId, output)
once the response has hit the threshold.
Run the example
- Install dependencies:
pnpm install
- Build:
pnpm build
- Test:
pnpm test
to run thelifecycle.test.ts
Notes
- Slashing:
enableSlashing
wires the service to registry-managed slashing. This example shows the setup; the challenge flow is outside the scope of this sample. - Prices and AUM: In the test, vault deposits and oracle prices together determine operators’ AUM in USD, which the SLAYOracle exposes to the BVS.
- The prices in the test are fixed but in reality, prices fluctuate over time. It might be a good idea to expect responses from Operator within a certain timeframe.
Last updated on