Eth Account Strategy#
- exception rizemind.authentication.eth_account_strategy.CannotRecoverSignerException[source]
Bases:
RizemindExceptionThe signer of a model update could not be recovered.
- exception rizemind.authentication.eth_account_strategy.CannotTrainException(address: str)[source]
Bases:
RizemindExceptionAn attempt was made to train with an unauthorized address.
- class rizemind.authentication.eth_account_strategy.EthAccountStrategy(strat: Strategy, swarm: SupportsEthAccountStrategy, account: BaseAccount)[source]
Bases:
StrategyA federated learning strategy that verifies model authenticity.
This strategy wraps an existing Flower Strategy to ensure that only authorized clients can contribute training updates. It verifies cryptographic signatures against a blockchain-based model registry. If a client is not authorized, it is added to the failures list with a CannotTrainException.
- strat
The base Flower Strategy to wrap.
- Type:
flwr.server.strategy.strategy.Strategy
- swarm
The blockchain-based model registry.
- Type:
rizemind.authentication.typing.SupportsEthAccountStrategy
- address
The contract address of the swarm.
- Type:
str
- account
The Ethereum account used for signing.
- Type:
eth_account.signers.base.BaseAccount
- Example Usage:
strategy = SomeBaseStrategy()
model_registry = SwarmV1.from_address(address=”0xMY_MODEL_ADDRESS”)
eth_strategy = EthAccountStrategy(strategy, model_registry)
- account: BaseAccount
- address: str
- aggregate_evaluate(server_round, results, failures)[source]
Aggregate evaluation results by delegating to the wrapped strategy.
- Parameters:
server_round – The current server round.
results – A list of tuples (ClientProxy, EvaluateRes) received from clients.
failures – A list of failures encountered during evaluation.
- Returns:
The aggregated evaluation result as returned by the wrapped strategy’s aggregate_evaluate.
- aggregate_fit(server_round, results, failures)[source]
Aggregate fit results from authorized clients only.
Recovers the signer address from each client’s fit result, tags the client with the recovered address, and filters out contributions from non-authorized addresses. Unauthorized attempts are recorded as failures. Delegates final aggregation to the wrapped strategy.
- Parameters:
server_round – The current server round.
results – A list of tuples (ClientProxy, FitRes) received from clients.
failures – A list that will be extended with failures that occur during processing.
- Returns:
The aggregated result as returned by the wrapped strategy’s aggregate_fit.
- configure_evaluate(server_round, parameters, client_manager)[source]
Prepare evaluation instructions using authenticated client manager.
Wraps the base strategy’s configure_evaluate with AuthenticatedClientManager and delegates to the wrapped strategy.
- Parameters:
server_round – The current server round.
parameters – The global model parameters to send to clients.
client_manager – The Flower client manager.
- Returns:
The list of client evaluation instructions produced by the wrapped strategy.
- configure_fit(server_round, parameters, client_manager)[source]
Prepare fit instructions and attach notary metadata.
Wraps the base strategy’s configure_fit to use AuthenticatedClientManager and appends a signed notary payload to each client’s config so that clients can sign their updates.
- Parameters:
server_round – The current server round.
parameters – The global model parameters to send to clients.
client_manager – The Flower client manager.
- Returns:
The list of client instructions produced by the wrapped strategy with notary metadata attached to each instruction’s config.
- evaluate(server_round, parameters)[source]
Evaluate the current global model via the wrapped strategy.
- Parameters:
server_round – The current server round.
parameters – The global model parameters to evaluate.
- Returns:
The evaluation result as returned by the wrapped strategy’s evaluate.
- initialize_parameters(client_manager)[source]
Initializes model parameters.
- strat: Strategy
- swarm: SupportsEthAccountStrategy