- Made a start with the arachne latex output. It's a mess currently.
This commit is contained in:
parent
56b083205a
commit
197117f2fe
455
src/arachne.c
455
src/arachne.c
@ -682,7 +682,337 @@ bind_new_run (const Binding b, const Protocol p, const Role r,
|
|||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! Iterate over all events that have an incoming arrow to the current one (forgetting the intruder for a moment)
|
||||||
|
void
|
||||||
|
iterate_incoming_arrows (void (*func) (), const int run, const int ev)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine wheter to draw an incoming arrow to this event.
|
||||||
|
* We check all other runs, to see if they are ordered.
|
||||||
|
*/
|
||||||
|
int run2;
|
||||||
|
|
||||||
|
run2 = 0;
|
||||||
|
while (run2 < sys->maxruns)
|
||||||
|
{
|
||||||
|
if (run2 != run && sys->runs[run2].protocol != INTRUDER)
|
||||||
|
{
|
||||||
|
// Is this run before the event?
|
||||||
|
int ev2;
|
||||||
|
int found;
|
||||||
|
|
||||||
|
found = 0;
|
||||||
|
ev2 = sys->runs[run2].length;
|
||||||
|
while (found == 0 && ev2 > 0)
|
||||||
|
{
|
||||||
|
ev2--;
|
||||||
|
if (graph[graph_nodes (nodes, run2, ev2, run, ev)] != 0)
|
||||||
|
{
|
||||||
|
found = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found == 1)
|
||||||
|
{
|
||||||
|
// It is before the event, and thus we would like to draw it.
|
||||||
|
// However, if there is another path along which we can get here, forget it
|
||||||
|
/**
|
||||||
|
* Note that this algorithm is similar to Floyd's algorithm for all shortest paths.
|
||||||
|
* The goal here is to select only the path with distance 1 (as viewed from the regular runs),
|
||||||
|
* so we can simplify stuff a bit.
|
||||||
|
* Nevertheless, using Floyd first would probably be faster.
|
||||||
|
*/
|
||||||
|
int other_route;
|
||||||
|
int run3;
|
||||||
|
int ev3;
|
||||||
|
|
||||||
|
other_route = 0;
|
||||||
|
run3 = 0;
|
||||||
|
ev3 = 0;
|
||||||
|
while (other_route == 0 && run3 < sys->maxruns)
|
||||||
|
{
|
||||||
|
if (sys->runs[run3].protocol != INTRUDER)
|
||||||
|
{
|
||||||
|
ev3 = 0;
|
||||||
|
while (other_route == 0 && ev3 < sys->runs[run3].length)
|
||||||
|
{
|
||||||
|
if (graph
|
||||||
|
[graph_nodes
|
||||||
|
(nodes, run2, ev2, run3, ev3)] != 0
|
||||||
|
&&
|
||||||
|
graph[graph_nodes
|
||||||
|
(nodes, run3, ev3, run, ev)] != 0)
|
||||||
|
{
|
||||||
|
// other route found
|
||||||
|
other_route = 1;
|
||||||
|
}
|
||||||
|
ev3++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
run3++;
|
||||||
|
}
|
||||||
|
if (other_route == 0)
|
||||||
|
{
|
||||||
|
func (run2, ev2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
run2++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Iterate over all events that have an outgoing arrow from the current one (forgetting the intruder for a moment)
|
||||||
|
void
|
||||||
|
iterate_outgoing_arrows (void (*func) (), const int run, const int ev)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine wheter to draw an incoming arrow to this event.
|
||||||
|
* We check all other runs, to see if they are ordered.
|
||||||
|
*/
|
||||||
|
int run2;
|
||||||
|
|
||||||
|
run2 = 0;
|
||||||
|
while (run2 < sys->maxruns)
|
||||||
|
{
|
||||||
|
if (run2 != run && sys->runs[run2].protocol != INTRUDER)
|
||||||
|
{
|
||||||
|
// Is this run after the event?
|
||||||
|
int ev2;
|
||||||
|
int found;
|
||||||
|
|
||||||
|
found = 0;
|
||||||
|
ev2 = 0;
|
||||||
|
while (found == 0 && ev2 < sys->runs[run2].length)
|
||||||
|
{
|
||||||
|
if (graph[graph_nodes (nodes, run, ev, run2, ev2)] != 0)
|
||||||
|
{
|
||||||
|
found = 1;
|
||||||
|
}
|
||||||
|
ev2++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found == 1)
|
||||||
|
{
|
||||||
|
// It is after the event, and thus we would like to draw it.
|
||||||
|
// However, if there is another path along which we can get there, forget it
|
||||||
|
/**
|
||||||
|
* Note that this algorithm is similar to Floyd's algorithm for all shortest paths.
|
||||||
|
* The goal here is to select only the path with distance 1 (as viewed from the regular runs),
|
||||||
|
* so we can simplify stuff a bit.
|
||||||
|
* Nevertheless, using Floyd first would probably be faster.
|
||||||
|
*/
|
||||||
|
int other_route;
|
||||||
|
int run3;
|
||||||
|
int ev3;
|
||||||
|
|
||||||
|
other_route = 0;
|
||||||
|
run3 = 0;
|
||||||
|
ev3 = 0;
|
||||||
|
while (other_route == 0 && run3 < sys->maxruns)
|
||||||
|
{
|
||||||
|
if (sys->runs[run3].protocol != INTRUDER)
|
||||||
|
{
|
||||||
|
ev3 = 0;
|
||||||
|
while (other_route == 0 && ev3 < sys->runs[run3].length)
|
||||||
|
{
|
||||||
|
if (graph
|
||||||
|
[graph_nodes
|
||||||
|
(nodes, run, ev, run3, ev3)] != 0
|
||||||
|
&&
|
||||||
|
graph[graph_nodes
|
||||||
|
(nodes, run3, ev3, run2, ev2)] != 0)
|
||||||
|
{
|
||||||
|
// other route found
|
||||||
|
other_route = 1;
|
||||||
|
}
|
||||||
|
ev3++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
run3++;
|
||||||
|
}
|
||||||
|
if (other_route == 0 || 1 == 1)
|
||||||
|
{
|
||||||
|
func (run2, ev2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
run2++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//! Display the current semistate using LaTeX output format.
|
||||||
|
/**
|
||||||
|
* This is not as nice as we would like it. Furthermore, the function is too big, and needs to be split into functional parts that
|
||||||
|
* will allow the generation of dot code as well.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
latexSemiState ()
|
||||||
|
{
|
||||||
|
static int attack_number = 0;
|
||||||
|
int run;
|
||||||
|
Protocol p;
|
||||||
|
int *ranks;
|
||||||
|
int maxrank;
|
||||||
|
|
||||||
|
void node (const int run, const int index)
|
||||||
|
{
|
||||||
|
if (sys->runs[run].protocol == INTRUDER)
|
||||||
|
{
|
||||||
|
if (sys->runs[run].role == I_M)
|
||||||
|
{
|
||||||
|
eprintf ("m0");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
eprintf ("i%i", run);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
eprintf ("r%ii%i", run, index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open graph
|
||||||
|
attack_number++;
|
||||||
|
eprintf ("\\begin{msc}{Attack on ");
|
||||||
|
p = (Protocol) current_claim->protocol;
|
||||||
|
termPrint (p->nameterm);
|
||||||
|
eprintf (", role ");
|
||||||
|
termPrint (current_claim->rolename);
|
||||||
|
eprintf (", claim type ");
|
||||||
|
termPrint (current_claim->type);
|
||||||
|
eprintf ("}\n%% Attack number %i\n", attack_number);
|
||||||
|
eprintf ("\n");
|
||||||
|
|
||||||
|
// Needed for the bindings later on: create graph
|
||||||
|
goal_graph_create (); // create graph
|
||||||
|
if (warshall (graph, nodes) == 0) // determine closure
|
||||||
|
{
|
||||||
|
eprintf
|
||||||
|
("%% This graph was not completely closed transitively because it contains a cycle!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
ranks = memAlloc (nodes * sizeof (int));
|
||||||
|
maxrank = graph_ranks (graph, ranks, nodes); // determine ranks
|
||||||
|
|
||||||
|
// Draw headings (boxes)
|
||||||
|
run = 0;
|
||||||
|
while (run < sys->maxruns)
|
||||||
|
{
|
||||||
|
if (sys->runs[run].protocol != INTRUDER)
|
||||||
|
{
|
||||||
|
eprintf ("\\declinst{r%i}{}{run %i}\n", run, run);
|
||||||
|
}
|
||||||
|
run++;
|
||||||
|
}
|
||||||
|
eprintf ("\\nextlevel\n\n");
|
||||||
|
|
||||||
|
// Draw all events (according to ranks)
|
||||||
|
{
|
||||||
|
int myrank;
|
||||||
|
|
||||||
|
myrank = 0;
|
||||||
|
while (myrank < maxrank)
|
||||||
|
{
|
||||||
|
int count;
|
||||||
|
int run;
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
run = 0;
|
||||||
|
while (run < sys->maxruns)
|
||||||
|
{
|
||||||
|
if (sys->runs[run].protocol != INTRUDER)
|
||||||
|
{
|
||||||
|
int ev;
|
||||||
|
|
||||||
|
ev = 0;
|
||||||
|
while (ev < sys->runs[run].step)
|
||||||
|
{
|
||||||
|
if (myrank == ranks[node_number (run, ev)])
|
||||||
|
{
|
||||||
|
// We have found an event on this rank
|
||||||
|
// We only need to consider reads and claims, but for fun we just consider everything.
|
||||||
|
void outgoing_arrow (const int run2, const int ev2)
|
||||||
|
{
|
||||||
|
Roledef rd, rd2;
|
||||||
|
int delta;
|
||||||
|
|
||||||
|
rd = roledef_shift (sys->runs[run].start, ev);
|
||||||
|
rd2 = roledef_shift (sys->runs[run2].start, ev2);
|
||||||
|
|
||||||
|
eprintf ("\\mess{");
|
||||||
|
/*
|
||||||
|
// Print the term
|
||||||
|
// Maybe, if more than one outgoing, and different send/reads, we might want to change this a bit.
|
||||||
|
if (rd->type == SEND)
|
||||||
|
{
|
||||||
|
if (rd2->type == CLAIM)
|
||||||
|
{
|
||||||
|
roledefPrint(rd);
|
||||||
|
}
|
||||||
|
if (rd2->type == READ)
|
||||||
|
{
|
||||||
|
eprintf("$");
|
||||||
|
if (isTermEqual(rd->message, rd2->message))
|
||||||
|
{
|
||||||
|
termPrint(rd->message);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
termPrint(rd->message);
|
||||||
|
eprintf(" \\longrightarrow ");
|
||||||
|
termPrint(rd2->message);
|
||||||
|
}
|
||||||
|
eprintf("$");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
roledefPrint(rd);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
roledefPrint (rd);
|
||||||
|
eprintf (" $\\longrightarrow$ ");
|
||||||
|
roledefPrint (rd2);
|
||||||
|
|
||||||
|
eprintf ("}{r%i}{r%i}", run, run2);
|
||||||
|
delta = ranks[node_number (run2, ev2)] - myrank;
|
||||||
|
if (delta != 0)
|
||||||
|
{
|
||||||
|
eprintf ("[%i]", delta);
|
||||||
|
}
|
||||||
|
eprintf ("\n");
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
iterate_outgoing_arrows (outgoing_arrow, run, ev);
|
||||||
|
}
|
||||||
|
ev++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
run++;
|
||||||
|
}
|
||||||
|
eprintf ("\\nextlevel\n");
|
||||||
|
myrank++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// clean memory
|
||||||
|
memFree (ranks, nodes * sizeof (int)); // ranks
|
||||||
|
|
||||||
|
// close graph
|
||||||
|
eprintf ("\\nextlevel\n\\end{msc}\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
//! Display the current semistate using dot output format.
|
//! Display the current semistate using dot output format.
|
||||||
|
/**
|
||||||
|
* This is not as nice as we would like it. Furthermore, the function is too big, and needs to be split into functional parts that
|
||||||
|
* will allow the generation of LaTeX code as well.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
dotSemiState ()
|
dotSemiState ()
|
||||||
{
|
{
|
||||||
@ -924,75 +1254,7 @@ dotSemiState ()
|
|||||||
ev = 0;
|
ev = 0;
|
||||||
while (ev < sys->runs[run].length)
|
while (ev < sys->runs[run].length)
|
||||||
{
|
{
|
||||||
/**
|
void incoming_arrow (int run2, int ev2)
|
||||||
* Determine wheter to draw an incoming arrow to this event.
|
|
||||||
* We check all other runs, to see if they are ordered.
|
|
||||||
*/
|
|
||||||
int run2;
|
|
||||||
|
|
||||||
run2 = 0;
|
|
||||||
while (run2 < sys->maxruns)
|
|
||||||
{
|
|
||||||
if (run2 != run && sys->runs[run2].protocol != INTRUDER)
|
|
||||||
{
|
|
||||||
// Is this run before the event?
|
|
||||||
int ev2;
|
|
||||||
int found;
|
|
||||||
|
|
||||||
found = 0;
|
|
||||||
ev2 = sys->runs[run2].length;
|
|
||||||
while (found == 0 && ev2 > 0)
|
|
||||||
{
|
|
||||||
ev2--;
|
|
||||||
if (graph[graph_nodes (nodes, run2, ev2, run, ev)]
|
|
||||||
!= 0)
|
|
||||||
{
|
|
||||||
found = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (found == 1)
|
|
||||||
{
|
|
||||||
// It is before the event, and thus we would like to draw it.
|
|
||||||
// However, if there is another path along which we can get here, forget it
|
|
||||||
/**
|
|
||||||
* Note that this algorithm is similar to Floyd's algorithm for all shortest paths.
|
|
||||||
* The goal here is to select only the path with distance 1 (as viewed from the regular runs),
|
|
||||||
* so we can simplify stuff a bit.
|
|
||||||
* Nevertheless, using Floyd first would probably be faster.
|
|
||||||
*/
|
|
||||||
int other_route;
|
|
||||||
int run3;
|
|
||||||
int ev3;
|
|
||||||
|
|
||||||
other_route = 0;
|
|
||||||
run3 = 0;
|
|
||||||
ev3 = 0;
|
|
||||||
while (other_route == 0 && run3 < sys->maxruns)
|
|
||||||
{
|
|
||||||
if (sys->runs[run3].protocol != INTRUDER)
|
|
||||||
{
|
|
||||||
ev3 = 0;
|
|
||||||
while (other_route == 0
|
|
||||||
&& ev3 < sys->runs[run3].length)
|
|
||||||
{
|
|
||||||
if (graph
|
|
||||||
[graph_nodes
|
|
||||||
(nodes, run2, ev2, run3, ev3)] != 0
|
|
||||||
&&
|
|
||||||
graph[graph_nodes
|
|
||||||
(nodes, run3, ev3, run,
|
|
||||||
ev)] != 0)
|
|
||||||
{
|
|
||||||
// other route found
|
|
||||||
other_route = 1;
|
|
||||||
}
|
|
||||||
ev3++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
run3++;
|
|
||||||
}
|
|
||||||
if (other_route == 0)
|
|
||||||
{
|
{
|
||||||
Roledef rd, rd2;
|
Roledef rd, rd2;
|
||||||
/*
|
/*
|
||||||
@ -1007,8 +1269,7 @@ dotSemiState ()
|
|||||||
eprintf (" ");
|
eprintf (" ");
|
||||||
// decide color
|
// decide color
|
||||||
rd = roledef_shift (sys->runs[run].start, ev);
|
rd = roledef_shift (sys->runs[run].start, ev);
|
||||||
rd2 =
|
rd2 = roledef_shift (sys->runs[run2].start, ev2);
|
||||||
roledef_shift (sys->runs[run2].start, ev2);
|
|
||||||
if (rd->type == CLAIM)
|
if (rd->type == CLAIM)
|
||||||
{
|
{
|
||||||
// Towards a claim, so only indirect dependency
|
// Towards a claim, so only indirect dependency
|
||||||
@ -1021,13 +1282,11 @@ dotSemiState ()
|
|||||||
if (rd->type == READ && rd2->type == SEND)
|
if (rd->type == READ && rd2->type == SEND)
|
||||||
{
|
{
|
||||||
// We want to distinguish where it is from a 'broken' send
|
// We want to distinguish where it is from a 'broken' send
|
||||||
if (isTermEqual
|
if (isTermEqual (rd->message, rd2->message))
|
||||||
(rd->message, rd2->message))
|
|
||||||
{
|
{
|
||||||
if (isTermEqual
|
if (isTermEqual
|
||||||
(rd->from, rd2->from)
|
(rd->from, rd2->from)
|
||||||
&& isTermEqual (rd->to,
|
&& isTermEqual (rd->to, rd2->to))
|
||||||
rd2->to))
|
|
||||||
{
|
{
|
||||||
// Wow, a perfect match. Leave the arrow as-is :)
|
// Wow, a perfect match. Leave the arrow as-is :)
|
||||||
eprintf ("[color=forestgreen]");
|
eprintf ("[color=forestgreen]");
|
||||||
@ -1042,31 +1301,16 @@ dotSemiState ()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Not even the same message, intruder construction
|
// Not even the same message, intruder construction
|
||||||
eprintf
|
eprintf ("[label=\"construct\",color=red]");
|
||||||
("[label=\"construct\",color=red]");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// close up
|
// close up
|
||||||
eprintf (";\n");
|
eprintf (";\n");
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// for debugging: show other route
|
|
||||||
run3--;
|
|
||||||
ev3--;
|
|
||||||
|
|
||||||
eprintf
|
iterate_incoming_arrows (incoming_arrow, run, ev);
|
||||||
("\t// HIDDEN r%ii%i -> r%ii%i because route through r%ii%i\n",
|
|
||||||
run2, ev2, run, ev, run3, ev3);
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
run2++;
|
|
||||||
}
|
|
||||||
ev++;
|
ev++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1247,7 +1491,8 @@ termBindConsequences (Term t)
|
|||||||
tl = openVariables;
|
tl = openVariables;
|
||||||
while (tl != NULL)
|
while (tl != NULL)
|
||||||
{
|
{
|
||||||
if ((rd->type == READ || rd->type == SEND) && termSubTerm (rd->message, tl->term))
|
if ((rd->type == READ || rd->type == SEND)
|
||||||
|
&& termSubTerm (rd->message, tl->term))
|
||||||
{
|
{
|
||||||
// This run event contains the open variable
|
// This run event contains the open variable
|
||||||
affectedCount++;
|
affectedCount++;
|
||||||
@ -1404,13 +1649,17 @@ select_goal ()
|
|||||||
|
|
||||||
// Determine buf_constrain levels
|
// Determine buf_constrain levels
|
||||||
// Bit 0: 1 constrain level
|
// Bit 0: 1 constrain level
|
||||||
if (mode & 1) adapt (1, term_constrain_level (b->term));
|
if (mode & 1)
|
||||||
|
adapt (1, term_constrain_level (b->term));
|
||||||
// Bit 1: 2 key level (inverted)
|
// Bit 1: 2 key level (inverted)
|
||||||
if (mode & 2) adapt (1, 0.5 * (1 - b->level));
|
if (mode & 2)
|
||||||
|
adapt (1, 0.5 * (1 - b->level));
|
||||||
// Bit 2: 4 consequence level
|
// Bit 2: 4 consequence level
|
||||||
if (mode & 4) adapt (1, termBindConsequences (b->term));
|
if (mode & 4)
|
||||||
|
adapt (1, termBindConsequences (b->term));
|
||||||
// Bit 4: 16 single variables first
|
// Bit 4: 16 single variables first
|
||||||
if (mode & 16) adapt (4, 1-isTermVariable (b->term));
|
if (mode & 16)
|
||||||
|
adapt (4, 1 - isTermVariable (b->term));
|
||||||
|
|
||||||
// Weigh result
|
// Weigh result
|
||||||
if (buf_weight == 0 || buf_constrain <= min_constrain)
|
if (buf_weight == 0 || buf_constrain <= min_constrain)
|
||||||
@ -2055,7 +2304,8 @@ prune_bounds ()
|
|||||||
if (sys->output == PROOF)
|
if (sys->output == PROOF)
|
||||||
{
|
{
|
||||||
indentPrint ();
|
indentPrint ();
|
||||||
eprintf ("Pruned: ran out of allowed time (-T %i switch)\n", get_time_limit () );
|
eprintf ("Pruned: ran out of allowed time (-T %i switch)\n",
|
||||||
|
get_time_limit ());
|
||||||
}
|
}
|
||||||
// Pruned because of time bound!
|
// Pruned because of time bound!
|
||||||
current_claim->timebound = 1;
|
current_claim->timebound = 1;
|
||||||
@ -2245,7 +2495,16 @@ property_check ()
|
|||||||
*/
|
*/
|
||||||
count_false ();
|
count_false ();
|
||||||
if (sys->output == ATTACK)
|
if (sys->output == ATTACK)
|
||||||
|
{
|
||||||
|
if (sys->latex == 1)
|
||||||
|
{
|
||||||
|
latexSemiState ();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
dotSemiState ();
|
dotSemiState ();
|
||||||
|
}
|
||||||
|
}
|
||||||
// Store attack length if shorter
|
// Store attack length if shorter
|
||||||
attack_this = get_trace_length ();
|
attack_this = get_trace_length ();
|
||||||
if (attack_this < attack_length)
|
if (attack_this < attack_length)
|
||||||
|
Loading…
Reference in New Issue
Block a user