Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime Verification #1202

Draft
wants to merge 115 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
acede73
Initial setup runtime verification
ddjanssen Oct 27, 2023
86dff78
Initial start on reconstructing constructors and removing unnecessary…
ddjanssen Nov 1, 2023
0154bb7
Trying to use Java AST
ddjanssen Nov 2, 2023
326b797
Revert "Trying to use Java AST"
ddjanssen Nov 3, 2023
7d3717f
Creating constructor works
ddjanssen Nov 3, 2023
f6b8954
Start on automated testing
ddjanssen Nov 6, 2023
09d7dbc
Created CodeString declaration to insert code directly, without havin…
ddjanssen Nov 6, 2023
82e8abb
Created block structure to perform permission checks
ddjanssen Nov 6, 2023
4bea70b
clean up of CreateBlocksMethods.scala
ddjanssen Nov 7, 2023
ef0a747
clean up
ddjanssen Nov 8, 2023
1b18062
clean up
ddjanssen Nov 8, 2023
a6e008c
Created permission checks on blocks in methods
ddjanssen Nov 8, 2023
1bb38de
Updated desciption of block permissions
ddjanssen Nov 8, 2023
ce2378b
Add: Pre post condition permission checking
ddjanssen Nov 8, 2023
7dc578e
Start: creating array permission fields
ddjanssen Nov 9, 2023
e9eddd5
Creating ideas on how to do the passes for the Transformation
ddjanssen Nov 10, 2023
5b4f8e6
Fix bug: duplication error while origin is different
ddjanssen Nov 13, 2023
656526c
Fix: found bug with method reference and refactored permissions block…
ddjanssen Nov 13, 2023
60a2cc6
Fix bug: objects dereferenced fields can now also be checked in blocks
ddjanssen Nov 13, 2023
d0ccabd
Fix bug: post conditions before return statements
ddjanssen Nov 13, 2023
217e9fc
Fix permission checking blocks for if statements and loops
ddjanssen Nov 14, 2023
56299a1
Fix bug post condition checking at all return statements
ddjanssen Nov 14, 2023
6e9e821
Fix bug inner object references
ddjanssen Nov 14, 2023
1feb682
Remove todo
ddjanssen Nov 14, 2023
0f8befe
pc change
ddjanssen Nov 23, 2023
a1caaab
add test cases
ddjanssen Nov 27, 2023
ce8c9bf
Changed field permission to do both normal fields and arrays. Changed…
ddjanssen Nov 27, 2023
671fb31
PC change
ddjanssen Nov 29, 2023
3df2f7b
Pc change
ddjanssen Nov 30, 2023
fa2bb84
Add: finding bounds of a quantifier is now possible
ddjanssen Dec 1, 2023
8eb53c5
Found mistake for quantifier
ddjanssen Dec 1, 2023
fbc8e7d
Quantifier work correctly, starall needs to be checked that the value…
ddjanssen Dec 4, 2023
fcf979c
Quantifier in quantifier works and naming is now done for the newly c…
ddjanssen Dec 5, 2023
1aee7c4
Quantifier calls are now also possible
ddjanssen Dec 7, 2023
0d852fc
clean up and refactoring
ddjanssen Dec 7, 2023
60f861c
pc switch
ddjanssen Dec 12, 2023
2413957
Pc change
ddjanssen Dec 13, 2023
f89a77c
Start on predicates
ddjanssen Dec 21, 2023
a1f0248
pc switch
ddjanssen Dec 21, 2023
d08e5bf
Predicates and quantifiers remove errors
ddjanssen Dec 21, 2023
67a177a
Fix bug: nested quantifiers prev look up works again
ddjanssen Jan 3, 2024
599611d
Fix bug: equals method returns correct boolean value and .equals is n…
ddjanssen Jan 3, 2024
7b4cbdf
Fix bug: arguments of the getpredicate method work now
ddjanssen Jan 3, 2024
00de3cc
Removed: unnecessary node for PredicateEquals and created an equals expr
ddjanssen Jan 8, 2024
ad731fa
Change: Made AbstractQuantifierRewriter to easily create new quantifi…
ddjanssen Jan 8, 2024
358a1b3
ADD: it is now possible to generate permission transfer on fork
ddjanssen Jan 10, 2024
42cdd33
Start on joining
ddjanssen Jan 11, 2024
7200cab
ADD: postJoin to the grammar and lexer as a built in method
ddjanssen Jan 11, 2024
f5f5398
Changed join token to only have 1 expression instead of having multiple
ddjanssen Jan 15, 2024
d2f2999
ADD: join and forking possible
ddjanssen Jan 15, 2024
db9a52d
Refactor of ForkJoinPermissionTransfer
ddjanssen Jan 15, 2024
914e7b6
PC switch
ddjanssen Jan 16, 2024
82b33f7
Resolved bug with loops creating duplicate statements
ddjanssen Jan 16, 2024
8211038
Add: loop invariants can now be tested
ddjanssen Jan 16, 2024
52805e7
Start on transfferring permissions in quantifiers
ddjanssen Jan 17, 2024
9fdef9f
Fix bug with inner reference for transmission transfer in arrays
ddjanssen Jan 18, 2024
5856df7
Fix bug that breaks for normal methods
ddjanssen Jan 21, 2024
998e957
Major rework, in order to do variables properly. Transferring permiss…
ddjanssen Jan 21, 2024
c65782c
Bug fix, this keyword correctly changed to offset. And remove of old …
ddjanssen Jan 22, 2024
ea4d335
Reformat and code clean up
ddjanssen Jan 22, 2024
ece7a4c
Clean up and better template to add new functions to the predicate an…
ddjanssen Jan 22, 2024
dca73f4
Removed old code
ddjanssen Jan 22, 2024
d8c6612
Created a EnhancedLoop to recreate the getpredicate method
ddjanssen Jan 22, 2024
a56023a
PC switch
ddjanssen Jan 23, 2024
e40567e
quantifiers are now translated as for loops instead of function. This…
ddjanssen Jan 24, 2024
2900a2b
Fixed nested assertion checks
ddjanssen Jan 24, 2024
3f90a8a
Loops without a body will not be created for quantifiers
ddjanssen Jan 24, 2024
6da5d5b
Fixed offset for assertion checking in quantifiers
ddjanssen Jan 24, 2024
0671a98
Add unfold method to the predicates
ddjanssen Jan 24, 2024
4acebac
Clean up and bug fix op CreatePredicates
ddjanssen Jan 24, 2024
09a46d1
Node implementations for runtime put in own package
ddjanssen Jan 25, 2024
af21cb4
it is now possible to check if the thread holds a predicate with thes…
ddjanssen Jan 25, 2024
8b47bd7
Removed unused RewriteQuantifier.scala
ddjanssen Jan 25, 2024
f075939
Transferring predicates between threads work
ddjanssen Jan 25, 2024
d008f7c
Clean up of the CheckPermissionsBlocksMethod
ddjanssen Jan 25, 2024
d2908a8
Permissions are now initialized and locking is implemented as well
ddjanssen Jan 25, 2024
cecac30
Finalizing
ddjanssen Jan 25, 2024
bd4f1c1
Add ledger example
ddjanssen Jan 26, 2024
8881f20
Add ledger transformer
ddjanssen Jan 26, 2024
ff61e18
Create template for CreateLedger
ddjanssen Jan 26, 2024
332d0be
Using a ledger it is possible to store permissions
ddjanssen Jan 30, 2024
cc8b1e1
ADD: Ledger locations for PrimitiveTypes can now be inserted.
ddjanssen Jan 31, 2024
5da6406
Add join token to ledger
ddjanssen Jan 31, 2024
a6eaa70
Predicates can now be folded and unfolded
ddjanssen Jan 31, 2024
9ef71e0
Fix bug in checking permissions per blocks, if the final statement ha…
ddjanssen Jan 31, 2024
3587688
Arrays permissions are now also being initialized
ddjanssen Jan 31, 2024
e176a75
REMOVE: unnecessary code
ddjanssen Feb 7, 2024
33e3641
Merge remote-tracking branch 'origin/1-create-template-for-runtime-ve…
ddjanssen Feb 7, 2024
5365dc3
FIX: small bugs that are occurring while executing the tests
ddjanssen Feb 7, 2024
058932e
FIX: new array dimensions
ddjanssen Feb 12, 2024
5e63190
ADD: optional static to instanceMethod
ddjanssen Feb 12, 2024
aae5600
ADD: optional static to instanceMethod
ddjanssen Feb 12, 2024
c79a902
ADD: optional static to instanceMethod
ddjanssen Feb 12, 2024
12616e4
FIX: bug for library fraction
ddjanssen Feb 12, 2024
0ac2e35
FIX: bug naming for classes, procedure is now not taking the name any…
ddjanssen Feb 12, 2024
d7e53af
FIX: offset in quantifiers condition
ddjanssen Feb 12, 2024
fbd0f6a
FIX: bug permission on other fields of object
ddjanssen Feb 12, 2024
3400ceb
Change: predicates are now also in the ledger
ddjanssen Feb 13, 2024
c752ea8
Fix bug loop invariant
ddjanssen Feb 13, 2024
b64b25f
Fix final bugs
ddjanssen Feb 19, 2024
d7d9406
Fix final bugs
ddjanssen Feb 19, 2024
207b857
Fix final bugs
ddjanssen Feb 19, 2024
4fb25be
Fixed bugs and moved the GenerateJava to the codegeneration step to t…
ddjanssen Feb 22, 2024
717eba9
Fix injectivitymap check for duplicates
ddjanssen Feb 22, 2024
24a1755
Update message with line numbers
ddjanssen Feb 26, 2024
a7bac02
Fixed bugs (un)fold
ddjanssen Feb 27, 2024
a819229
Add comments to the code
ddjanssen Feb 27, 2024
822e74d
Fixed tiny bug in code
ddjanssen Mar 14, 2024
56fe703
Loopinvariant only check on continue keyword and not return or break …
ddjanssen Mar 25, 2024
5f3811f
Loopinvariant only check on continue or break keywords and not return…
ddjanssen Mar 25, 2024
17bce44
Should only be continue, checked again, also at other languages
ddjanssen Apr 3, 2024
d138138
Merge branch 'dev' into 1-create-template-for-runtime-verification
pieter-bos May 21, 2024
a81bbc2
fixes up to needing new-style constructors
pieter-bos May 22, 2024
e4a5f97
Merge branch 'dev' into 1-create-template-for-runtime-verification
pieter-bos May 22, 2024
cf52842
clean up some nodes
pieter-bos May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions examples/runtime/ledgerExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package test;

