- Added support for more intelligent bounding. Fairly untested at the
moment.
This commit is contained in:
parent
c20810def5
commit
c4628e8be6
@ -33,6 +33,7 @@
|
|||||||
#include "type.h"
|
#include "type.h"
|
||||||
#include "switches.h"
|
#include "switches.h"
|
||||||
#include "specialterm.h"
|
#include "specialterm.h"
|
||||||
|
#include "cost.h"
|
||||||
|
|
||||||
extern int *graph;
|
extern int *graph;
|
||||||
extern int nodes;
|
extern int nodes;
|
||||||
@ -40,6 +41,7 @@ extern int graph_uordblks;
|
|||||||
|
|
||||||
static System sys;
|
static System sys;
|
||||||
static int attack_length;
|
static int attack_length;
|
||||||
|
static int attack_leastcost;
|
||||||
|
|
||||||
Protocol INTRUDER; // Pointers, to be set by the Init
|
Protocol INTRUDER; // Pointers, to be set by the Init
|
||||||
Role I_M; // Same here.
|
Role I_M; // Same here.
|
||||||
@ -3194,14 +3196,25 @@ prune_bounds ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Limit on exceeding any attack length
|
// Limit on exceeding any attack length
|
||||||
if (switches.prune == 2 && get_semitrace_length () >= attack_length)
|
if (get_semitrace_length () >= attack_length)
|
||||||
{
|
{
|
||||||
|
if (switches.output == PROOF)
|
||||||
|
{
|
||||||
|
indentPrint ();
|
||||||
|
eprintf ("Pruned: attack length %i.\n", attack_length);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* prune for cheaper */
|
||||||
|
if (switches.prune == 2 && attack_leastcost <= attackCost (sys))
|
||||||
|
{
|
||||||
|
// We already had an attack at least this cheap.
|
||||||
if (switches.output == PROOF)
|
if (switches.output == PROOF)
|
||||||
{
|
{
|
||||||
indentPrint ();
|
indentPrint ();
|
||||||
eprintf
|
eprintf
|
||||||
("Pruned: we already know an attack of length %i.\n",
|
("Pruned: attack cost exceeds a previously found attack.\n");
|
||||||
attack_length);
|
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -3584,7 +3597,7 @@ int
|
|||||||
property_check ()
|
property_check ()
|
||||||
{
|
{
|
||||||
int flag;
|
int flag;
|
||||||
int attack_this;
|
int cost;
|
||||||
|
|
||||||
flag = 1;
|
flag = 1;
|
||||||
|
|
||||||
@ -3600,17 +3613,16 @@ property_check ()
|
|||||||
{
|
{
|
||||||
arachneOutputAttack ();
|
arachneOutputAttack ();
|
||||||
}
|
}
|
||||||
// Store attack length if shorter
|
// Store attack cost if cheaper
|
||||||
attack_this = get_semitrace_length ();
|
cost = attackCost (sys);
|
||||||
if (attack_this < attack_length)
|
if (cost < attack_leastcost)
|
||||||
{
|
{
|
||||||
// Shortest attack
|
// Cheapest attack
|
||||||
attack_length = attack_this;
|
attack_leastcost = cost;
|
||||||
if (switches.output == PROOF)
|
if (switches.output == PROOF)
|
||||||
{
|
{
|
||||||
indentPrint ();
|
indentPrint ();
|
||||||
eprintf ("New shortest attack found with trace length %i.\n",
|
eprintf ("New cheaper attack found with cost %i.\n", cost);
|
||||||
attack_length);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3855,6 +3867,7 @@ arachne ()
|
|||||||
|
|
||||||
sys->current_claim = cl;
|
sys->current_claim = cl;
|
||||||
attack_length = INT_MAX;
|
attack_length = INT_MAX;
|
||||||
|
attack_leastcost = INT_MAX;
|
||||||
cl->complete = 1;
|
cl->complete = 1;
|
||||||
p = (Protocol) cl->protocol;
|
p = (Protocol) cl->protocol;
|
||||||
r = (Role) cl->role;
|
r = (Role) cl->role;
|
||||||
|
90
src/cost.c
Normal file
90
src/cost.c
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*@file cost.c
|
||||||
|
*
|
||||||
|
* Determine cost of a given semitrace in sys
|
||||||
|
* Constructed for Arachne results, unreliable otherwise.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "switches.h"
|
||||||
|
|
||||||
|
//************************************************************************
|
||||||
|
// Private methods
|
||||||
|
//************************************************************************
|
||||||
|
|
||||||
|
int selfInitiator(const System sys, const int run)
|
||||||
|
{
|
||||||
|
int self_initiator;
|
||||||
|
|
||||||
|
self_initiator = false;
|
||||||
|
if (sys->runs[run].role->initiator)
|
||||||
|
{
|
||||||
|
// An initiator
|
||||||
|
Termlist agents;
|
||||||
|
Termlist seen;
|
||||||
|
|
||||||
|
agents = sys->runs[run].agents;
|
||||||
|
seen = NULL;
|
||||||
|
while (agents != NULL)
|
||||||
|
{
|
||||||
|
Term agent;
|
||||||
|
|
||||||
|
agent = agents->term;
|
||||||
|
if (inTermlist (seen, agent))
|
||||||
|
{
|
||||||
|
// This agent was already in the seen list
|
||||||
|
self_initiator = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
termlistAdd (seen, agent);
|
||||||
|
}
|
||||||
|
agents = agents->next;
|
||||||
|
}
|
||||||
|
termlistDelete (seen);
|
||||||
|
}
|
||||||
|
return self_initiator;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Count the number of any self-initiators
|
||||||
|
int selfInitiators(const System sys)
|
||||||
|
{
|
||||||
|
int count;
|
||||||
|
int run;
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
run = 0;
|
||||||
|
while (run < sys->maxruns)
|
||||||
|
{
|
||||||
|
if (selfInitiator (sys, run))
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
run++;
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
//************************************************************************
|
||||||
|
// Public methods
|
||||||
|
//************************************************************************
|
||||||
|
|
||||||
|
//! Determine cost of an attack
|
||||||
|
/*
|
||||||
|
* This should also work on uncompleted semitraces, and should be monotonous
|
||||||
|
* (i.e. further iterations should increase the cost only) so that it can be
|
||||||
|
* used for branch and bound.
|
||||||
|
*
|
||||||
|
* A lower value (closer to 0) is a more feasible attack.
|
||||||
|
*/
|
||||||
|
int attackCost(const System sys)
|
||||||
|
{
|
||||||
|
int cost;
|
||||||
|
|
||||||
|
cost = 0;
|
||||||
|
|
||||||
|
cost += get_semitrace_length();
|
||||||
|
cost += 5 * selfInitiators(sys);
|
||||||
|
|
||||||
|
return cost;
|
||||||
|
}
|
6
src/cost.h
Normal file
6
src/cost.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef COST
|
||||||
|
#define COST
|
||||||
|
|
||||||
|
int attackCost(const System sys);
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user