{'fraction_non_alphanumeric': 0.038375350140056025, 'fraction_numerical': 0.005210084033613446, 'mean_word_length': 4.177810007251631, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 19, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Timed Automata Semantics for Visual e-Contracts

C-O Diagrams have been introduced as a means to have a more visual representation of electronic contracts, where it is possible to represent the obligations, permissions and prohibitions of the different signatories, as well as what are the penalties in case of not fulfillment of their obligations and prohibitions. In such diagrams we are also able to represent absolute and relative timing constraints. In this paper we present a formal semantics for C-O Diagrams based on timed automata extended with an ordering of states and edges in order to represent different deontic modalities.


Introduction
In the software context, the term contract has traditionally been used as a metaphor to represent limited kinds of "agreements" between software elements at different levels of abstraction. The first use of the term in connection with software programming and design was done by Meyer in the context of the language Eiffel (programming-by-contracts, or design-by-contract) [10]. This notion of contracts basically relies on the Hoare's notion of pre and post-conditions and invariants. Though this paradigm has proved to be useful for developing object oriented systems, it seems to have shortcomings for novel development paradigms such as service-oriented computing and component-based development. These new applications have a more involved interaction and therefore require a more sophisticated notion of contracts.
As a response, behavioural interfaces have been proposed to capture richer properties than simple pre and post-conditions [5]. Here it is possible to express contracts on the history of events, including causality properties. However, the approach is limited when it comes to contracts containing exceptional behaviour, since the focus is mainly on the interaction concerning expected (and prohibited) behaviour.
In the context of SOA, there are different service contract specification languages, like ebXML [4], WSLA [14], and WS-Agreement [13]. These standards and specification languages suffer from one or more of the following problems: They are restricted to bilateral contracts, lack formal semantics (so it is difficult to reason about them), their treatment of functional behaviour is rather limited and the sub-languages used to specify, for instance, security constraints are usually limited to small applicationspecific domains. The lack of suitable languages for contracts in the context of SOA is a clear conclusion of the survey [11] where a taxonomy is presented. And-refinement Clause SubClause1 SubClause2 Or-refinement Seq-refinement More recently, some researchers have investigated how to adapt deontic logic [9] to define (consistent) contracts targeted to software systems where the focus is on the normative notions of obligation, permission and prohibition, including sometimes exceptional cases (e.g., [12]). Independently of the application domain, there still is need to better fill the gap between a contract understood by nonexperts in formal methods (for its use), its logical representation (for reasoning), and its internal machinerepresentation (for runtime monitoring, and to be manipulated by programmers). We see two possible ways to bridge this gap: i) to develop suitable techniques to get a good translation from contracts written in natural language into formal languages, and ii) to provide a graphical representation (and tools) to manipulate contracts at a high level, with formal semantics supporting automatic translation into the formal language. We take in this paper the second approach.
In [8] we have introduced C-O Diagrams, a graphical representation for contracts allowing the representation of complex clauses describing the obligations, permissions, and prohibitions of different signatories (as defined in deontic logic [9]), as well as reparations describing contractual clauses in case of not fulfillment of obligations and prohibitions. Besides, C-O Diagrams permit to define real-time constraints. In [7] some of the satisfaction rules needed to check if a timed automaton satisfies a C-O Diagram specification were defined. These rules were originally miscalled "formal semantics". The goal of this paper is to further develop our previous work, in particular we present here a formal semantics for C-O Diagrams based on timed automata, extended with an ordering of states and edges.
The rest of the work is structured as follows: Section 2 presents C-O Diagrams and their syntax, Section 3 develops the formal semantics of C-O Diagrams, including its implementation in UPPAAL [6] and a small example. The work is concluded in Section 4.