import java.lang.reflect.Array;
import java.util.concurrent.ConcurrentHashMap;


class Ledger {

public static ConcurrentHashMap<Long, ConcurrentHashMap<Object, Double>> __runtime__ = new ConcurrentHashMap<Long, ConcurrentHashMap<Object, Double>>();
public static ConcurrentHashMap<Object, ConcurrentHashMap<Integer, Object>> __array_locations = new ConcurrentHashMap<Object, ConcurrentHashMap<Integer, Object>>();


public static void createHashMap() {
if (!__runtime__.containsKey(Thread.currentThread().getId())) {
__runtime__.put(Thread.currentThread().getId(), new ConcurrentHashMap<Object, Double>());
}
}

public static Double getPermission(Object input) {
createHashMap();
return __runtime__.get(Thread.currentThread().getId()).getOrDefault(input, 0.0);
}

public static Double getPermission(Object input, int location) {
createHashMap();
Object permLoc = __array_locations.get(input).get(location);
return getPermission(permLoc);
}

public static void setPermission(Object input, Double value) {
assert (value >= 0 && value <= 1) : "value is not between bounds 0 and 1: " + value;
createHashMap();
__runtime__.get(Thread.currentThread().getId()).put(input, value);
}

public static void setPermission(Object input, int location, Double value) {
createHashMap();
assert (input.getClass().isArray());
Object permLoc = __array_locations.get(input).get(location);
setPermission(permLoc, value);
}

public static void initiatePermission(Object input) {
createHashMap();
setPermission(input, 1.0);
if (input.getClass().isArray()) {
initiatePermission(input, Array.getLength(input));
}
}

public static void initiatePermission(Object input, int size) {
createHashMap();
setPermission(input, 1.0);
__array_locations.put(input, new ConcurrentHashMap<>());
for (int i = 0; i < size; i++) {
Object[] permLoc = {input, i};
__array_locations.get(input).put(i, permLoc);
setPermission(permLoc, 1.0);
}

}
}


