Skip to content

Commit 9008307

Browse files
authored
Constrain rent parameters to avoid branching on float (#797)
* assume `burn_percent <= 100` (true percentage) to avoid underflow * constrain lamports_per_byteyear to `< 2^32` to avoid overflow for small concrete data sizes * set `exempt_threshold` to default of 2.0 * add a special rule to implement how the default exempt_threshold is recognised: `2.0f64 as u64 == 4611686018427387904u64` Closes runtimeverification/solana-token#33
2 parents 9e6f5c5 + 045a1d2 commit 9008307

File tree

1 file changed

+24
-6
lines changed
  • kmir/src/kmir/kdist/mir-semantics/symbolic

1 file changed

+24
-6
lines changed

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

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -559,12 +559,12 @@ An `AccountInfo` reference is passed to the function.
559559
#toPAcc(P_ACC),
560560
PRent(
561561
U64(?LMP_PER_BYTEYEAR),
562-
F64(?_EXEMPT_THRESHOLD),
562+
F64(2.0), // fixed exempt_threshold 2.0 (default)
563563
U8(?BURN_PCT)
564564
)
565565
)
566-
ensures 0 <=Int ?LMP_PER_BYTEYEAR andBool ?LMP_PER_BYTEYEAR <Int 1 <<Int 64
567-
andBool 0 <=Int ?BURN_PCT andBool ?BURN_PCT <Int 256
566+
ensures 0 <=Int ?LMP_PER_BYTEYEAR andBool ?LMP_PER_BYTEYEAR <Int 1 <<Int 32 // limited arbitrarily to avoid overflows on fixed concrete values
567+
andBool 0 <=Int ?BURN_PCT andBool ?BURN_PCT <=Int 100 // limited so that it is a true percentage
568568
andBool DATA_LEN ==Int 17 // size_of(Rent), see pinocchio::sysvars::rent::Rent::LEN
569569
```
570570

@@ -764,7 +764,7 @@ Only the system Rent will be stored as a value directly. The `SysRent` wrapper i
764764
SysRent(
765765
PRent(
766766
U64(?SYS_LMP_PER_BYTEYEAR),
767-
F64(?_SYS_EXEMPT_THRESHOLD),
767+
F64(2.0), // fixed exempt_threshold 2.0 (default)
768768
U8(?SYS_BURN_PCT)
769769
)
770770
)
@@ -775,8 +775,8 @@ Only the system Rent will be stored as a value directly. The `SysRent` wrapper i
775775
...
776776
</k>
777777
requires #functionName(lookupFunction(#tyOfCall(FUNC))) ==String "<sysvars::rent::Rent as sysvars::Sysvar>::get"
778-
ensures 0 <=Int ?SYS_LMP_PER_BYTEYEAR andBool ?SYS_LMP_PER_BYTEYEAR <Int 1 <<Int 64
779-
andBool 0 <=Int ?SYS_BURN_PCT andBool ?SYS_BURN_PCT <Int 256
778+
ensures 0 <=Int ?SYS_LMP_PER_BYTEYEAR andBool ?SYS_LMP_PER_BYTEYEAR <Int 1 <<Int 32 // limited arbitrarily to avoid overflows on fixed concrete values
779+
andBool 0 <=Int ?SYS_BURN_PCT andBool ?SYS_BURN_PCT <=Int 100 // limited so that it is a true percentage
780780
[priority(30), preserves-definedness]
781781
```
782782

@@ -833,6 +833,24 @@ Write access (as well as moving reads) uses `traverseProjection` and also requir
833833
rule #projectionsFor(CtxPRent CTXTS, PROJS) => #projectionsFor(CTXTS, PROJS)
834834
```
835835

836+
### `Rent` specific evaluation for `Float` (Exempt threshold)
837+
838+
THe pinocchio library contains special code to perform rent compuation in `u64` instead of `Float`
839+
when the rent exempt threshold parameter is the default of 2.0.
840+
The default is assumed in the cheat code throughout all our proofs so the test for the default is implemented as a special rule.
841+
842+
```k
843+
rule <k> #applyBinOp (
844+
binOpEq,
845+
thunk(#cast(Float(VAL, 64), castKindTransmute, _, _)),
846+
Integer ( 4611686018427387904 , 64 , false ),
847+
false
848+
) => BoolVal(true)
849+
...
850+
</k>
851+
requires VAL ==Float 2.0
852+
```
853+
836854
### Reading and Writing the Second Component
837855

838856
The access to the second component of the `PAccount` value is implemented with a special projection.

0 commit comments

Comments
 (0)