C-O Diagrams Description and Syntax
In Fig. 1 we show the basic element of C-O Diagrams. It is called a box and it is divided into four fields. On the left-hand side of the box we specify the conditions and restrictions. The guard g specifies the conditions under which the contract clause must be taken into account (boolean expression). The time restriction tr specifies the time frame during which the contract clause must be satisfied (deadlines, timeouts, etc.). The propositional content P, on the center, is the main field of the box, and it is used to specify normative aspects (obligations, permissions and prohibitions) that are applied over actions, and/or the specification of the actions themselves. The last field of these boxes, on the right-hand side, is the reparation R. This reparation, if specified by the contract clause, is a reference to another contract that must be satisfied in case the main norm is not satisfied (a prohibition is violated or an obligation is not fulfilled, there is no reparation for permission), considering the clause eventually satisfied if this reparation is satisfied. Each box has also a name and an agent. The name is useful both to describe the clause and to reference the box from other clauses, so it must be unique. The agent indicates who is the performer of the action. Seq-refinement --

a & b a + b a ; b
And-refinement Or-refinement And-refinement These basic elements of C-O Diagrams can be refined by using AND/OR/SEQ refinements, as shown in Fig. 2. The aim of these refinements is to capture the hierarchical clause structure followed by most contracts. An AND-refinement means that all the subclauses must be satisfied in order to satisfied the parent clause. An OR-refinement means that it is only necessary to satisfy one of the subclauses in order to satisfy the parent clause, so as soon as one of its subclauses is fulfilled, we conclude that the parent clause is fulfilled as well. A SEQ-refinement means that the norm specified in the target box (SubClause2 in Fig. 2) must be fulfilled after satisfying the norm specified in the source box (SubClause1 in Fig. 2). By using these structures we can build a hierarchical tree with the clauses defined by a contract, where the leaf clauses correspond to the atomic clauses, that is, to the clauses that cannot be divided into subclauses. There is another structure that can be used to model repetition. This structure is represented as an arrow going from a subclause to one of its ancestor clauses (or to itself), meaning the repetitive application of all the subclauses of the target clause after satisfying the source subclause. For example, in the right-hand side of Fig. 2, we have an OR-refinement with an arrow going from SubClause1 to Clause. It means that after satisfying SubClause1 we apply Clause again, but not after satisfying SubClause2.
It is only considered the specification of atomic actions in the P field of the leaf boxes of our diagrams. The composition of actions can be achieved by means of the different kinds of refinement. In this way, an AND-refinement can be used to model concurrency "&" between actions, an OR-refinement can be used to model a choice "+" between actions, and a SEQ-refinement can be used to model sequence ";" of actions. In Fig. 3 we can see an example about how to model these compound actions through refinements, given two atomic actions a and b.
The deontic norms (obligations, permissions and prohibitions) that are applied over these actions can be specified in any box of our C-O Diagrams, affecting all the actions in the leaf boxes that are descendants of this box. If it is the case that the box where we specify the deontic norm is a leaf, the norm only affects the atomic action we have in this box. It is used an upper case "O" to denote an obligation, an upper case "P" to denote a permission, and an upper case "F" to denote a prohibition (forbidden). These letters are written in the top left corner of field P.
The composition of deontic norms is also achieved by means of the different refinements we have in C-O Diagrams. Thus, an AND-refinement corresponds to the conjunction operator "∧" between norms, an OR-refinement corresponds to the choice operator "+" between norms, and a SEQ-refinement corresponds to the sequence operator ";" between norms. For example, we can imagine having a leaf box specifying the obligation of performing an action a, written as O(a), and another leaf box specifying the obligation of performing an action b, written as O(b). These two norms can be combined in the three different ways mentioned before through the different kinds of refinement (Fig. 4). However, the specification of deontic norms in our diagrams must fulfill the following rule: exactly one deontic norm must be specified in each one of the branches of our hierarchical tree, i.e., we cannot have an action without a deontic norm applied over it and we cannot have deontic norms applied over other deontic norms. We have also that agents are only specified in the boxes where a deontic norm is defined, being each agent associated to a concrete deontic norm. Finally, the repetition of both, actions and deontic norms, can be achieved by means of the repetition structure we have in C-O Diagrams.
We have given here an abridged description of C-O Diagrams. A more detail description can be found in [8], including a qualitative and quantitative evaluation, and a discussion on related work.