class Test extends Thread{
int[] a;
int b;

public Test(int[] a) {
this.a = a;
}

/*@
requires Perm(this.a, write);
*/
@Override
public void run() {
Ledger.setPermission(this.a, 1.0);
System.out.println("External thread: " + Ledger.getPermission(this.a));
super.run();
}
}


class Main {

public static void main(String[] args) {
int[] a = new int[]{1, 2, 3, 4};
Ledger.initiatePermission(a);
Test test = new Test(a);
Ledger.setPermission(test.a, Ledger.getPermission(test.a) - 1.0);
test.start();
Ledger.initiatePermission(test, 1);
System.out.println(Ledger.getPermission(test.a));
System.out.println(Ledger.getPermission(test, 0));
}
}

16 changes: 16 additions & 0 deletions examples/runtime/lockInvariant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@ lock_invariant Perm(this.i, write);
class Source {
int i;

public void test(){
int x = this.i;
synchronized (this) {
this.i = 0;
}
}

public void main() {
Source source = new Source();
source.test();
}
}
29 changes: 29 additions & 0 deletions examples/runtime/loopInvariants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Program {
int[] a;

public void setA(int[] a) {
this.a = a;
}

public int indexOf(int b) {
//@ loop_invariant i <= a.length;
//@ loop_invariant (\forall* int j; 0 <= j && j < a.length; Perm(a[j], read));
//@ loop_invariant (\forall int j; 0 <= j && j < a.length; a[j] % 3 == 0);
for(int i = 0; i < a.length; i++) {
if(a[i] == b) {
return i;
}
}
return -1;
}

public void main() {
Program program = new Program();
int[] tmp = new int[3];
tmp[0] = 2;
tmp[1] = 4;
tmp[2] = 6;
program.setA(tmp);
program.indexOf(4);
}
}
39 changes: 39 additions & 0 deletions examples/runtime/predicates.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
public class Main {

//@ requires c != null ** c.state(0);
//@ ensures c.state(2);
void foo(Counter c) {
c.increment(2);
}

public void execute() {
Counter c = new Counter();
//@ fold c.state(0);
Counter c2 = new Counter();
//@ fold c2.state(0);

foo(c);
foo(c2);
}

public void main() {
Main m = new Main();
m.execute();
}
}


