Skip to content

Commit a1a43e8

Browse files
authored
Simplification rule to eliminate amount round-trip conversions (#779)
These round-trip conversions `toAmount(fromAmount(...(toAmount(fromAmount(Amount(?AMOUNT))))))` were building up in the `initialize_account` proof. The simplification rule does not apply because the function equation is applied to the symbolic value.
2 parents f48bd71 + 20e32f1 commit a1a43e8

File tree

1 file changed

+21
-0
lines changed
  • kmir/src/kmir/kdist/mir-semantics/symbolic

1 file changed

+21
-0
lines changed

kmir/src/kmir/kdist/mir-semantics/symbolic/p-token.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,27 @@ The code uses some helper sorts for better readability.
203203
rule toAmount(fromAmount(AMT)) => AMT [simplification, preserves-definedness]
204204
rule fromAmount(toAmount(VAL)) => VAL [simplification, preserves-definedness]
205205
206+
// Amount Round-trip Simplifications:
207+
rule Bytes2Int(
208+
#bytesFrom(
209+
ListItem(Integer(AMOUNT &Int 255, 8, false))
210+
ListItem(Integer(AMOUNT >>Int 8 &Int 255, 8, false))
211+
ListItem(Integer(AMOUNT >>Int 8 >>Int 8 &Int 255, 8, false))
212+
ListItem(Integer(AMOUNT >>Int 8 >>Int 8 >>Int 8 &Int 255, 8, false))
213+
ListItem(Integer(AMOUNT >>Int 8 >>Int 8 >>Int 8 >>Int 8 &Int 255, 8, false))
214+
ListItem(Integer(AMOUNT >>Int 8 >>Int 8 >>Int 8 >>Int 8 >>Int 8 &Int 255, 8, false))
215+
ListItem(Integer(AMOUNT >>Int 8 >>Int 8 >>Int 8 >>Int 8 >>Int 8 >>Int 8 &Int 255, 8, false))
216+
ListItem(Integer(AMOUNT >>Int 8 >>Int 8 >>Int 8 >>Int 8 >>Int 8 >>Int 8 >>Int 8 &Int 255, 8, false))
217+
) ,
218+
LE,
219+
Unsigned
220+
) => AMOUNT
221+
[simplification, symbolic(AMOUNT), preserves-definedness]
222+
223+
224+
225+
// ------------------------------------------------------------------------------
226+
206227
syntax Flag ::= Flag ( Int ) // 4 bytes , first byte representing bool. From = 4 bytes, to = read/check all bytes
207228
| FlagError ( Value ) // to make converters total, add an error constructor
208229

0 commit comments

Comments
 (0)