Definition 1 (C-O Diagrams Syntax)
We consider a finite set of real-valued variables C standing for clocks, a finite set of non-negative integer-valued variables V , a finite alphabet Σ for atomic actions, a finite set of identifiers A for agents, and another finite set of identifiers N for names. The greek letter ε means that and expression is not given, i.e., it is empty.
We use C to denote the contract modelled by a C-O Diagram. The diagram is defined by the following EBNF grammar: where a ∈ Σ, agent ∈ A and name ∈ N . Guard g is ε or a conjunctive formula of atomic constraints of the form: v ∼ n or v − w ∼ n, for v, w ∈ V , ∼∈ { ≤, <, =, >, ≥ } and n ∈ IN, whereas timed restriction tr is ε or a conjunctive formula of atomic constraints of the form: x ∼ n or x − y ∼ n, for x, y ∈ C , ∼∈ { ≤, <, =, >, ≥ } and n ∈ IN. O, P and F are the deontic operators corresponding to obligation, permission and prohibition, respectively, where O(C 2 ) states the obligation of performing C 2 , F(C 2 ) states prohibition of performing C 2 , and P(C 2 ) states the permission of performing C 2 . And, Or and Seq are the operators corresponding to the refinements we have in C-O Diagrams, AND-refinement, OR-refinement and SEQ-refinement, respectively.
The simplest contract we can have in C-O Diagrams is that composed of only one box including the elements agent and name. Optionally, we can specify a guard g and a time restriction tr. We also have a deontic operator (O, P or F) applied over an atomic action a, and in the case of obligations and prohibitions it is possible to specify another contract C as a reparation.
We use C 1 to define a more complex contract where we combine different deontic norms by means of any of the different refinements we have in C-O Diagrams. In the box where we have the refinement into C 1 we cannot specify an agent nor a reparation because these elements are always related to a single deontic norm, but we still can specify a guard g and a time restriction tr that affect all the deontic norms we combine.
Once we write a deontic operator in a box of our diagram, we have two possibilities as we can see in the specification of C 2 : we can just write a simple action a in the box, being the deontic operator applied only over it, or we can refine this box in order to apply the deontic operator over a compound action. In this case we have that the subboxes (C 3 ) cannot define a new deontic operator as it has already been defined in the parent box (affecting all the subboxes).

C-O Diagrams Semantics
The C-O Diagrams semantics is defined by means of a transformation into a Network of Timed Automata (NTA), that is defined as a set of timed automata [1,2] that run simultaneously, using the same set of clocks and variables, and synchronizing on the common actions.
In what follows we consider a finite set of real-valued variables C ranged over by x, y, . . . standing for clocks, a finite set of non-negative integer-valued variables V , ranged over by v, w, . . . and a finite alphabet Σ ranged over by a, b, . . . standing for actions. We will use letters r, r ′ , . . . to denote sets of clocks. We will denote by Assigns the set of possible assignments, Assigns = {v := expr | v ∈ V }, where expr are arithmetic expressions using naturals and variables. Letters s, s ′ . . . will be used to represent a set of assignments.
A guard or invariant condition is a conjunctive formula of atomic constraints of the form: The set of guard or invariant conditions will be denoted by G , ranged over by g, g ′ , . . ..

Definition 2 (Timed Automaton)
where the subset of urgent edges is called E u ⊆ E, and they will graphically be distinguished as they will have their arrowhead painted in white. I : N → G is a function that assigns invariant conditions (which could be empty) to locations.
From now on, we will write n g,a,r −→ s n ′ to denote (n, g, a, s, r, n ′ ) ∈ E, and n g,a,r In an NTA we distinguish two types of actions: internal and synchronization actions. Internal actions can be executed by the corresponding automata independently, and they will be ranged over the letters a, b . . .. Synchronization actions, however, must be executed simultaneously by two automata, and they will be ranged over letters m, m ′ , . . . and come from the synchronization of two actions m! and m?, executed from two different automata. Due to the lack of space, we refer the reader to [3] for the definition of the semantics of timed automaton and NTA.
To specify the C-O Diagrams semantics, we add the definition of two orderings, ≺ N and ≺ E , where: • ≺ N is a (strict, partial) ordering on N where n ≺ N n ′ means that node n is better than node n ′ .
• ≺ E is a (strict, partial) ordering on E where e ≺ N e ′ means that edge e is better than edge e ′ . We also add a violation set V (n) associated to each node n in N, that is the set of contractual obligations and prohibitions that are violated in n.