class Counter {
int count;

//@ resource state(int val) = Perm(count, write) ** count == val;

//@ requires state(count);
//@ ensures state(count);
void increment(int n) {
int z = count;
//@ unfold state(count);
count += n;
//@ fold state(count);
};
}
40 changes: 40 additions & 0 deletions examples/runtime/quantifiers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
class Program {
int[] a;
int b;


/*@
requires (\forall* int i; 0 <= i && i < a.length; Perm(a[i], write));
*/
public void setA(int[] a) {
this.a = a;
}

/*@
requires a.length > 0;
requires (\forall* int x; 0 <= x && x < a.length; Perm(a[x], write));
requires (\forall int x; 0 <= x && x < a.length; a[x] > 0);
requires (\forall int x; 0 <= x && x < a.length; (\forall int j; 0 <= j && j < x; a[j] >= a[x]));
ensures (\forall* int x; 0 <= x && x < a.length; Perm(a[x], write));
ensures (\exists int x; 0 <= x && x < a.length; a[x] > 0);
*/
//ensures (\exists int x; 0 <= x && x < a.length; a[x] == b) ==> \result >= 0;
public int indexOf(int b) {
for (int i = 0; i < a.length; i++) {
if (a[i] == b) {
return i;
}
}
return -1;
}

public void main() {
Program program = new Program();
int[] tmp = new int[3];
tmp[0] = 2;
tmp[1] = 4;
tmp[2] = 6;
program.setA(tmp);
program.indexOf(4);
}
}
62 changes: 62 additions & 0 deletions examples/runtime/sinksource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import java.util.*;


