-
Notifications
You must be signed in to change notification settings - Fork 3
P-TOKEN-HOTFIX: Conversions between [u8;8] and u64 #697
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
base: feature/p-token
Are you sure you want to change the base?
Changes from all commits
3753c54
2e86a00
2aa8c0c
efb8dd9
e802c88
ec7b4b8
59b756c
026f3ba
4527a09
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,10 +193,18 @@ The code uses some helper sorts for better readability. | |
syntax List ::= #asU8s ( Int ) [function] | ||
| #asU8List ( List , Int ) [function] | ||
// ------------------------------------- | ||
rule #asU8s(X) => #asU8List(.List, X) | ||
rule #asU8s(X) => #asU8List(.List, X) [concrete] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a good idea. Requires testing, of course, but we want to avoid building up the list of bit-shifts and enable round-tripping, which this should do. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works on |
||
rule #asU8List(ACC, _) => ACC requires 8 <=Int size(ACC) [priority(40)] // always cut at 8 bytes | ||
rule #asU8List(ACC, X) => #asU8List( ACC ListItem(Integer( X &Int 255, 8, false)) , X >>Int 8) [preserves-definedness] | ||
|
||
// mapping an offset over bytes produced by #asU8s has no effect | ||
rule #mapOffset(#asU8s(X), _) => #asU8s(X) [simplification, preserves-definedness] | ||
|
||
// Shortcut transmute: [u8; 8] (from #asU8s) to u64 | ||
rule castAux(Range(#asU8s(X)), castKindTransmute, _TY_SOURCE, TY_TARGET) => Integer(X, 64, false) | ||
requires TY_TARGET ==K typeInfoPrimitiveType(primTypeUint(uintTyU64)) | ||
[simplification, preserves-definedness] | ||
|
||
rule toAmount(fromAmount(AMT)) => AMT [simplification, preserves-definedness] | ||
rule fromAmount(toAmount(VAL)) => VAL [simplification, preserves-definedness] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure I understand, this is stating: the result of any integers bitwise
And
ed with 255 will be bounded between 0 (inclusive) and 256 (not inclusive)?I don't really understand how this works under the hood, but straight away I wonder if there should be any restriction on the integers. How does this work with negative numbers? Does this make assumptions about 2's complement?
I might be highlighting some misunderstanding I have by asking these questions, but it feels a bit suspicious to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the answer is yes. We've checked and introduced similar simp rules for riscv-semantics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No restriction on the integers. The way
&Int
works in K is that negative numbers are assumed to have an infinite prefix of...111111
but that prefix becomes zero when applying&Int N
with a positiveN
. So negative numbers become positive.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two simp rules (smt-lemma) are used to return a true for the following expression.
andBool 0 <=Int B0 andBool B0 <Int 256
If we don't have these two rules, the corresponding rule cannot be applied.
I'm not sure the implementation detail of the backend. I think it might be a rewrite to the substitued terms to get this
true
. Another thing that I guess the backend can do is to interpret it in SMT, and let SMT solver to return true or false. I think haskell backend should have both way to tackle the require clause, like apply rewrites first, then give it to Z3. Am I right? @jberthold