Definition 3 (Violation Set) Let us consider the set of contractual obligations and prohibitions CN
ranged over cn, cn ′ ,. . . standing for identifiers of obligations and prohibitions. We write n |= cn to express that obligation or prohibition cn is violated in node n. Therefore, the violation set is defined as V (n) = {cn | cn ∈ CN and n |= cn}.
Another set called satisfaction set S(n) is also associated to each node n in N. This set is composed by the contractual obligations and prohibitions that have already been satisfied in n.

Definition 4 (Satisfaction Set) Let us consider the set of contractual obligations and prohibitions COF
ranged over co f , co f ′ ,. . . standing for identifiers of obligations and prohibitions. We write n |= co f to express that obligation or prohibition co f has been satisfied in node n (we consider a prohibition satisfied in node n if it has not been violated and cannot be violated anymore because the time frame specified for the prohibition has expired). Hence, the satisfaction set is defined as S(n) = {co f | co f ∈ COF and n |= co f }.
Once these two sets have been defined, we can formally define the ordering on nodes ≺ N , by comparing the violation sets and the satisfaction sets of the nodes, and the ordering on edges ≺ E , by comparing the violation sets and the satisfaction sets of the target nodes of the edges.

Definition 5 (Ordering on Nodes)
A node n 1 is better than another node n 2 if the violation set of n 1 is a proper subset of the violation set of n 2 or, if the violation sets are the same, a node n 1 is better than another node n 2 if the satisfaction set of n 1 is a proper superset of the satisfaction set of n 2 , that is, Definition 6 (Ordering on Edges) An edge e 1 is better than another edge e 2 if the source node is the same in both cases but the violation set of the target node of e 1 is a proper subset of the violation set of the target node of e 2 or, if the violation sets are the same, an edge e 1 is better than another edge e 2 if the satisfaction set of the target node of e 1 is a proper superset of the satisfaction set of the target node of e 2 . Considering e 1 = (n 1 , g 1 , a 1 , s 1 , r 1 , n 1 ′ ) and e 2 = (n 2 , g 2 , a 2 , Finally, another set called permission set P(n) is associated to each node n in N. This set influences neither the ordering on nodes nor the ordering on edges, it is used just to record the permissions in the contract that have been made effective.
Definition 7 (Permission Set) Let us consider the set of contractual permissions CP ranged over cp, cp ′ ,. . . standing for identifiers of permissions. We write n |= cp to express that permission cp has already been made effective in node n. Then, the permission set is defined as P(n) = {cp | cp ∈ CP and n |= cp}.
Graphically, when we draw a timed automaton extended with these three sets, we write under each node n between braces its violation set V (n) on the left, its satisfaction set S(n) on the centre and its permission set P(n) on the right. In the initial node of the automata we build corresponding to C-O Diagrams these three sets are empty. By default, a node keeps in these sets the same content of the previous node when we compose the automata. Only in a few cases the content of these sets is modified (when an obligation or a prohibition is violated, an obligation or a prohibition is satisfied or a permission is made effective).
Concerning the real-time restrictions tr specified in the contract, the two types of time restrictions we can have in C-O Diagrams must be translated in a different way for their inclusion into a timed automaton construction: • A time restriction specified using absolute time must be specified in timed automata by rewriting the terms in which absolute time references occur. For that purpose we define a global clock T ∈ C that is never reset during the execution of the automata and, taking into account the moment at which the contract is enacted, we rewrite the absolute time references as deadlines involving clock T and considering the smallest time unit needed in the contract. For example, let us consider a clause that must be satisfied between the 5th of November and the 10th of November, and that the contract containing this clause is enacted the 31st of October. If we suppose that days is the smallest time unit used in the contract for the specification of real-time restrictions, the time restriction of this clause is written as (T ≥ 5) and (T ≤ 10). • A time restriction specified using relative time must be specified in timed automata by introducing an additional clock to register the amount of time that has elapsed since another clause has been satisfied, resetting the additional clock value when this happens and specifying the deadline using it. We call this clock t name , where name is the clause used as reference for the specification of the time restriction. Therefore, we define a set of additional clocks C add = {t name |t name ∈ C } including  Figure 5: Automata corresponding to a simple action a and to compound actions a clock for every clause that is used as reference in the time restriction of at least another clause. For example, let us consider a contract with a clause that must be satisfied between 5 and 10 days after another clause name1 has been satisfied. In this case we define an additional clock t name1 that is reset to zero when clause name1 is satisfied (t name1 := 0) and the time restriction of the other clause is written as (t name1 ≥ 5) and (t name1 ≤ 10). As a result, the set of clocks of the timed automata would be C = {T } ∪C add . When we construct the timed automata corresponding to C-O Diagrams, we always consider (x ≥ t1) and (x ≤ t2) as the interval corresponding to the time restriction tr of the clause, where x ∈ C is the clock used for its specification (x = T in the case of absolute time and x = t name in the case of relative time, being name the clause used as reference), t1 ∈ IN is the beginning of the interval and t2 ∈ IN is the end of the interval (t1 ≤ t2). If tr does not define the lower bound of the interval we take t1 = 0, if tr does not define the upper bound of the interval we take t2 = ∞, and if tr = ε we take t1 = 0, t2 = ∞ and x = T .
Once we have given these extensions of the definition of timed automata and we have explained how the different kinds of time restriction can be expressed, considering all the different elements we can specify in a C-O Diagram, we can define the transformation of the diagrams into timed automata by induction using several transformation rules.

Definition 8 (C-O Diagrams Transformation Rules: Part I)
(1) An atomic action in a C-O Diagram, that is, (ε, name, ε, ε, a, ε) corresponds to the timed automa- , satisfaction (S) and permission (P) sets are not modified, so V (a init ) = V (a end ), S(a init ) = S(a end ) and P(a init ) = P(a end ). This timed automaton can be seen in Fig. 5 (A).

(2) A compound action in a C-O Diagram where an AND-refinement is used to compose actions,
that is, (ε, name, ε, ε,C 1 And C 2 And . . . And C n , ε) corresponds to the cartesian product of the automata corresponding to each one of the subcontracts. Let us consider A, B, . . . , Z the automata corresponding to the subcontracts C 1 ,C 2 , . . . ,C n (the actions specified in these subcontracts can be atomic actions or other compound actions). The resulting automaton AND corresponds to the cartesian product of these automata, that is, AND = A × B × . . . × Z. Again, the violation (V), satisfaction (S) and permission (P) sets are not modified, so they are the same in all the nodes. This composition of timed automata is shown graphically in Fig. 5 (B).  n 0 B , E B , I B ), . . . , Z = (N Z , n 0 Z , E Z , I Z ). The resulting automaton is therefore OR = (N OR , n 0 OR , E OR , I OR ), where: Fig. 5 (C).

