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

Verify the IO behavior (a.k.a., basis PR) #248

Merged
merged 111 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
0aa5841
manually trigger workflow
mlimbeck Jun 20, 2023
8525b7c
manually trigger workflow
mlimbeck Jun 20, 2023
2eaf7a4
raw byte to spec for segments and hopfields
mlimbeck Jul 4, 2023
e9d31ae
bugfix
mlimbeck Jul 4, 2023
6b77cb6
import fix
mlimbeck Jul 4, 2023
e9631e0
bugfix after gobra update
mlimbeck Jul 10, 2023
bd062dc
spec to pkt (currSeg)
mlimbeck Jul 10, 2023
3246a2b
spec to pkt (left, mid, right)
mlimbeck Jul 11, 2023
35ff392
spec to pkt (termination)
mlimbeck Jul 11, 2023
f925f10
code clean up
mlimbeck Jul 17, 2023
6a19edf
Merge branch 'viperproject:master' into master
mlimbeck Jul 17, 2023
3d90011
clean up
mlimbeck Jul 17, 2023
6e8f884
improvements
mlimbeck Jul 18, 2023
afe9e52
instantiate abstract functions with bodies
mlimbeck Jul 19, 2023
de241b5
progress io spec
mlimbeck Jul 19, 2023
8a0452e
formatting
mlimbeck Jul 24, 2023
4540095
specification fixes
mlimbeck Jul 24, 2023
bf2c331
improve IO-spec
mlimbeck Jul 24, 2023
53cadc9
IO-spec to pkt rewritten
mlimbeck Jul 24, 2023
790e842
clean up
mlimbeck Jul 24, 2023
ca581db
improve readability
mlimbeck Jul 28, 2023
0d3cc57
Merge branch 'master' into master
jcp19 Sep 28, 2023
01eade7
Merge branch 'master' into master
jcp19 Oct 17, 2023
bfd6c2f
rename of function lengthOfCurrSeg
mlimbeck Nov 1, 2023
8c7b6c1
Merge remote-tracking branch 'remotescion/master'
mlimbeck Nov 14, 2023
89997c6
Merge remote-tracking branch 'remotescion/master'
mlimbeck Nov 15, 2023
f1cf0b1
extract asid-seqence from raw pkt
mlimbeck Nov 16, 2023
4343478
missing trigger
mlimbeck Nov 16, 2023
715fa51
quick fix
mlimbeck Nov 16, 2023
b051f09
Update router/dataplane_spec.gobra
mlimbeck Nov 17, 2023
7cbe9d6
Apply suggestions from code review
mlimbeck Nov 22, 2023
689e9da
readability improvements
mlimbeck Nov 22, 2023
24d19e1
further improvements
mlimbeck Nov 22, 2023
e923c40
replace 4 by its constant InfoLen
mlimbeck Nov 22, 2023
45b432e
readability improvement
mlimbeck Nov 22, 2023
8f15113
constant for metaLen in package path
mlimbeck Nov 22, 2023
503b0e0
Update router/io-spec.gobra
mlimbeck Nov 22, 2023
c292a84
minor improvements
mlimbeck Nov 22, 2023
a68a3e7
move validMetaLenInPath() to test file
mlimbeck Nov 22, 2023
ff00b89
Merge remote-tracking branch 'remotescion/master'
mlimbeck Dec 12, 2023
4e85c1f
io-spec in Run
mlimbeck Dec 12, 2023
cd887c9
Merge branch 'master' into io-spec-in-Run
jcp19 Dec 21, 2023
81b951a
Merge branch 'master' into io-spec-in-Run
jcp19 Jan 16, 2024
8d468b8
Merge remote-tracking branch 'remotescion/master' into io-spec-in-Run
mlimbeck Feb 7, 2024
b92ee32
add body to absIO_val
mlimbeck Feb 7, 2024
2f250fb
Merge branch 'io-spec-in-Run' of https://github.com/mlimbeck/Verified…
mlimbeck Feb 7, 2024
95af227
fix merge mistake
mlimbeck Feb 7, 2024
00d92c5
fix merge mistake
mlimbeck Feb 8, 2024
8c57264
fix typo
mlimbeck Feb 8, 2024
1c1850b
io-spec skeleton for processPkt and processSCION
mlimbeck Feb 8, 2024
4ccdab1
import fix
mlimbeck Feb 8, 2024
3161a68
Update router/io-spec.gobra
mlimbeck Feb 8, 2024
92b4a1a
Merge branch 'io-spec-in-Run' into unsupported
Dspil Feb 13, 2024
9680dd6
unit
Dspil Feb 15, 2024
50beee9
well formdness
Dspil Feb 15, 2024
8300ead
relate dataplane with dataplaneSpec
mlimbeck Feb 15, 2024
468fab7
Merge remote-tracking branch 'remotescion/master' into io-spec-in-Run
mlimbeck Feb 19, 2024
cdd2ce8
various fixes
mlimbeck Feb 19, 2024
7eca4dc
Update verification/io/values.gobra
jcp19 Feb 19, 2024
67a4d5d
permission fix for dpSpecWellConfigured
mlimbeck Feb 19, 2024
de48fa1
permission fix in rc
mlimbeck Feb 19, 2024
f892030
fix verification error
mlimbeck Feb 19, 2024
9258b54
Merge branch 'master' into io-spec-in-Run
jcp19 Feb 19, 2024
7df48b8
dp.Valid() as opaque
mlimbeck Feb 19, 2024
1560668
merge master
jcp19 Feb 20, 2024
1a9daf3
backup
jcp19 Feb 20, 2024
0160b2c
format spacing
jcp19 Feb 20, 2024
465553b
improve perf; drop assumption
jcp19 Feb 20, 2024
71866b2
fix formatting
jcp19 Feb 20, 2024
0a4c77d
Merge branch 'joao-continue-markus-pr-iospec' into io_spec_verification
Dspil Feb 20, 2024
ea7c499
merge master
jcp19 Feb 23, 2024
f07073e
Update router/dataplane.go
jcp19 Feb 23, 2024
d6b8d33
Merge branch 'master' into io_spec_verification
mlimbeck Feb 27, 2024
384661e
formatting postconditions of processPkt, processSCION
mlimbeck Feb 27, 2024
8514223
fix extra permission
Dspil Feb 27, 2024
c27a66a
typo
Dspil Feb 27, 2024
71aadfe
processSCION had the same issue
Dspil Feb 27, 2024
88db3fd
ingressID is preseved intead of sInit
Dspil Feb 27, 2024
8383408
Revert "ingressID is preseved intead of sInit"
Dspil Feb 27, 2024
ab5e91f
Revert "processSCION had the same issue"
Dspil Feb 27, 2024
2c08fb3
Updated IO-Spec-Function to Correlate Bytes with Terms (#262)
mlimbeck Feb 27, 2024
39330b5
made absIO_val opaque
Dspil Feb 28, 2024
99bd1e6
Merge branch 'master' into io_spec_verification
jcp19 Mar 14, 2024
7d13caf
Merge branch 'io_spec_verification' of github.com:viperproject/Verifi…
jcp19 Mar 14, 2024
e733dc8
Merge branch 'master' into io_spec_verification
jcp19 Mar 14, 2024
005fa2a
Merge branch 'master' into io_spec_verification
jcp19 Mar 17, 2024
98a867b
use artificial triggers for quantifiers inside IO resources (#280)
jcp19 Mar 18, 2024
ebf95fb
Merge branch 'master' into io_spec_verification
jcp19 Mar 18, 2024
baa1bb6
Merge branch 'master' into io_spec_verification
jcp19 Mar 18, 2024
72a5aec
AbsPkt improvements (#270)
mlimbeck Mar 18, 2024
c9c16c7
Merge branch 'master' into io_spec_verification
jcp19 Mar 18, 2024
e40741a
Merge branch 'master' into io_spec_verification
jcp19 Mar 25, 2024
2c509cc
Verify send guard in Run (#263)
mlimbeck Mar 25, 2024
bc7494b
Merge branch 'master' into io_spec_verification
jcp19 Mar 25, 2024
431a897
Merge branch 'master' into io_spec_verification
jcp19 Mar 28, 2024
045d57e
Merge branch 'master' into io_spec_verification
jcp19 Apr 2, 2024
e49b959
Merge branch 'master' into io_spec_verification
jcp19 Apr 2, 2024
60bbbf8
Merge branch 'master' into io_spec_verification
jcp19 Apr 3, 2024
1349d7a
IO specification skeleton in process (#284)
mlimbeck Apr 3, 2024
5ae6bfd
Add functional spec to `InfoField.SerializeTo` (#300)
jcp19 Apr 4, 2024
7ea708c
Missing Postcondition in Process (#301)
mlimbeck Apr 4, 2024
003bb51
Drop unnecessary function `hopFieldsNotConsDir` (#303)
Dspil Apr 5, 2024
d512053
Update IO-spec to drop the `xover_core` event (#302)
mlimbeck Apr 5, 2024
f3ff7a0
merge master
jcp19 Apr 5, 2024
5b658be
Fix precondition of `processSCION` (#307)
jcp19 Apr 6, 2024
97e4ac7
streamline msgterm assumptions (#308)
jcp19 Apr 9, 2024
f03cb47
merge with master
jcp19 Apr 10, 2024
24b0577
improve verification time of processPkt
jcp19 Apr 10, 2024
d8fb8f1
IO-spec update for link check logic (#310)
mlimbeck Apr 11, 2024
863bfa3
Pre/Post conditions of processPkt (#312)
mlimbeck Apr 11, 2024
a67c139
fmt
jcp19 Apr 12, 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
51 changes: 35 additions & 16 deletions pkg/slayers/path/hopfield_spec.gobra
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,51 @@

package path

ghost const MetaLen = 4
import (
"verification/io"
"verification/utils/slices"
"verification/dependencies/encoding/binary"
. "verification/utils/definitions"
)

pred (h *HopField) Mem() {
acc(h) && h.ConsIngress >= 0 && h.ConsEgress >= 0
}

ghost

ghost
decreases
pure func InfoFieldOffset(currINF int) int {
return MetaLen + InfoLen * currINF
pure func ifsToIO_ifs(ifs uint16) option[io.IO_ifs]{
return ifs == 0 ? none[io.IO_ifs] : some(io.IO_ifs(ifs))
}

ghost
requires 0 <= currINF
requires InfoFieldOffset(currINF) < len(raw)
requires acc(&raw[InfoFieldOffset(currINF)], _)
ghost
requires 0 <= start && start <= middle
requires middle + HopLen <= end && end <= len(raw)
requires acc(slices.AbsSlice_Bytes(raw, start, end), _)
decreases
pure func ConsDir(raw []byte, currINF int) bool {
return raw[InfoFieldOffset(currINF)] & 0x1 == 0x1
pure func BytesToIO_HF(raw [] byte, start int, middle int, end int) (io.IO_HF) {
return let _ := Asserting(forall k int :: {&raw[middle+2:middle+4][k]} 0 <= k && k < 2 ==> &raw[middle+2:middle+4][k] == &raw[middle + 2 + k]) in
let _ := Asserting(forall k int :: {&raw[middle+4:middle+6][k]} 0 <= k && k < 4 ==> &raw[middle+4:middle+6][k] == &raw[middle + 4 + k]) in
let _ := Asserting(forall k int :: {&raw[middle+6:middle+6+MacLen][k]} 0 <= k && k < MacLen ==> &raw[middle+6:middle+6+MacLen][k] == &raw[middle + 6 + k]) in
unfolding acc(slices.AbsSlice_Bytes(raw, start, end), _) in
let inif2 := binary.BigEndian.Uint16(raw[middle+2:middle+4]) in
let egif2 := binary.BigEndian.Uint16(raw[middle+4:middle+6]) in
let op_inif2 := ifsToIO_ifs(inif2) in
let op_egif2 := ifsToIO_ifs(egif2) in
io.IO_HF(io.IO_HF_{
InIF2 : op_inif2,
EgIF2 : op_egif2,
HVF : AbsMac(FromSliceToMacArray(raw[middle+6:middle+6+MacLen])),
})
}

ghost
requires 0 <= currINF
requires InfoFieldOffset(currINF) < len(raw)
requires acc(&raw[InfoFieldOffset(currINF)], _)
ghost
decreases
pure func Peer(raw []byte, currINF int) bool {
return raw[InfoFieldOffset(currINF)] & 0x2 == 0x2
pure func (h HopField) ToIO_HF() (io.IO_HF) {
return io.IO_HF(io.IO_HF_{
InIF2 : ifsToIO_ifs(h.ConsIngress),
EgIF2 : ifsToIO_ifs(h.ConsEgress),
HVF : AbsMac(h.Mac),
})
}
25 changes: 24 additions & 1 deletion pkg/slayers/path/infofield.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import (

"github.com/scionproto/scion/pkg/private/serrors"
"github.com/scionproto/scion/pkg/private/util"
//@ bits "github.com/scionproto/scion/verification/utils/bitwise"
//@ . "github.com/scionproto/scion/verification/utils/definitions"
//@ "github.com/scionproto/scion/verification/utils/slices"
//@ "verification/io"
)

// InfoLen is the size of an InfoField in bytes.
Expand Down Expand Up @@ -85,38 +87,59 @@ func (inf *InfoField) DecodeFromBytes(raw []byte) (err error) {
// @ preserves acc(inf, R10)
// @ preserves slices.AbsSlice_Bytes(b, 0, InfoLen)
// @ ensures err == nil
// @ ensures inf.ToIntermediateAbsInfoField() ==
// @ BytesToIntermediateAbsInfoField(b, 0, 0, InfoLen)
// @ decreases
func (inf *InfoField) SerializeTo(b []byte) (err error) {
if len(b) < InfoLen {
return serrors.New("buffer for InfoField too short", "expected", InfoLen,
"actual", len(b))
}
//@ ghost targetAbsInfo := inf.ToIntermediateAbsInfoField()
//@ unfold slices.AbsSlice_Bytes(b, 0, InfoLen)
b[0] = 0
if inf.ConsDir {
b[0] |= 0x1
}
//@ ghost tmpInfo1 := BytesToIntermediateAbsInfoFieldHelper(b, 0, InfoLen)
//@ bits.InfoFieldFirstByteSerializationLemmas()
//@ assert tmpInfo1.ConsDir == targetAbsInfo.ConsDir
//@ ghost firstByte := b[0]
if inf.Peer {
b[0] |= 0x2
}
//@ tmpInfo2 := BytesToIntermediateAbsInfoFieldHelper(b, 0, InfoLen)
//@ assert tmpInfo2.Peer == (b[0] & 0x2 == 0x2)
//@ assert tmpInfo2.ConsDir == (b[0] & 0x1 == 0x1)
//@ assert tmpInfo2.Peer == targetAbsInfo.Peer
//@ assert tmpInfo2.ConsDir == tmpInfo1.ConsDir
//@ assert tmpInfo2.ConsDir == targetAbsInfo.ConsDir
b[1] = 0 // reserved
//@ assert &b[2:4][0] == &b[2] && &b[2:4][1] == &b[3]
binary.BigEndian.PutUint16(b[2:4], inf.SegID)
//@ ghost tmpInfo3 := BytesToIntermediateAbsInfoFieldHelper(b, 0, InfoLen)
//@ assert tmpInfo3.UInfo == targetAbsInfo.UInfo
//@ assert &b[4:8][0] == &b[4] && &b[4:8][1] == &b[5]
//@ assert &b[4:8][2] == &b[6] && &b[4:8][3] == &b[7]
binary.BigEndian.PutUint32(b[4:8], inf.Timestamp)
//@ ghost tmpInfo4 := BytesToIntermediateAbsInfoFieldHelper(b, 0, InfoLen)
//@ assert tmpInfo4.AInfo == targetAbsInfo.AInfo
//@ fold slices.AbsSlice_Bytes(b, 0, InfoLen)
return nil
}

// UpdateSegID updates the SegID field by XORing the SegID field with the 2
// first bytes of the MAC. It is the beta calculation according to
// https://docs.scion.org/en/latest/protocols/scion-header.html#hop-field-mac-computation
// @ requires hf.HVF == AbsMac(hfMac)
// @ preserves acc(&inf.SegID)
// @ ensures AbsUInfoFromUint16(inf.SegID) ==
// @ old(io.upd_uinfo(AbsUInfoFromUint16(inf.SegID), hf))
// @ decreases
func (inf *InfoField) UpdateSegID(hfMac [MacLen]byte) {
func (inf *InfoField) UpdateSegID(hfMac [MacLen]byte /* @, ghost hf io.IO_HF @ */) {
//@ share hfMac
inf.SegID = inf.SegID ^ binary.BigEndian.Uint16(hfMac[:2])
// @ AssumeForIO(AbsUInfoFromUint16(inf.SegID) == old(io.upd_uinfo(AbsUInfoFromUint16(inf.SegID), hf)))
}

// @ decreases
Expand Down
127 changes: 127 additions & 0 deletions pkg/slayers/path/infofield_spec.gobra
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// Copyright 2022 ETH Zurich
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// +gobra

package path

import (
"verification/io"
sl "verification/utils/slices"
"verification/dependencies/encoding/binary"
. "verification/utils/definitions"
)

ghost const MetaLen = 4

ghost
decreases
pure func InfoFieldOffset(currINF, headerOffset int) int {
return headerOffset + MetaLen + InfoLen * currINF
}

ghost
requires 0 <= currINF && 0 <= headerOffset
requires InfoFieldOffset(currINF, headerOffset) < len(raw)
requires acc(sl.AbsSlice_Bytes(raw, 0, len(raw)), R56)
decreases
pure func ConsDir(raw []byte, currINF int, headerOffset int) bool {
return unfolding acc(sl.AbsSlice_Bytes(raw, 0, len(raw)), R56) in
raw[InfoFieldOffset(currINF, headerOffset)] & 0x1 == 0x1
}

ghost
requires 0 <= currINF && 0 <= headerOffset
requires InfoFieldOffset(currINF, headerOffset) < len(raw)
requires acc(sl.AbsSlice_Bytes(raw, 0, len(raw)), R56)
decreases
pure func Peer(raw []byte, currINF int, headerOffset int) bool {
return unfolding acc(sl.AbsSlice_Bytes(raw, 0, len(raw)), R56) in
raw[InfoFieldOffset(currINF, headerOffset)] & 0x2 == 0x2
}

ghost
requires 0 <= currINF && 0 <= headerOffset
requires InfoFieldOffset(currINF, headerOffset) + InfoLen < len(raw)
requires acc(sl.AbsSlice_Bytes(raw, 0, len(raw)), R56)
decreases
pure func Timestamp(raw []byte, currINF int, headerOffset int) io.IO_ainfo {
return let idx := InfoFieldOffset(currINF, headerOffset) + 4 in
unfolding acc(sl.AbsSlice_Bytes(raw, 0, len(raw)), R56) in
let _ := Asserting(forall i int :: { &raw[idx+i] } { &raw[idx:idx+4][i] } 0 <= i && i < 4 ==>
&raw[idx+i] == &raw[idx:idx+4][i]) in
io.IO_ainfo(binary.BigEndian.Uint32(raw[idx : idx + 4]))
}

ghost
requires 0 <= currINF && 0 <= headerOffset
requires InfoFieldOffset(currINF, headerOffset) + InfoLen < len(raw)
requires acc(sl.AbsSlice_Bytes(raw, 0, len(raw)), R56)
decreases
pure func AbsUinfo(raw []byte, currINF int, headerOffset int) set[io.IO_msgterm] {
return let idx := InfoFieldOffset(currINF, headerOffset) + 2 in
unfolding acc(sl.AbsSlice_Bytes(raw, 0, len(raw)), R56) in
let _ := Asserting(forall k int :: {&raw[idx:idx+2][k]} 0 <= k && k < 2 ==>
&raw[idx:idx+4][k] == &raw[idx + k]) in
AbsUInfoFromUint16(binary.BigEndian.Uint16(raw[idx:idx+2]))
}

// This type simplifies the infoField, making it easier
// to use than the IO_seg3 from the IO-spec.
type IntermediateAbsInfoField adt {
IntermediateAbsInfoField_ {
AInfo io.IO_ainfo
UInfo set[io.IO_msgterm]
ConsDir bool
Peer bool
}
}

ghost
requires 0 <= start && start <= middle
requires middle+InfoLen <= end && end <= len(raw)
requires acc(sl.AbsSlice_Bytes(raw, start, end), _)
decreases
pure func BytesToIntermediateAbsInfoField(raw [] byte, start int, middle int, end int) (IntermediateAbsInfoField) {
return unfolding acc(sl.AbsSlice_Bytes(raw, start, end), _) in
BytesToIntermediateAbsInfoFieldHelper(raw, middle, end)
}

ghost
requires 0 <= middle
requires middle+InfoLen <= end && end <= len(raw)
requires forall i int :: { &raw[i] } middle <= i && i < end ==>
acc(&raw[i], _)
decreases
pure func BytesToIntermediateAbsInfoFieldHelper(raw [] byte, middle int, end int) (IntermediateAbsInfoField) {
return let _ := Asserting(forall k int :: {&raw[middle+2:middle+4][k]} 0 <= k && k < 2 ==> &raw[middle+2:middle+4][k] == &raw[middle+2 + k]) in
let _ := Asserting(forall k int :: {&raw[middle+4:middle+8][k]} 0 <= k && k < 4 ==> &raw[middle+4:middle+8][k] == &raw[middle+4 + k]) in
IntermediateAbsInfoField(IntermediateAbsInfoField_{
AInfo : io.IO_ainfo(binary.BigEndian.Uint32(raw[middle+4:middle+8])),
UInfo : AbsUInfoFromUint16(binary.BigEndian.Uint16(raw[middle+2:middle+4])),
ConsDir : raw[middle] & 0x1 == 0x1,
Peer : raw[middle] & 0x2 == 0x2,
})
}

ghost
decreases
pure func (inf InfoField) ToIntermediateAbsInfoField() (IntermediateAbsInfoField) {
return IntermediateAbsInfoField(IntermediateAbsInfoField_{
AInfo : io.IO_ainfo(inf.Timestamp),
UInfo : AbsUInfoFromUint16(inf.SegID),
ConsDir : inf.ConsDir,
Peer : inf.Peer,
})
}
46 changes: 46 additions & 0 deletions pkg/slayers/path/io_msgterm_spec.gobra
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2020 Anapaya Systems
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// +gobra

package path

import "verification/io"

// At the moment, we assume that all cryptographic operations performed at the code level
// imply the desired properties at the IO spec level because we cannot currently prove in
// Gobra the correctness of these operations. Given that we do not prove any properties
// about this function, we currently do not provide a definition for it.

ghost
decreases
pure func AbsUInfoFromUint16(SegID uint16) set[io.IO_msgterm]

ghost
decreases
pure func AbsMac(mac [MacLen]byte) (io.IO_msgterm)

// The following function converts a slice with at least `MacLen` elements into
// an (exclusive) array containing the mac. Note that there are no permissions
// involved for accessing exclusive arrays. This functions is abstract for now
// because Gobra does not allow for array literals in pure functions, even though
// they are no more side-effectful than creating an instance of a struct type.
// This will soon be fixed in Gobra.
ghost
requires MacLen <= len(mac)
requires forall i int :: { &mac[i] } 0 <= i && i < MacLen ==> acc(&mac[i], _)
ensures len(res) == MacLen
ensures forall i int :: { res[i] } 0 <= i && i < MacLen ==> mac[i] == res[i]
decreases
pure func FromSliceToMacArray(mac []byte) (res [MacLen]byte)
22 changes: 3 additions & 19 deletions pkg/slayers/path/scion/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,7 @@ type MetaHdr struct {
// @ preserves acc(m)
// @ preserves acc(sl.AbsSlice_Bytes(raw, 0, len(raw)), R50)
// @ ensures (len(raw) >= MetaLen) == (e == nil)
// @ ensures e == nil ==> (
// @ MetaLen <= len(raw) &&
// @ 0 <= m.CurrINF && m.CurrINF <= 3 &&
// @ 0 <= m.CurrHF && m.CurrHF < 64 &&
// @ m.SegsInBounds() &&
// @ let lenR := len(raw) in
// @ let b0 := sl.GetByte(raw, 0, lenR, 0) in
// @ let b1 := sl.GetByte(raw, 0, lenR, 1) in
// @ let b2 := sl.GetByte(raw, 0, lenR, 2) in
// @ let b3 := sl.GetByte(raw, 0, lenR, 3) in
// @ let line := binary.BigEndian.Uint32Spec(b0, b1, b2, b3) in
// @ DecodedFrom(line) == *m)
// @ ensures e == nil ==> m.DecodeFromBytesSpec(raw)
// @ ensures e != nil ==> e.ErrorMem()
// @ decreases
func (m *MetaHdr) DecodeFromBytes(raw []byte) (e error) {
Expand Down Expand Up @@ -300,16 +289,11 @@ func (m *MetaHdr) DecodeFromBytes(raw []byte) (e error) {
// @ preserves acc(m, R50)
// @ preserves sl.AbsSlice_Bytes(b, 0, len(b))
// @ ensures e == nil
// @ ensures let lenR := len(b) in
// @ let b0 := sl.GetByte(b, 0, lenR, 0) in
// @ let b1 := sl.GetByte(b, 0, lenR, 1) in
// @ let b2 := sl.GetByte(b, 0, lenR, 2) in
// @ let b3 := sl.GetByte(b, 0, lenR, 3) in
// @ let v := m.SerializedToLine() in
// @ binary.BigEndian.PutUint32Spec(b0, b1, b2, b3, v)
// @ ensures m.SerializeToSpec(b)
// @ decreases
func (m *MetaHdr) SerializeTo(b []byte) (e error) {
if len(b) < MetaLen {
// @ Unreachable()
return serrors.New("buffer for MetaHdr too short", "expected", MetaLen, "actual", len(b))
}
line := uint32(m.CurrINF)<<30 | uint32(m.CurrHF&0x3F)<<24
Expand Down
Loading
Loading