class Source extends Thread {
int i;

/*@
requires Perm(this.i, 1);
ensures Perm(this.i, 1);
*/
public void run() {
i = 42;
}

public void join(){}
public void start(){}
}

class Sink extends Thread {
Source source;

public void setSource(Source source) {
this.source = source;
}

/*@
requires Perm(source, 1);
ensures Perm(source, 1);
ensures Perm(source.i, 1/2);
*/
public void run() {

//@ source.postJoin(1\2);
source.join();
source.i = 1;
}

public void join(){}
public void start(){}
}

class Main{

public void main() {
Source source = new Source();
Sink sink = new Sink();
sink.setSource(source);

sink.source.i = 1;
source.start();
sink.start();
//@ source.postJoin(1\2);
source.join();
//@ sink.postJoin(1);
sink.join();
source.i = 1988;
}
}

class Thread{

}
67 changes: 67 additions & 0 deletions examples/runtime/sinksourcearray.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
class Source extends Thread {
int[] i;

public void createI() {
this.i = new int[2];
}

/*@
requires Perm(this.i, 1);
requires (\forall* int j; 0 <= j && j < i.length; Perm(i[j], write));
ensures Perm(this.i, 1);
ensures (\forall* int j; 0 <= j && j < i.length; Perm(i[j], write));
*/
public void run() {
i[0] = 42;
i[1] = 43;
}


public void join(){}
public void start(){}
}

class Sink extends Thread {
Source source;

public void setSource(Source source) {
this.source = source;
}

/*@
requires Perm(source, 1);
ensures Perm(source, 1);
ensures Perm(source.i, 1/2);
ensures (\forall* int j; 0 <= j && j < source.i.length ==> Perm(source.i[j], 1/2));
*/
public void run() {
//@ source.postJoin(1\2);
source.join();
source.i[0] = 1;
}

public void join(){}
public void start(){}
}

class Main{

public void main() {
Source source = new Source();
Sink sink = new Sink();
sink.setSource(source);
source.createI();

source.start();
sink.start();
//@ source.postJoin(1/2);
source.join();
//@ sink.postJoin(1);
sink.join();
source.i[0] = 1988;
}
}

class Thread{

}
30 changes: 30 additions & 0 deletions examples/runtime/sinksourcearrayobjects.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class DummyData {
int val;
}

class Source {
DummyData[] i;

public void createI() {
this.i = new DummyData[2];
DummyData o = new DummyData();
this.i[0] = o;
this.i[1] = o;
}

/*@
requires Perm(this.i, 1);
requires (\forall* int j; 0 <= j && j < i.length; Perm(i[j].val, write));
ensures Perm(this.i, 1);
ensures (\forall* int j; 0 <= j && j < i.length; Perm(i[j].val, write));
*/
public void test() {

}

public void main(){
Source source = new Source();
source.createI();
source.test();
}
}
Loading
Loading