. , Z init ). This rule is not applied in the cases of A init (as there is not previous ending node to connect) and Z end (as there is not following initial node to connect). Let
. The resulting automaton is therefore SEQ = (N SEQ , n 0 SEQ , E SEQ , I SEQ ), where: Fig. 5 (D).

Again, the violation (V), satisfaction (S) and permission (P) sets are not modified, so they are the same in all the nodes. This composition of timed automata is shown graphically in
Until now, we have seen how the automata corresponding to the different actions (atomic or compound) specified in a C-O Diagram are constructed and we have seen that these translations do not modify the content of any of the sets (violation, satisfaction or permission). Next, we define the transformation rules specifying how these "action" automata are modified when we apply a deontic norm (obligation, permission or prohibition) over the actions in the C-O Diagram.

Definition 7 (C-O Diagrams Transformation Rules: Part II) (5) The application of an obligation, a permission or a prohibition over an action in a C-O Di
The resulting timed automata are shown graphically in Fig. 6, where (A

) corresponds to obligation, (B) corresponds to permission and (C) corresponds to prohibition. We consider a one of the atomic actions included in the subcontract C.
We can see that the above constructions can include a reparation contract R in the cases of obligation and prohibition. If this reparation is defined, we have to construct the automaton corresponding to the reparation contract and integrate this automaton as part of the automaton we have generated for the obligation or prohibition. This reparation contract removes the obliged or prohibited clause name from the violation set of the corresponding automaton, as we can see in Fig. 6 (D).  Figure 6: Automata corresponding to deontic norms and automaton corresponding to a reparation Finally, we have to define the rules about how the automata corresponding to different deontic norms are composed when we have a composition of deontic norms in our C-O Diagram. To make this composition possible, first we need to have only one ending node in the automata corresponding to the different deontic norms. Therefore, we add a new ending node in these automata and urgent edges from the old ending nodes to this new node. Notice that in the case of obligation and prohibition, if there is no reparation defined, the node violating the norm is a final node of the whole automaton construction where the contract is breached. In the case of permission, as no reparation is defined, we have that P(A) R = P(A).

