Skip to content
This repository was archived by the owner on May 27, 2026. It is now read-only.

[acc] Add clobbered-register annotation checker#231

Draft
mkannwischer wants to merge 1 commit into
masterfrom
mjk/check-clobbered-regs
Draft

[acc] Add clobbered-register annotation checker#231
mkannwischer wants to merge 1 commit into
masterfrom
mjk/check-clobbered-regs

Conversation

@mkannwischer

@mkannwischer mkannwischer commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Add a static checker that verifies clobbered-register docstring
annotations against the actual registers written, as determined by
the existing information-flow analysis.

The check currently only covers a part of the routines
(those that are currently supported by the information-flow
analysis script).

Also adjusted the docstrings for the covered routines - most of those were not aligned with the output of the information-flow script, but some of those differences are just cosmetic (like changing x2, x3 to x2 to x3)

@mkannwischer mkannwischer force-pushed the mjk/check-clobbered-regs branch from 23ddbbe to 334e46e Compare March 31, 2026 09:50
@mkannwischer mkannwischer force-pushed the mjk/check-clobbered-regs branch 2 times, most recently from 0b88b43 to 593a66c Compare April 23, 2026 09:54
Add a static checker that verifies clobbered-register docstring
annotations against the actual registers written, as determined by
the existing information-flow analysis.

The check currently only covers a part of the routines
(those that are currently supported by the information-flow
analysis script).

Signed-off-by: Matthias J. Kannwischer <matthias@zerorisc.com>
@mkannwischer mkannwischer force-pushed the mjk/check-clobbered-regs branch from 593a66c to c161310 Compare April 23, 2026 10:06
@mkannwischer mkannwischer marked this pull request as ready for review April 23, 2026 10:31
@mkannwischer

Copy link
Copy Markdown
Contributor Author

@pqcfox, @jadephilipoom, do you think something like this would be useful? Or am I overengineering this?

@jadephilipoom jadephilipoom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks Matthias, looks good to me! I think this would be nice to have.

Comment thread sw/acc/crypto/tests/BUILD
# N-dependent RSA/bignum helpers, routines taking a WDR index in a GPR,
# and sha3_shake (no acc_binary) are omitted.
#
# TODO: investigate why these take 30s-200s; tagged "manual" until fixed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is probably because for loopi instructions the information-flow backend unrolls loops, and these ones all include the P384 scalarmult loop repeated 448 times. If so, we could fix it by making the backend treat large loops the same way it treats loops with a non-constant number of iterations, but at the cost of potentially missing some details in large loops that depend on a specific number of iterations, and perhaps making the behavior a little less predictable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As of #247 this issue is fixed; all the consttime checks take less than 5s.

Comment thread sw/acc/crypto/tests/BUILD
subroutine = sub,
tags = ["manual"] if (elf, sub) in _SLOW_CLOBBERED_REGS_SUBS else [],
deps = ["//sw/acc/crypto:" + elf],
) for sub, src, elf in [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, rather than this big loop it would be nice to run this almost as a linter. Could we put it under the top-level quality maybe with the other linters, and automatically run it on everything that's not specifically excluded?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will try this when i find some time.

@mkannwischer mkannwischer marked this pull request as draft April 27, 2026 06:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants