#include #include "problem.h" #include "attack.h" using namespace std; static bool cacheinit = 0; static problem Ecached; static vector Pcached; static vector pub; int attack_handle(const problem &E,const vector &P,const attack &A,const vector &Q) { bigint maxcost = 1073741824; selection_constrain(attack_selection,"maxcost",maxcost,maxcost); bigint predictedcost = A.cost(P,Q); cout << "circuitcost"; cout << " problem=" << E.name; for (bigint j = 0;j < P.size();++j) cout << (j ? ',' : ' ') << E.paramnames.at(j) << "=" << P.at(j); cout << " attack="; cout << A.name; for (bigint j = 0;j < Q.size();++j) cout << (j ? ',' : ' ') << A.paramnames.at(j) << "=" << Q.at(j); cout << " prediction " << predictedcost; if (predictedcost > maxcost) { cout << " skipping\n" << flush; return 1; } if (cacheinit) { if (E.psgen != Ecached.psgen) cacheinit = 0; if (E.paramnames != Ecached.paramnames) cacheinit = 0; if (P != Pcached) cacheinit = 0; } if (!cacheinit) { Ecached = E; Pcached = P; pub = E.psgen(P).first; cacheinit = 1; } vector pubbit; for (bigint j = 0;j < pub.size();++j) pubbit.push_back(bit(pub.at(j))); vector Pbigint; for (bigint j = 0;j < P.size();++j) Pbigint.push_back((bigint) (P.at(j))); vector Qbigint; for (bigint j = 0;j < Q.size();++j) Qbigint.push_back((bigint) (Q.at(j))); bit::clear_all(); vector attackoutput = A.circuit(pubbit,Pbigint,Qbigint); bigint cost = bit::ops(); for (auto i: bit_ops_selectors) cout << " " << bit::opsname(i) << " " << bit::ops(i); if (cost != predictedcost) cout << " ALERT"; cout << '\n' << flush; return 1; }