Files
aitbc/apps/zk-circuits/modular_ml_components.circom
aitbc e4f1a96172
Some checks failed
Blockchain Synchronization Verification / sync-verification (push) Failing after 8s
CLI Tests / test-cli (push) Successful in 10s
Contract Performance Benchmarks / benchmark-gas-usage (push) Successful in 1m22s
Contract Performance Benchmarks / benchmark-execution-time (push) Successful in 1m11s
Contract Performance Benchmarks / benchmark-throughput (push) Successful in 1m13s
Cross-Chain Functionality Tests / test-cross-chain-sync (push) Failing after 5s
Cross-Chain Functionality Tests / test-cross-chain-transactions (push) Successful in 5s
Cross-Chain Functionality Tests / test-cross-chain-bridge (push) Has been skipped
Cross-Chain Functionality Tests / test-multi-chain-consensus (push) Failing after 3s
Cross-Chain Functionality Tests / aggregate-results (push) Has been skipped
Cross-Node Transaction Testing / transaction-test (push) Successful in 5s
Deploy to Testnet / deploy-testnet (push) Successful in 1m14s
Contract Performance Benchmarks / compare-benchmarks (push) Has been cancelled
Documentation Validation / validate-docs (push) Failing after 10s
Multi-Node Stress Testing / stress-test (push) Has been cancelled
Node Failover Simulation / failover-test (push) Has been cancelled
Security Scanning / security-scan (push) Has been cancelled
Smart Contract Tests / test-solidity (map[name:aitbc-contracts path:contracts]) (push) Has been cancelled
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Has been cancelled
Smart Contract Tests / test-foundry (push) Has been cancelled
Smart Contract Tests / lint-solidity (push) Has been cancelled
Smart Contract Tests / deploy-contracts (push) Has been cancelled
Documentation Validation / validate-policies-strict (push) Successful in 3s
Integration Tests / test-service-integration (push) Failing after 45s
Multi-Chain Island Architecture Tests / test-multi-chain-island (push) Failing after 2s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 5s
P2P Network Verification / p2p-verification (push) Successful in 3s
Production Tests / Production Integration Tests (push) Failing after 7s
Python Tests / test-python (push) Failing after 46s
Staking Tests / test-staking-service (push) Failing after 2s
Staking Tests / test-staking-integration (push) Has been skipped
Staking Tests / test-staking-contract (push) Has been skipped
Staking Tests / run-staking-test-runner (push) Has been skipped
Systemd Sync / sync-systemd (push) Successful in 21s
API Endpoint Tests / test-api-endpoints (push) Failing after 12m19s
ci: standardize pytest invocation and add security scanning
- Changed pytest calls to use `venv/bin/python -m pytest` with explicit config
- Added `--rootdir "$PWD"` and `--import-mode=importlib` for consistent imports
- Fixed PYTHONPATH to use absolute paths with $PWD prefix
- Added smart contract security scanning for Solidity files
- Added Circom circuit security checks for ZK proof circuits
- Added ZK proof implementation security validation
- Added contracts/** to security scanning workflow
2026-05-11 13:46:42 +02:00

150 lines
4.3 KiB
Plaintext

pragma circom 2.0.0;
include "node_modules/circomlib/circuits/comparators.circom";
/*
* Modular ML Circuit Components
*
* Reusable components for machine learning circuits
*/
// Basic parameter update component (gradient descent step)
template ParameterUpdate() {
signal input current_param;
signal input gradient;
signal input learning_rate;
signal output new_param;
// Simple gradient descent: new_param = current_param - learning_rate * gradient
new_param <== current_param - learning_rate * gradient;
}
// Vector parameter update component
template VectorParameterUpdate(PARAM_COUNT) {
signal input current_params[PARAM_COUNT];
signal input gradients[PARAM_COUNT];
signal input learning_rate;
signal output new_params[PARAM_COUNT];
component updates[PARAM_COUNT];
for (var i = 0; i < PARAM_COUNT; i++) {
updates[i] = ParameterUpdate();
updates[i].current_param <== current_params[i];
updates[i].gradient <== gradients[i];
updates[i].learning_rate <== learning_rate;
new_params[i] <== updates[i].new_param;
}
}
// Simple loss constraint component
template LossConstraint() {
signal input predicted_loss;
signal input actual_loss;
signal input tolerance;
// Constrain that |predicted_loss - actual_loss| <= tolerance
signal diff;
diff <== predicted_loss - actual_loss;
// Use absolute value constraint: diff^2 <= tolerance^2
signal diff_squared;
diff_squared <== diff * diff;
signal tolerance_squared;
tolerance_squared <== tolerance * tolerance;
// This constraint ensures the loss is within tolerance
diff_squared * (1 - diff_squared / tolerance_squared) === 0;
}
// Learning rate validation component
template LearningRateValidation() {
signal input learning_rate;
// Re-implemented proper validation using efficient comparison circuits
// Ensures 0 < learning_rate < 1
component lt1 = LessThan(252);
component gt0 = GreaterThan(252);
// Ensure learning_rate < 1
lt1.in[0] <== learning_rate;
lt1.in[1] <== 1;
lt1.out === 1;
// Ensure learning_rate > 0
gt0.in[0] <== learning_rate;
gt0.in[1] <== 0;
gt0.out === 1;
}
// Training epoch component
template TrainingEpoch(PARAM_COUNT) {
signal input epoch_params[PARAM_COUNT];
signal input epoch_gradients[PARAM_COUNT];
signal input learning_rate;
signal output next_epoch_params[PARAM_COUNT];
component param_update = VectorParameterUpdate(PARAM_COUNT);
param_update.current_params <== epoch_params;
param_update.gradients <== epoch_gradients;
param_update.learning_rate <== learning_rate;
next_epoch_params <== param_update.new_params;
}
// Main modular training verification using components
template ModularTrainingVerification(PARAM_COUNT, EPOCHS) {
signal input initial_parameters[PARAM_COUNT];
signal input learning_rate;
signal output final_parameters[PARAM_COUNT];
signal output training_complete;
// Learning rate validation
component lr_validator = LearningRateValidation();
lr_validator.learning_rate <== learning_rate;
// Training epochs using modular components
signal current_params[EPOCHS + 1][PARAM_COUNT];
// Initialize
for (var i = 0; i < PARAM_COUNT; i++) {
current_params[0][i] <== initial_parameters[i];
}
// Run training epochs
component epochs[EPOCHS];
for (var e = 0; e < EPOCHS; e++) {
epochs[e] = TrainingEpoch(PARAM_COUNT);
// Input current parameters
for (var i = 0; i < PARAM_COUNT; i++) {
epochs[e].epoch_params[i] <== current_params[e][i];
}
// Use constant gradients for simplicity (would be computed in real implementation)
for (var i = 0; i < PARAM_COUNT; i++) {
epochs[e].epoch_gradients[i] <== 1; // Constant gradient
}
epochs[e].learning_rate <== learning_rate;
// Store results
for (var i = 0; i < PARAM_COUNT; i++) {
current_params[e + 1][i] <== epochs[e].next_epoch_params[i];
}
}
// Output final parameters
for (var i = 0; i < PARAM_COUNT; i++) {
final_parameters[i] <== current_params[EPOCHS][i];
}
training_complete <== 1;
}
component main = ModularTrainingVerification(4, 3);