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 packSCMP #243

Merged
merged 58 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
c4042f1
start
jcp19 Jan 26, 2024
e308b68
make type-check
jcp19 Jan 26, 2024
88c9632
backup
jcp19 Jan 26, 2024
bff7eba
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 Feb 6, 2024
43536ff
fix syntax errors
jcp19 Feb 7, 2024
7c324f1
establish necessary precondition of DecodeFromBytes
jcp19 Feb 9, 2024
4f0b9f6
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 Feb 19, 2024
4cfda29
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 Feb 19, 2024
85fe9c8
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 Feb 23, 2024
1fcaebf
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 Feb 25, 2024
467903e
remove TODOs
jcp19 Feb 25, 2024
bb4300e
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 Feb 27, 2024
84ef751
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 Mar 1, 2024
f280f21
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 Mar 4, 2024
cfcd6ef
backup
jcp19 Mar 4, 2024
ae8edf9
move on with proof obligations
jcp19 Mar 5, 2024
2da529a
verify packSCMP; reinstate TODO()s for doing the proof step by step
jcp19 Mar 5, 2024
0836f5f
backup
jcp19 Mar 5, 2024
28f71bd
backup
jcp19 Mar 7, 2024
ff922a0
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 Mar 14, 2024
8169c88
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 Mar 17, 2024
52c6c0f
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 Mar 18, 2024
f81b174
merge with master
jcp19 Apr 17, 2024
18bd360
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 Apr 25, 2024
f42467c
fix parse and type errors
jcp19 Apr 25, 2024
9494a94
fix packscmp
jcp19 Apr 25, 2024
3eba827
backup
jcp19 Apr 26, 2024
cef6040
backup
jcp19 Apr 26, 2024
da1682e
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 May 3, 2024
e7dab5f
kill branches for now
jcp19 May 3, 2024
bef9116
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 May 6, 2024
ba85226
backup
jcp19 May 6, 2024
59c146a
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 May 6, 2024
2e6f4db
backup
jcp19 May 6, 2024
72fd18d
merge with master
jcp19 May 9, 2024
efa659c
remove files pushed by mistake
jcp19 May 9, 2024
e070366
del file
jcp19 May 9, 2024
d5369c8
fix verification error
jcp19 May 9, 2024
e70ae13
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 May 19, 2024
faa6e9b
change comment format
jcp19 May 20, 2024
e2d8843
backup
jcp19 May 20, 2024
fe76389
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 May 21, 2024
03189d8
merge with master
jcp19 Jun 4, 2024
aa7013d
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 Jun 5, 2024
7c4f0c3
merge with master
jcp19 Jun 17, 2024
d7e952e
reset changes to scion_spec.gobra
jcp19 Jun 17, 2024
4a5a5f3
continue making progress
jcp19 Jun 18, 2024
dc25b29
backup
jcp19 Jun 18, 2024
c6194d1
simplify spec
jcp19 Jun 18, 2024
4c2464d
backup
jcp19 Jun 18, 2024
2b178e8
non-termination again
jcp19 Jun 21, 2024
81ca970
backup
jcp19 Jun 24, 2024
689222a
merge with master
jcp19 Jul 12, 2024
80ef78a
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 Jul 23, 2024
d7bf52d
packSCMP Continued (#373)
mlimbeck Aug 15, 2024
d4da9cc
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 Aug 15, 2024
320a1fb
Merge branch 'master' into joao-uncomment-packSCMP
jcp19 Aug 28, 2024
ed7b61d
Move ownership of underlying slice of `SerializableBuffer` to outside…
mlimbeck Aug 29, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,5 @@ target
*.internal
.devcontainer
.metals
.bazelbsp
.bazel
4 changes: 2 additions & 2 deletions pkg/private/serrors/serrors_spec.gobra
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ func Wrap(msg, cause error, errCtx ...interface{}) (res error)
// Elements of errCtx are limited to "primitive types" at the moment.
// This is a safe but strict under-approximation of what can be done
// with this method.
requires cause.ErrorMem()
requires cause != nil ==> cause.ErrorMem()
preserves forall i int :: { &errCtx[i] } 0 <= i && i < len(errCtx) ==> acc(&errCtx[i], R15)
// The following precondition cannot be adequately captured in Gobra.
// requires forall i int :: 0 <= i && i < len(errCtx) ==> IsOfPrimitiveType(errCtx[i])
ensures res != nil && res.ErrorMem()
ensures res.ErrorMem() --* cause.ErrorMem()
ensures cause != nil ==> (res.ErrorMem() --* cause.ErrorMem())
decreases
func WrapStr(msg string, cause error, errCtx ...interface{}) (res error)

Expand Down
16 changes: 8 additions & 8 deletions pkg/slayers/path/scion/raw_spec.gobra
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,15 @@ requires validPktMetaHdr(raw)
decreases
pure func (s *Raw) absPkt(raw []byte) (res io.IO_pkt2) {
return let _ := reveal validPktMetaHdr(raw) in
let metaHdr := RawBytesToMetaHdr(raw) in
let metaHdr := RawBytesToMetaHdr(raw) in
let currInfIdx := int(metaHdr.CurrINF) in
let currHfIdx := int(metaHdr.CurrHF) in
let seg1Len := int(metaHdr.SegLen[0]) in
let seg2Len := int(metaHdr.SegLen[1]) in
let seg3Len := int(metaHdr.SegLen[2]) in
let currHfIdx := int(metaHdr.CurrHF) in
let seg1Len := int(metaHdr.SegLen[0]) in
let seg2Len := int(metaHdr.SegLen[1]) in
let seg3Len := int(metaHdr.SegLen[2]) in
let segs := io.CombineSegLens(seg1Len, seg2Len, seg3Len) in
let segLen := segs.LengthOfCurrSeg(currHfIdx) in
let prevSegLen := segs.LengthOfPrevSeg(currHfIdx) in
let segLen := segs.LengthOfCurrSeg(currHfIdx) in
let prevSegLen := segs.LengthOfPrevSeg(currHfIdx) in
let numINF := segs.NumInfoFields() in
let offset := HopFieldOffset(numINF, prevSegLen, MetaLen) in
io.IO_Packet2 {
Expand Down Expand Up @@ -428,7 +428,7 @@ pure func validPktMetaHdr(raw []byte) bool {
let segs := io.CombineSegLens(seg1, seg2, seg3) in
let base := RawBytesToBase(raw) in
0 < metaHdr.SegLen[0] &&
base.Valid() &&
base.Valid() &&
PktLen(segs, MetaLen) <= len(raw)
}

Expand Down
5 changes: 2 additions & 3 deletions pkg/slayers/scion.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,11 @@ func (s *SCION) NetworkFlow() (res gopacket.Flow) {
// @ requires b != nil && b.Mem()
// @ requires acc(s.Mem(ubuf), R0)
// @ requires sl.Bytes(ubuf, 0, len(ubuf))
// @ requires sl.Bytes(b.UBuf(), 0, len(b.UBuf()))
// @ ensures b.Mem()
// @ ensures acc(s.Mem(ubuf), R0)
// @ ensures sl.Bytes(ubuf, 0, len(ubuf))
// @ ensures sl.Bytes(b.UBuf(), 0, len(b.UBuf()))
// TODO: hide internal spec details
// @ ensures e == nil && s.HasOneHopPath(ubuf) ==>
// @ len(b.UBuf()) == old(len(b.UBuf())) + unfolding acc(s.Mem(ubuf), R55) in
Expand Down Expand Up @@ -257,7 +259,6 @@ func (s *SCION) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeO
}
// @ ghost uSerBufN := b.UBuf()
// @ assert buf === uSerBufN[:scnLen]
// @ b.ExchangePred()

// @ unfold acc(sl.Bytes(uSerBufN, 0, len(uSerBufN)), writePerm)
// Serialize common header.
Expand Down Expand Up @@ -287,7 +288,6 @@ func (s *SCION) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeO
// @ sl.Unslice_Bytes(uSerBufN, 0, CmnHdrLen, R54)
// @ sl.CombineRange_Bytes(uSerBufN, CmnHdrLen, scnLen, writePerm)
// @ sl.CombineRange_Bytes(ubuf, CmnHdrLen, len(ubuf), R10)
// @ b.RestoreMem(uSerBufN)
return err
}
offset := CmnHdrLen + s.AddrHdrLen( /*@ nil, true @*/ )
Expand Down Expand Up @@ -320,7 +320,6 @@ func (s *SCION) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeO
// @ sl.CombineRange_Bytes(uSerBufN, offset, scnLen, HalfPerm)
// @ sl.CombineRange_Bytes(ubuf, startP, endP, HalfPerm)
// @ reveal IsSupportedPkt(uSerBufN)
// @ b.RestoreMem(uSerBufN)
// @ reveal IsSupportedRawPkt(b.View())
return tmp
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/slayers/scion_spec.gobra
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ ghost
requires 0 < p
preserves acc(s.Mem(ub), p)
ensures let start := s.PathStartIdx(ub) in
let end := s.PathEndIdx(ub) in
0 <= start && start <= end && end <= len(ub)
let end := s.PathEndIdx(ub) in
0 <= start && start <= end && end <= len(ub)
decreases
func LemmaPathIdxStartEnd(s *SCION, ub []byte, p perm) {
unfold acc(s.Mem(ub), p)
Expand Down Expand Up @@ -462,7 +462,7 @@ pure func ValidPktMetaHdr(raw []byte) bool {
let length := GetLength(raw) in
length <= len(raw) &&
unfolding acc(sl.Bytes(raw, 0, len(raw)), R56) in
let _ := Asserting(forall k int :: {&rawHdr[k]} 0 <= k && k < scion.MetaLen ==> &rawHdr[k] == &raw[start + k]) in
let _ := Asserting(forall k int :: {&rawHdr[k]} 0 <= k && k < scion.MetaLen ==> &rawHdr[k] == &raw[start + k]) in
let hdr := binary.BigEndian.Uint32(rawHdr) in
let metaHdr := scion.DecodedFrom(hdr) in
let seg1 := int(metaHdr.SegLen[0]) in
Expand Down
32 changes: 1 addition & 31 deletions pkg/slayers/scmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (s *SCMP) NextLayerType( /*@ ghost ub []byte @*/ ) gopacket.LayerType {
// @ requires b != nil
// @ requires s.Mem(ubufMem)
// @ preserves b.Mem()
// @ preserves sl.Bytes(b.UBuf(), 0, len(b.UBuf()))
// @ ensures err == nil ==> s.Mem(ubufMem)
// @ ensures err != nil ==> err.ErrorMem()
// @ decreases
Expand All @@ -121,15 +122,6 @@ func (s *SCMP) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOp
return err
}
// @ unfold s.Mem(ubufMem)

// @ requires len(underlyingBufRes) >= 4
// @ requires bytes === underlyingBufRes[:4]
// @ requires b != nil
// @ preserves acc(&s.TypeCode)
// @ preserves b.Mem() && b.UBuf() === underlyingBufRes
// @ decreases
// @ outline (
// @ b.ExchangePred()
// @ sl.SplitByIndex_Bytes(underlyingBufRes, 0, len(underlyingBufRes), 2, writePerm)
// @ unfold sl.Bytes(underlyingBufRes, 0, 2)
// @ assert forall i int :: { &bytes[i] } 0 <= i && i < 2 ==> &bytes[i] == &underlyingBufRes[i]
Expand All @@ -138,59 +130,37 @@ func (s *SCMP) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOp
// @ unfold sl.Bytes(bytes, 0, 2)
// @ fold sl.Bytes(underlyingBufRes, 0, 2)
// @ sl.CombineAtIndex_Bytes(underlyingBufRes, 0, len(underlyingBufRes), 2, writePerm)
// @ b.RestoreMem(underlyingBufRes)
// @ )

if opts.ComputeChecksums {
if s.scn == nil {
// @ fold s.Mem(ubufMem)
return serrors.New("can not calculate checksum without SCION header")
}
// zero out checksum bytes
// @ requires len(underlyingBufRes) >= 4
// @ requires bytes === underlyingBufRes[:4]
// @ requires b != nil
// @ preserves b.Mem() && b.UBuf() === underlyingBufRes
// @ decreases
// @ outline (
// @ b.ExchangePred()
// @ sl.SplitByIndex_Bytes(underlyingBufRes, 0, len(underlyingBufRes), 4, writePerm)
// @ unfold sl.Bytes(underlyingBufRes, 0, 4)
// @ assert forall i int :: { &bytes[i] } 0 <= i && i < 4 ==> &bytes[i] == &underlyingBufRes[i]
bytes[2] = 0
bytes[3] = 0
// @ fold sl.Bytes(underlyingBufRes, 0, 4)
// @ sl.CombineAtIndex_Bytes(underlyingBufRes, 0, len(underlyingBufRes), 4, writePerm)
// @ b.RestoreMem(underlyingBufRes)
// @ )
verScionTmp := b.Bytes()
// @ unfold s.scn.ChecksumMem()
s.Checksum, err = s.scn.computeChecksum(verScionTmp, uint8(L4SCMP))
// @ fold s.scn.ChecksumMem()
// @ b.RestoreMem(verScionTmp)
if err != nil {
// @ fold s.Mem(ubufMem)
return err
}

}
// @ requires len(underlyingBufRes) >= 4
// @ requires bytes === underlyingBufRes[:4]
// @ requires b != nil
// @ preserves acc(&s.Checksum)
// @ preserves b.Mem() && b.UBuf() === underlyingBufRes
// @ decreases
// @ outline (
// @ b.ExchangePred()
// @ sl.SplitByIndex_Bytes(underlyingBufRes, 0, len(underlyingBufRes), 4, writePerm)
// @ unfold sl.Bytes(underlyingBufRes, 0, 4)
// @ assert forall i int :: { &bytes[i] } 0 <= i && i < 4 ==> &bytes[i] == &underlyingBufRes[i]
// @ assert forall i int :: { &bytes[2:][i] } 0 <= i && i < 2 ==> &bytes[2:][i] == &bytes[i + 2]
binary.BigEndian.PutUint16(bytes[2:], s.Checksum)
// @ fold sl.Bytes(underlyingBufRes, 0, 4)
// @ sl.CombineAtIndex_Bytes(underlyingBufRes, 0, len(underlyingBufRes), 4, writePerm)
// @ b.RestoreMem(underlyingBufRes)
// @ )
// @ fold s.Mem(ubufMem)
return nil
}
Expand Down
Loading
Loading