Skip to content

Commit 7f5f579

Browse files
authored
Merge pull request #2 from henriman/sif-private-topology
Verify `private/topology`
2 parents 4d936ca + c72c877 commit 7f5f579

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

private/topology/linktype.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/scionproto/scion/pkg/private/serrors"
2424
//@ . "github.com/scionproto/scion/verification/utils/definitions"
2525
//@ sl "github.com/scionproto/scion/verification/utils/slices"
26+
//@ "github.com/scionproto/scion/verification/utils/sif"
2627
)
2728

2829
// LinkType describes inter-AS links.
@@ -44,6 +45,7 @@ const (
4445
Peer LinkType = 4
4546
)
4647

48+
// @ requires low(l)
4749
// @ decreases
4850
func (l LinkType) String() string {
4951
if l == Unset {
@@ -59,6 +61,7 @@ func (l LinkType) String() string {
5961

6062
// LinkTypeFromString returns the numerical link type associated with a string description. If the
6163
// string is not recognized, an Unset link type is returned. The matching is case-insensitive.
64+
// @ requires low(s)
6265
// @ decreases
6366
func LinkTypeFromString(s string) (res LinkType) {
6467
var l /*@@@*/ LinkType
@@ -70,6 +73,7 @@ func LinkTypeFromString(s string) (res LinkType) {
7073
return l
7174
}
7275

76+
// @ requires low(l)
7377
// @ ensures (l == Core || l == Parent || l == Child || l == Peer) == (err == nil)
7478
// @ ensures err == nil ==> sl.Bytes(res, 0, len(res))
7579
// @ ensures err != nil ==> err.ErrorMem()
@@ -97,13 +101,21 @@ func (l LinkType) MarshalText() (res []byte, err error) {
97101
}
98102
}
99103

104+
// @ requires acc(sl.Bytes(data, 0, len(data)), R15)
105+
// @ requires low(len(data)) &&
106+
// @ forall i int :: { sl.GetByte(data, 0, len(data), i) } 0 <= i && i < len(data) && low(i) ==>
107+
// @ low(sl.GetByte(data, 0, len(data), i))
100108
// @ preserves acc(l)
101-
// @ preserves acc(sl.Bytes(data, 0, len(data)), R15)
109+
// @ ensures acc(sl.Bytes(data, 0, len(data)), R15)
102110
// @ ensures err != nil ==> err.ErrorMem()
111+
// @ ensures low(err != nil)
103112
// @ decreases
104113
func (l *LinkType) UnmarshalText(data []byte) (err error) {
105-
//@ unfold acc(sl.Bytes(data, 0, len(data)), R15)
106-
//@ ghost defer fold acc(sl.Bytes(data, 0, len(data)), R15)
114+
//@ unfold acc(sl.Bytes(data, 0, len(data)), R16)
115+
//@ ghost defer fold acc(sl.Bytes(data, 0, len(data)), R16)
116+
//@ assert forall i int :: { &data[i] } 0 <= i && i < len(data) ==>
117+
//@ sl.GetByte(data, 0, len(data), i) == data[i]
118+
//@ sif.LowSliceImpliesLowString(data, R16)
107119
switch strings.ToLower(string(data)) {
108120
case "core":
109121
*l = Core
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// +gobra
2+
3+
package sif
4+
5+
// TODO: Once Gobra issue #832 is resolved, introduce body and prove this.
6+
ghost
7+
requires p > 0 && acc(b, p)
8+
requires low(len(b)) && forall i int :: { &b[i] } 0 <= i && i < len(b) && low(i) ==> low(b[i])
9+
ensures acc(b, p) && low(string(b))
10+
decreases
11+
func LowSliceImpliesLowString(b []byte, p perm)

0 commit comments

Comments
 (0)