(6) An obligation or prohibition in a C-O Diagram specifying a contract reparation R = ε corresponds to the obligation automaton O(A) or the prohibition automaton F(A) together with the reparation automaton R, considering the node with name in its violation (A vio ) set as the initial node of the reparation automaton (R init ). In the ending node of the reparation automaton (R end ) name is removed from the violation set, as the violation has been repaired. In this node we also have that the satisfaction set and the permission set are different from the ones we have in the initial node of the reparation because we have to include in the satisfaction set all the obligations and prohibitions satisfied in the reparation contract, and in the permission
Therefore, the composition of the automata corresponding to different deontic norms is defined by three additional transformation rules.
. . , C n = (N C n , n 0 Cn , E C n , I C n ). Considering the case where g = ε and tr = ε, and having that E C 1 * , E C 2 * , . . . , E C n * are the sets of edges considering time restriction tr together with their own time restriction, the resulting network of automata is therefore . . , n where:  This composition of timed automata is shown graphically in Fig. 7 (A). (9) If several norms are composed by an OR-refinement, that is, we have specified the diagram (ε, name, g,tr,C 1 OrC 2 Or . . . OrC n , ε), their composition corresponds to an automaton in which the automata corresponding to each one of the norms is considered as an alternative. Let us consider C 1 , C 2 , . . . , C n the automata corresponding to the norms we are composing. The resulting automaton OR * preserves the structure of the automata we are composing, adding two nodes called C init and C f inal . We define an urgent edge performing no action for each one of the norms we are composing connecting C init with the initial node of the automaton corresponding to the norm and we also define an urgent edge performing no action for each one of the norm we are composing connecting the final node of its automaton with C f inal . We add another node C skip if guard condition of the parent clause g = ε and an urgent edge from C init to this new node guarded with the guard condition negated (¬g). In the final node of this new structure we keep the violation, satisfaction and permission sets of the previous final node, so we have that Vfinal = V 1|V 2| . . . |V n, Sfinal = S1|S2| . . . |Sn and Pfinal = P1|P2| . . . |Pn. If time restriction of the parent clause tr = ε, we consider this additional time restriction in all the composed automata together with their own time restrictions. Let Considering the case where g = ε and tr = ε, and having that E C 1 * , E C 2 * , . . . , E C n * are the sets of edges considering time restriction tr together with their own time restriction, the resulting automaton is therefore OR * = (N OR * , n 0 OR * , E OR * , I OR * ), where: This composition of timed automata is shown graphically in Fig. 7 (B). (10) If several norms are composed by a SEQ-refinement, that is, we have specified the diagram (ε, name, g,tr,C 1 SeqC 2 Seq . . . SeqC n , ε), their composition corresponds to an automaton in which the automata corresponding to each one of the norms are connected in sequence. Let us consider C 1 , C 2 , . . . , C n the automata corresponding to the norms we are composing. The resulting automaton SEQ * preserves the structure of the automata we are composing, adding just one extra node C skip if guard condition of the parent clause g = ε and an urgent edge from C 1init to this new node guarded with the guard condition negated (¬g). We connect with an urgent edge performing no action the ending node of each automaton in the sequence (C 1 f inal ,C 2 f inal , . . . ,C n−1 f inal ) with the initial node of the next automaton (C 2init ,C 3init . . . ,C ninit ). This rule is not applied in the cases of C 1init (as there is not previous ending node to connect) and C n f inal (as there is not following initial node to connect). In the initial node of each one of the composed automata we preserve the violation, satisfaction and permission sets of the previous final node. If time restriction of the parent clause tr = ε, we consider this additional time restriction in all the composed automata together with their own time restrictions. Let Considering the case where g = ε and tr = ε, and having that E C 1 * , E C 2 * , . . . , E C n * are the sets of edges considering time restriction tr together with their own time restriction, the resulting automaton is SEQ * = (N SEQ * , n 0 SEQ * , E SEQ * , I SEQ * ), where: Fig. 7 (C).

