Skip to content

Conversation

@jcp19
Copy link
Contributor

@jcp19 jcp19 commented Sep 26, 2025

PR #4187 introduced Gobra to the SCION CI and added formal specifications to some files in the path package.

Recently, in the context of an NGI Zero project, we have been looking at the possibility of adding more extensive formal specifications to the packages in the SCION repository, with the goal of bringing the specifications and proofs from the VerifiedSCION project, which formally verifies the router and its dependencies, to the upstream SCION implementation.

This PR makes more contributions in that direction. In particular, it introduces the following changes:

  • It updates the CI to use an updated version of Gobra, which is faster and supports more features of Go.
  • It introduces formal specifications in packages pkg/addr and pkg/slayers/path that ensure memory safety and crash-freedom:
    • pkg/addr: we specify and verify the functions and methods in files addr.go, host.go, isdas.go and svc.go, except for functions that are used for testing purposes only (i.e., functions named MustParseXXX). In addition, we specify and verify fmtAS in file fmt.go. A version of these annotations in an older version of SCION was useful in detecting a minor mistake (addr: missing bounds check #4080).
    • pkg/slayers/path: it adds specifications to path.go to specify its functions and methods. Of interest, we add a specification to the Path interface that over-approximates what all valid implementations of Path may do.
  • We add some unverified specs for functions and methods from the Go standard library that are necessary to verify the SCION packages that depend on the standard library.

We are aware that adding these annotations impose a high burden on developers, especially if these packages are expected to change often. Thus, we do not expect this PR to be merged as is. Nonetheless, we hope we can use it as a basis for continuing our discussion (@katyatitkova, @romshark) about strategies to progressively incorporate more formal methods in the SCION repository.

@jcp19 jcp19 changed the title [Experimental] Add specification annotations to the pkg/addr package, verify it in the CI with Gobra [Experimental] Add specification annotations to the pkg/addr and pkg/slayers/path packages, verify it in the CI with Gobra Sep 26, 2025
@jcp19 jcp19 changed the title [Experimental] Add specification annotations to the pkg/addr and pkg/slayers/path packages, verify it in the CI with Gobra [Experimental] Add specifications to packages pkg/addr and pkg/slayers/path, verify the in the CI with Gobra Sep 26, 2025
@jcp19 jcp19 changed the title [Experimental] Add specifications to packages pkg/addr and pkg/slayers/path, verify the in the CI with Gobra [Experimental] Add specifications to packages pkg/addr and pkg/slayers/path, verify them in the CI with Gobra Sep 27, 2025
@katyatitkova katyatitkova changed the title [Experimental] Add specifications to packages pkg/addr and pkg/slayers/path, verify them in the CI with Gobra [experimental] Add specifications to packages pkg/addr and pkg/slayers/path, verify them in the CI with Gobra Sep 29, 2025
@katyatitkova katyatitkova changed the title [experimental] Add specifications to packages pkg/addr and pkg/slayers/path, verify them in the CI with Gobra [experimental] add specifications to packages pkg/addr and pkg/slayers/path, verify them in the CI with Gobra Sep 29, 2025
@katyatitkova katyatitkova changed the title [experimental] add specifications to packages pkg/addr and pkg/slayers/path, verify them in the CI with Gobra experimental: add specifications to packages pkg/addr and pkg/slayers/path, verify them in the CI with Gobra Sep 29, 2025
@katyatitkova
Copy link
Contributor

I think what could be done is making this CI check optional: so it's still being run, but if it fails for any reason, it's still possible to merge the PR. Also, is there any link for Gobra 101? It could be useful if the check fails and the person seeing it is interested enough in fixing it

@jcp19
Copy link
Contributor Author

jcp19 commented Oct 2, 2025

I think what could be done is making this CI check optional: so it's still being run, but if it fails for any reason, it's still possible to merge the PR. Also, is there any link for Gobra 101? It could be useful if the check fails and the person seeing it is interested enough in fixing it

Thank you for the idea, @katyatitkova. As suggested, I made the CI checks optional (with the option continue-on-error: true for each verification step) and I added a bit of documentation in the Gobra worflow configuration. There, I list two sources of documentation for Gobra.

func ParseFormattedAS(as string, opts ...FormatOption) (AS, error) {
// @ trusted
// @ requires false
func ParseFormattedAS(a string, opts ...FormatOption) (AS, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why renaming as to a?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as is currently a keyword of Gobra.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's unfortunate considering that our code has a lot of variables called as... But it's OK I guess

var (
registeredPaths [maxPathType]metadata
strictDecoding bool = true
registeredPaths/*@@@*/ [maxPathType]metadata
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's another variable in this PR where the comment is added after a space. IMO, it looks better with a space, but I don't have a preference. But I think it's best to stick to one way to "style" this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I agree! I added a space here :)

Copy link
Contributor Author

@jcp19 jcp19 Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, turns out that this spacing is actually enforced by go-fmt. It looks like the comments after a variable identifier have different whitespacing depending on whether they occur in a single variable declaration or in declaration of multiple variables (https://go.dev/play/p/xhmKLzNbVtV).

# (hopefully) informative error message, which identifies the parts of the code
# where the issues might lie.
# For more information on Gobra and its error messages, check the following:
# - The Gobra Book (WIP): viperproject.github.io/gobra-book/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A feedback about the book itself, not this particular PR: the search there doesn't work with special characters, like @. Fortunately for me (a complete beginner with Gobra), I noticed that one chapter has @ in its name. But for people like me, the search bar might be a first place to go...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I added a feature request in the book repository (viperproject/gobra-book#43).

@katyatitkova
Copy link
Contributor

Looks good to me. I think we could try to merge these changes to see how it works in real life. Let's see what others will say

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants