Skip to content
Open

Asn1 #294

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
158 commits
Select commit Hold shift + click to select a range
3c9ad83
add build folder to gitingore
gewlar Sep 10, 2025
0204b54
Start working on bytearray implementation
gewlar Sep 11, 2025
4682cc3
Merge remote-tracking branch 'origin/master' into asn1
gewlar Sep 11, 2025
612d0cd
Print name of unsupported function
gewlar Sep 15, 2025
9fdbca8
Trying call extension
gewlar Sep 15, 2025
f2465f0
Working implementation for empty bytearray constructor
gewlar Sep 16, 2025
86db8f3
Working bytearray from bytearray and append method
gewlar Sep 17, 2025
10439f5
Extending bytearray support
gewlar Sep 18, 2025
bd4517c
Add special predicate for access to bytearray
gewlar Sep 19, 2025
7edab59
Implement Iterator for bytearray
gewlar Sep 19, 2025
e9d7133
Update builtins.json
gewlar Sep 19, 2025
9160e1e
Add lshift to bitwise operations
gewlar Sep 23, 2025
0fd24d6
Adjust error messages for bytearray bounds
gewlar Sep 23, 2025
9480b7b
Get __initFromList__ working
gewlar Sep 24, 2025
e0d18e1
Clean up call.py
gewlar Sep 24, 2025
27365c6
Add tests for bytearray
gewlar Sep 25, 2025
32dbda1
Fix Low conditions
gewlar Sep 26, 2025
c0ef41c
Extend bytearray tests
gewlar Sep 26, 2025
c66ffae
Add tests for lshift and fix negative inputs
gewlar Sep 26, 2025
93689d9
fix: spelling mistake
gewlar Sep 26, 2025
45f5531
Add dummy implementation for formatted strings
gewlar Sep 26, 2025
8b369b1
Partial support for right shift
gewlar Sep 29, 2025
bbe4219
Disable right shift of negative numbers
gewlar Sep 29, 2025
6a83817
Attempting to enable Unfold statements in pure functions
marcoeilers Sep 30, 2025
d5d4ed1
Merge remote-tracking branch 'origin/master' into asn1
gewlar Sep 30, 2025
27b9290
Merge remote-tracking branch 'origin/unfold_in_pure_functions' into asn1
gewlar Oct 1, 2025
dd5af62
Checking type of assign during _assign_with_subscript
gewlar Oct 1, 2025
921418b
Ignore sign bit for bitvector operations
gewlar Oct 1, 2025
dba26d2
Adjust tests for larget bitsize
gewlar Oct 2, 2025
b60a507
Add eq content check for bytearray
gewlar Oct 2, 2025
7f11081
Merge remote-tracking branch 'origin/master' into asn1
gewlar Oct 7, 2025
ab16a01
Simplify bytearray___eq__
gewlar Oct 7, 2025
e629041
Merge remote-tracking branch 'origin/master' into asn1
gewlar Oct 8, 2025
961e7fc
Progress on adding PIntSeq
gewlar Oct 8, 2025
2fd7ba7
Add PIntSeq
gewlar Oct 8, 2025
c6f906b
Add helper method range to PSeq and PIntSeq
gewlar Oct 8, 2025
429aab4
Add special implementation to ToIntSeq for bytearray and bytes
gewlar Oct 10, 2025
cea14aa
Repurpose PIntSeq as PByteSeq
gewlar Oct 10, 2025
0cc53f0
Use prim_int for bytearray setitem
gewlar Oct 14, 2025
f1d3f53
Use multiplication for lshift of at most 8 bits
gewlar Oct 14, 2025
a36755e
Allow preprocessing of comments
gewlar Oct 15, 2025
268ae52
Add decreases clause to functions generated for constants
gewlar Oct 17, 2025
9bdba4c
Vscode task to debug verification
gewlar Oct 22, 2025
f0580b3
Merge remote-tracking branch 'origin/master' into asn1
gewlar Oct 22, 2025
fe7b95e
Merge remote-tracking branch 'origin/master' into asn1
gewlar Oct 27, 2025
3200da5
Use any version of pytest
gewlar Oct 27, 2025
9ce7e1c
WIP bitwise operations
gewlar Oct 27, 2025
5022a11
Implement PByteSeq_int_get_bit with direct handling on bit vectors
gewlar Oct 27, 2025
d4d205f
Simplify bit and byte operations
gewlar Oct 28, 2025
f70176d
Providing a simple (not sound yet) way to mark parameters as primitives
marcoeilers Nov 11, 2025
7155b22
Remove range for now
gewlar Nov 11, 2025
e2d7ca9
Merge remote-tracking branch 'origin/prim_int_args' into asn1
gewlar Nov 11, 2025
3f39df7
Fix requirements for PByteSeq
gewlar Nov 11, 2025
5cc4cbf
Allow unrestricted lshift and rshift for shift values <= 8
gewlar Nov 12, 2025
357d572
Merge remote-tracking branch 'origin/master' into asn1
gewlar Nov 17, 2025
de18898
Remove unused byte operations
gewlar Nov 26, 2025
e830d8e
Apply preprocessing before mypy akin to analyzer
gewlar Nov 27, 2025
9161f52
Merge branch 'asn1' of https://github.com/marcoeilers/nagini into asn1
gewlar Nov 27, 2025
f14911d
Merge remote-tracking branch 'origin/master' into asn1
gewlar Nov 28, 2025
1431968
Reapply primitive type usage for arguments
gewlar Nov 28, 2025
5a98926
Fix merge issues
gewlar Nov 28, 2025
997648b
Fix bytearray hex and adjust test
gewlar Nov 28, 2025
f297fa1
Merge remote-tracking branch 'origin/master' into asn1
gewlar Dec 1, 2025
5f7f5ed
Add primitive int version for shift
gewlar Dec 2, 2025
f41d774
Support basic frozen dataclasses
gewlar Dec 3, 2025
acb2577
Remove legacy preprocessing flag
gewlar Dec 4, 2025
5bd21ff
IntEnum WIP
gewlar Dec 6, 2025
eebb1c3
WIP
gewlar Dec 9, 2025
2d819f3
Fix dataclass for arrays
gewlar Dec 10, 2025
807c10f
IntEnum WIP
gewlar Dec 12, 2025
f12af0e
Working IntEnum for equality checks on instances
gewlar Dec 12, 2025
a322375
Use box function for construction of enum
gewlar Dec 15, 2025
a389d38
Resolve mypy LiteralType
gewlar Dec 16, 2025
7ab9827
Mark IntEnum as subclass of int.
gewlar Dec 16, 2025
9a3bc02
Add precondition for box function of IntEnum
gewlar Dec 16, 2025
8ccd26f
Merge remote-tracking branch 'origin/master' into asn1
gewlar Dec 17, 2025
886852f
Add tests for named parameters
gewlar Dec 17, 2025
abd6351
Merge remote-tracking branch 'origin/master' into asn1
gewlar Dec 18, 2025
54b4d22
Fix failing tests due to illegal id access
gewlar Dec 18, 2025
e9883b5
Workaround for preprocessing
gewlar Dec 18, 2025
61c356f
Allow default values for dataclass fields
gewlar Dec 19, 2025
943af7e
Merge branch 'asn1' of github.com:marcoeilers/nagini into asn1
gewlar Dec 22, 2025
62f9fea
Add IntEnum to list of allowed extendable builtins
gewlar Dec 22, 2025
d58b358
Consider dataclass __post_init__ function
gewlar Jan 2, 2026
2e67938
Check for existing fields on superclass
gewlar Jan 5, 2026
cb2983a
Merge remote-tracking branch 'origin/master' into asn1
gewlar Jan 6, 2026
dfade3c
Fix constructor call for type argument change
gewlar Jan 6, 2026
f295ae0
Merge remote-tracking branch 'origin/master' into asn1
gewlar Jan 6, 2026
548a407
Merge remote-tracking branch 'origin/master' into asn1
gewlar Jan 8, 2026
e195207
Extend fix for #266 to union types
gewlar Jan 8, 2026
ca61a36
Merge remote-tracking branch 'origin/master' into asn1
gewlar Jan 9, 2026
de5feda
Extend shift operations to 64 bit, support int.bit_length()
gewlar Jan 9, 2026
c936624
Actually use extension to shift operations
gewlar Jan 11, 2026
cf91f9c
Mark abstractmethods as ContractOnly
gewlar Jan 17, 2026
398ecdd
Merge remote-tracking branch 'origin/master' into asn1
gewlar Jan 19, 2026
fdcf231
Merge remote-tracking branch 'origin/master' into asn1
gewlar Jan 19, 2026
0d6f0ea
Print more info for Analyzer type exception
gewlar Jan 19, 2026
0140c1e
Fixing #275 and #276
marcoeilers Jan 19, 2026
fa9fde2
Same fix for function calls
marcoeilers Jan 19, 2026
b91e97e
Merge remote-tracking branch 'origin/fix_275' into asn1
gewlar Jan 19, 2026
254d282
Merge remote-tracking branch 'origin/master' into asn1
gewlar Jan 19, 2026
aba9265
Merge remote-tracking branch 'origin/master' into asn1
gewlar Jan 20, 2026
9282a1a
Merge remote-tracking branch 'origin/master' into asn1
gewlar Jan 23, 2026
0661758
Fix error with non-existing method_name
gewlar Jan 23, 2026
c1a98c9
Fix context for self in dataclass properties
gewlar Jan 23, 2026
aaee70f
New approach for preprocessing mode
gewlar Jan 23, 2026
23907a3
Ingoring preprocessing for the moment
gewlar Jan 24, 2026
f4d1b47
Add base-dir when launch from vscode
gewlar Jan 26, 2026
6a8dc85
Clean up legacy handling for abstract methods
gewlar Jan 28, 2026
e62ea99
Slightly strength sequence take and drop functions
gewlar Feb 3, 2026
a2899f5
Merge branch 'asn1' of https://github.com/marcoeilers/nagini into asn1
gewlar Feb 4, 2026
d1bc6c1
Add handling for hash
gewlar Feb 4, 2026
efd5216
Launch files with parent directory as base-dir
gewlar Feb 4, 2026
5979334
Fix pbyteseq
gewlar Feb 5, 2026
ea42cc4
Copy changes for pseq to pbyteseq
gewlar Feb 5, 2026
811d36a
Add simple byteseq interop test
gewlar Feb 5, 2026
5f40542
Merge __str__ changes, add __repr__
gewlar Feb 6, 2026
9a3a82a
Stronger type information about ADTs
marcoeilers Feb 11, 2026
2a9e2e5
Better tests
marcoeilers Feb 11, 2026
8e0c42b
Merge remote-tracking branch 'origin/fix_adts' into asn1
gewlar Feb 11, 2026
23f65da
Disallow extending enumerations, which isn't caught by mypy
gewlar Feb 12, 2026
f6b8006
Adjust expected error type
gewlar Feb 12, 2026
88daee9
Expand handling for IntEnum
gewlar Feb 12, 2026
4cc62c4
Allow ast.Attribute usage for default value in dataclasses
gewlar Feb 16, 2026
4dea086
Use enum unbox function for int conversion call
gewlar Feb 16, 2026
9acf51a
Workaround for Union types
gewlar Feb 16, 2026
b79a51c
Remove legacy range test
gewlar Feb 16, 2026
a731704
Add reverse postcondition for int sequence conversion
gewlar Feb 16, 2026
ccd2655
Rename IntEnum __unbox__ to __int__ and register as viper function
gewlar Feb 17, 2026
49625cc
More dataclass tests
gewlar Feb 18, 2026
b6ef671
Improve dataclass decorator handling
gewlar Feb 18, 2026
e49a8b5
Support field with default_factory=list for dataclass
gewlar Feb 18, 2026
c2af5a0
Use value equality handling for lists
gewlar Feb 22, 2026
6261b4a
Add tests for contained list of dataclasses
gewlar Feb 22, 2026
3ba9f0a
Extend list equality check
gewlar Feb 22, 2026
a24c8f2
Add test for desired property
gewlar Feb 23, 2026
a52d420
Trying out using simplified e1 in e2.list_acc expressions only in tri…
marcoeilers Feb 24, 2026
4ebb655
Adding test
marcoeilers Feb 24, 2026
91b4c44
Fixing crashes
marcoeilers Feb 24, 2026
db80e6c
Doing the same for existentials
marcoeilers Feb 24, 2026
4537ac4
Test for existentials, some comments to explain what's happening
marcoeilers Feb 24, 2026
2e68745
Using both expressions as triggers
marcoeilers Feb 24, 2026
709e3a4
Fix failing tests
gewlar Feb 24, 2026
8763511
Trying stuff
marcoeilers Feb 25, 2026
66d4be1
Fixing things
marcoeilers Feb 25, 2026
fee7e79
Additional trigger for __seq_ref_to_seq_int
gewlar Feb 26, 2026
fe19cb9
Merge remote-tracking branch 'origin/master' into asn1
gewlar Feb 26, 2026
1769f8c
Merge remote-tracking branch 'origin/master' into asn1
gewlar Feb 27, 2026
eab1071
Merge branch 'master' into trying_trigger_stuff
marcoeilers Feb 27, 2026
f4573eb
Merge remote-tracking branch 'origin/trying_trigger_stuff' into asn1
gewlar Feb 27, 2026
84ac73c
Add argument for time limit to benchmark
gewlar Feb 27, 2026
a305167
Use threads for benchmark to reliably stop them
gewlar Feb 28, 2026
a098731
Accumulate benchmark results
gewlar Feb 28, 2026
1860395
Fix name overwrite in benchmark
gewlar Feb 28, 2026
e6b837c
Fixing let expression crash
marcoeilers Mar 3, 2026
c697778
Add support for non-frozen dataclasses
gewlar Mar 7, 2026
b60e75d
Merge remote-tracking branch 'origin/trying_trigger_stuff' into asn1
gewlar Mar 17, 2026
ea43a7e
Revert "Fixing things"
gewlar Mar 17, 2026
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
syntax: glob
env
bin
build
deps/JPype1
__pycache__
.virtualenv
Expand All @@ -14,4 +15,4 @@ tmp
docs/build
.idea
*.pyc
viper_out
viper_out
21 changes: 9 additions & 12 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,20 @@
},
{
"name": "Debug Nagini verifying Python",
"type": "python",
"type": "debugpy",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${workspaceRoot}/nagini/env/bin/python3",
"program": "${workspaceRoot}/nagini/env/bin/nagini",
"program": "${workspaceFolder}/src/nagini_translation/main.py",
"args": [
"--base-dir=${fileDirname}/..",
"${file}"
],
"cwd": "${workspaceRoot}",
"env": {},
"envFile": "${workspaceRoot}/.env",
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
"justMyCode": false,
"python": "${command:python.interpreterPath}",
"env": {
"PYTHONPATH": "${workspaceFolder}/src"
}
},
{
"name": "Translate Python to Viper",
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
'toposort==1.5',
'jpype1==1.5.0',
'astunparse==1.6.2',
'pytest==7.0.0',
'z3-solver==4.8.7.0'
'pytest',
'z3-solver==4.8.7.0',
'setuptools==68.2.0'
],
entry_points={
'console_scripts': [
Expand Down
84 changes: 83 additions & 1 deletion src/nagini_contracts/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
CONTRACT_FUNCS = ['Assume', 'Assert', 'Old', 'Result', 'ResultT', 'Implies', 'Forall', 'IOForall', 'Forall2', 'Forall3', 'Forall6',
'Exists', 'Low', 'LowVal', 'LowEvent', 'Declassify', 'TerminatesSif',
'Acc', 'Rd', 'Wildcard', 'Fold', 'Unfold', 'Unfolding', 'Previous',
'RaisedException', 'PSeq', 'PSet', 'ToSeq', 'ToMS', 'MaySet', 'MayCreate',
'RaisedException', 'PSeq', 'PByteSeq', 'PSet', 'ToSeq', 'ToByteSeq', 'ToMS', 'MaySet', 'MayCreate',
'getMethod', 'getArg', 'getOld', 'arg', 'Joinable', 'MayStart', 'Let',
'PMultiset', 'LowExit', 'Refute', 'isNaN', 'Reveal']

Expand Down Expand Up @@ -205,6 +205,10 @@ def TerminatesSif(cond: bool, rank: int) -> bool:
"""
pass

PBool = bool

PInt = int

class PSeq(Generic[T], Sized, Iterable[T]):
"""
A PSeq[T] represents a pure sequence of instances of subtypes of T, and
Expand Down Expand Up @@ -265,6 +269,66 @@ def __iter__(self) -> Iterator[T]:
can be used as arguments for Forall.
"""

class PByteSeq(Sized, Iterable[int]):
"""
A PByteSeq represents a pure sequence of instances of int, and
is translated to native Viper sequences.
"""

def __init__(self, *args: int) -> None:
"""
``PByteSeq(a, b, c)`` creates a PByteSeq instance containing the objects
a, b and c in that order.
"""

def __contains__(self, item: object) -> bool:
"""
True iff this PByteSeq contains the given object (not taking ``__eq__``
into account).
"""

def __getitem__(self, item: int) -> int:
"""
Returns the item at the given position.
"""

def __len__(self) -> int:
"""
Returns the length of this PByteSeq.
"""

def __add__(self, other: 'PByteSeq') -> 'PByteSeq':
"""
Concatenates two PByteSeqs to get a new PByteSeq.
"""

def take(self, until: int) -> 'PByteSeq':
"""
Returns a new PByteSeq containing all elements starting
from the beginning until the given index. ``PByteSeq(3,2,5,6).take(3)``
is equal to ``PByteSeq(3,2,5)``.
"""

def drop(self, until: int) -> 'PByteSeq':
"""
Returns a new PByteSeq containing all elements starting
from the given index (i.e., drops all elements until that index).
``PByteSeq(2,3,5,6).drop(2)`` is equal to ``PByteSeq(5,6)``.
"""

def update(self, index: int, new_val: int) -> 'PByteSeq':
"""
Returns a new PByteSeq, containing the same elements
except for the element at index ``index``, which is replaced by
``new_val``.
"""

def __iter__(self) -> Iterator[int]:
"""
PByteSeqs can be quantified over; this is only here so thatPByteSeqs
can be used as arguments for Forall.
"""

def Previous(it: T) -> PSeq[T]:
"""
Within the body of a loop 'for x in xs', Previous(x) represents the list of
Expand Down Expand Up @@ -356,6 +420,12 @@ def ToSeq(l: Iterable[T]) -> PSeq[T]:
Converts the given iterable of a built-in type (list, set, dict, range) to
a pure PSeq.
"""

def ToByteSeq(l: Iterable[int]) -> PByteSeq:
"""
Converts the given iterable of a compatible built-in type (bytearray) to
a pure PByteSeq.
"""


def ToMS(s: PSeq[T]) -> PMultiset[T]:
Expand Down Expand Up @@ -542,6 +612,13 @@ def dict_pred(d: object) -> bool:
be folded or unfolded.
"""

def bytearray_pred(d: object) -> bool:
"""
Special, predefined predicate that represents the permissions belonging
to a bytearray. To be used like normal predicates, except it does not need to
be folded or unfolded.
"""

def isNaN(f: float) -> bool:
pass

Expand Down Expand Up @@ -595,10 +672,15 @@ def isNaN(f: float) -> bool:
'list_pred',
'dict_pred',
'set_pred',
'bytearray_pred',
'PBool',
'PInt',
'PSeq',
'PByteSeq',
'PSet',
'PMultiset',
'ToSeq',
'ToByteSeq',
'ToMS',
'MaySet',
'MayCreate',
Expand Down
Loading
Loading