Implementation in UPPAAL
The implementation of the NTAs we have obtained in UPPAAL is quite straightforward as both, the NTA formalism considered by the tool and the NTA formalism that we have considered, are very similar. There are only a few implementation points that need a more detailed explanation: • First, as there is no way in UPPAAL of directly expressing that an edge without synchronisation should be taken without delay, that is, there are no urgent edges, we have to find an alternative way of encoding this behaviour. For this purpose we consider the modelling pattern proposed in [3]. The encoding of urgent edges introduces an extra automaton, that we call U rgent, with a single location and a self loop. The self loop synchronises on an urgent channel that we call urg edge. An edge can now be made urgent by performing the complimentary action. • The performance of actions by agents is implemented by means of boolean variables in UPPAAL.
We define a boolean variable called agent action for each one of the actions considered in the contract. These variables are initialized to false and, when one of the actions is performed by an agent in one of the edges, we update the value of the corresponding variable to true. • Finally, the violation, satisfaction and permission sets are implemented in UPPAAL by means of boolean arrays and constant integers with the names of the clauses of the contract containing obligations, prohibitions or permissions. We define an array V for violation, an array S for satisfaction,  and an array P for permission, all of them initialized to false. The size of the arrays V and S is equal to the number of obligations and prohibitions in the contract, whereas the size of the array P is equal to the number of permissions. We also define constant integers with the name of the clauses containing obligations and prohibitions, initializing each one of them to a different value (from 0 to the size of the arrays V and S minus 1), and constant integers with the name of the clauses containing permissions, initializing each one of them to a different value (from 0 to the size of the array P minus 1). These constants are used as indexes in the arrays. When taking a transition where the target node contains at least one modified set (an obligation/prohibition is violated, an obligation/prohibition is satisfied or a permission is made effective), we update to true in the proper array the value of the index corresponding to the clause. In the case of repairing an obligation/prohibition violation, the index corresponding to the proper clause in V is set to false.

Example: Online Auctioning Process
Let us consider part of a contract about an online auctioning process. It specifies that at the beginning of the process the seller has one day to upload valid information about the item he wants to sell, being forbidden the sale of inadequate items such as replicas of designers items or wild animals. We can identify in this specification an obligation, a prohibition and a real-time constraint affecting both norms. In the representation of this contract as a C-O Diagram, that can be seen in the left-hand side of Fig. 8, we have a main clause Check Item including the time restriction one day, denoted as t 1 . This main clause is decomposed by means of an AND-refinement, having on the one hand the clause with the prohibition, called Inadequate Item and denoting the action as a2, and on the other hand the clause with the obligation, called Valid Information and denoting the action as a3.
By following the C-O Diagrams semantics, we can obtain an NTA corresponding to the contract. Its implementation in the UPPAAL tool can be seen in the right-hand side of Fig. 8, having two automata running in parallel, one corresponding to the prohibition and the other one corresponding to the obligation. Now we can take advantage of all the mechanisms for simulation and formal verification provided by the tool to model-check the contract specification. As this is just a small part of a contract, the properties we can verify here are quite obvious. However, this verification process can be very useful over big contracts, verifying properties such as the violation of clauses when a time constraint expires, the possibility of satisfying the contract without violating any clause, etc.
For example, in the current NTA we can check the property that if the seller takes more that one day (t1 > 1) to upload valid information about the item, the clause Valid Information is always violated. This property is written as follows in the UPPAAL verifier:

Conclusions
In this work we have developed a formal semantics for C-O Diagrams based on timed automata extended with an ordering of states and edges in order to represent the different deontic modalities. We have also seen how these automata can be implemented in UPPAAL in order to model-check the contract specification, and a small example has been provided.
As future work, we are working on several case studies in order to proove the usefulness of our approach to model-check the specification of complex contracts with real-time constraints. With these case studies we also want to check the complexity of the contracts we can deal with. Finally, we are working on the improvement of the satisfaction rules defined in [7] and their relationship with the C-O Diagrams formal semantics.