diff --git a/src/kontrol/prove.py b/src/kontrol/prove.py index 0e9885310..40dec419e 100644 --- a/src/kontrol/prove.py +++ b/src/kontrol/prove.py @@ -13,7 +13,7 @@ from pyk.kcfg import KCFG from pyk.prelude.k import GENERATED_TOP_CELL from pyk.prelude.kbool import FALSE, TRUE, notBool -from pyk.prelude.kint import intToken, eqInt +from pyk.prelude.kint import intToken, eqInt, leInt from pyk.prelude.ml import mlEqualsTrue from pyk.proof.proof import Proof from pyk.proof.reachability import APRBMCProof, APRProof @@ -503,242 +503,267 @@ def _init_cterm( # TODO(palina): EXPERIMENTAL: if calldata is symbolic, # add assumptions that correspond to the test w/`BYTES_DATA` being 320 bytes long, and `bytes[]` containing # 10 elements, each 600 bytes long - target_constraint = mlEqualsTrue(KEVM.range_address(KVariable('target', 'Int'))) - sender_constraint = mlEqualsTrue(KEVM.range_address(KVariable('sender', 'Int'))) - l2_output_constraint = mlEqualsTrue(KEVM.range_uint('256', KVariable('l2OutputIndex', 'Int'))) - constraints.append(l2_output_constraint) - - constraints.append(target_constraint) - constraints.append(sender_constraint) - - length_bytes_data_constraint = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_DATA', 'Bytes')), intToken("320"))) - constraints.append(length_bytes_data_constraint) - - length_bytes_arr_constraint_1 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_1', 'Bytes')), intToken("600"))) - constraints.append(length_bytes_arr_constraint_1) - length_bytes_arr_constraint_2 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_2', 'Bytes')), intToken("600"))) - constraints.append(length_bytes_arr_constraint_2) - length_bytes_arr_constraint_3 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_3', 'Bytes')), intToken("600"))) - constraints.append(length_bytes_arr_constraint_3) - length_bytes_arr_constraint_4 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_4', 'Bytes')), intToken("600"))) - constraints.append(length_bytes_arr_constraint_4) - length_bytes_arr_constraint_5 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_5', 'Bytes')), intToken("600"))) - constraints.append(length_bytes_arr_constraint_5) - length_bytes_arr_constraint_6 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_6', 'Bytes')), intToken("600"))) - constraints.append(length_bytes_arr_constraint_6) - length_bytes_arr_constraint_7 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_7', 'Bytes')), intToken("600"))) - constraints.append(length_bytes_arr_constraint_7) - length_bytes_arr_constraint_8 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_8', 'Bytes')), intToken("600"))) - constraints.append(length_bytes_arr_constraint_8) - length_bytes_arr_constraint_9 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_9', 'Bytes')), intToken("600"))) - constraints.append(length_bytes_arr_constraint_9) - length_bytes_arr_constraint_10 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_10', 'Bytes')), intToken("600"))) - constraints.append(length_bytes_arr_constraint_10) - + structured_calldata_constraints = structured_calldata_assumptions() + constraints.extend(structured_calldata_constraints) # TODO(palina): uncomment to add assumptions that correspond to compiler-inserted checks on fully symbolic calldata ''' - chopped_calldata_length = KApply('chop(_)_WORD_Int_Int', [KEVM.size_bytes(KVariable('SYMBOLIC_CALLDATA'))]) - # calldata_length_range = mlEqualsTrue(leInt(KEVM.size_bytes(KVariable('SYMBOLIC_CALLDATA')), KEVM.pow256())) - # constraints.append(calldata_length_range) - calldata_length_416 = mlEqualsTrue( - eqInt(intToken(0), KApply('_s list[KApply]: + constraints = [] + + target_constraint = mlEqualsTrue(KEVM.range_address(KVariable('target', 'Int'))) + sender_constraint = mlEqualsTrue(KEVM.range_address(KVariable('sender', 'Int'))) + l2_output_constraint = mlEqualsTrue(KEVM.range_uint('256', KVariable('l2OutputIndex', 'Int'))) + constraints.append(l2_output_constraint) + + constraints.append(target_constraint) + constraints.append(sender_constraint) + + length_bytes_data_constraint = mlEqualsTrue( + eqInt(KEVM.size_bytes(KVariable('BYTES_DATA', 'Bytes')), intToken("320")) + ) + constraints.append(length_bytes_data_constraint) + + length_bytes_arr_constraint_1 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_1', 'Bytes')), intToken("600"))) + constraints.append(length_bytes_arr_constraint_1) + length_bytes_arr_constraint_2 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_2', 'Bytes')), intToken("600"))) + constraints.append(length_bytes_arr_constraint_2) + length_bytes_arr_constraint_3 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_3', 'Bytes')), intToken("600"))) + constraints.append(length_bytes_arr_constraint_3) + length_bytes_arr_constraint_4 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_4', 'Bytes')), intToken("600"))) + constraints.append(length_bytes_arr_constraint_4) + length_bytes_arr_constraint_5 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_5', 'Bytes')), intToken("600"))) + constraints.append(length_bytes_arr_constraint_5) + length_bytes_arr_constraint_6 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_6', 'Bytes')), intToken("600"))) + constraints.append(length_bytes_arr_constraint_6) + length_bytes_arr_constraint_7 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_7', 'Bytes')), intToken("600"))) + constraints.append(length_bytes_arr_constraint_7) + length_bytes_arr_constraint_8 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_8', 'Bytes')), intToken("600"))) + constraints.append(length_bytes_arr_constraint_8) + length_bytes_arr_constraint_9 = mlEqualsTrue(eqInt(KEVM.size_bytes(KVariable('BYTES_9', 'Bytes')), intToken("600"))) + constraints.append(length_bytes_arr_constraint_9) + length_bytes_arr_constraint_10 = mlEqualsTrue( + eqInt(KEVM.size_bytes(KVariable('BYTES_10', 'Bytes')), intToken("600")) + ) + constraints.append(length_bytes_arr_constraint_10) + return constraints + + +def compiler_assumptions(calldata: KInner) -> list[KApply]: + constraints = [] + chopped_calldata_length = KApply('chop(_)_WORD_Int_Int', [KEVM.size_bytes(KVariable('SYMBOLIC_CALLDATA'))]) + # calldata_length_range = mlEqualsTrue(leInt(KEVM.size_bytes(KVariable('SYMBOLIC_CALLDATA')), KEVM.pow256())) + # constraints.append(calldata_length_range) + calldata_length_416 = mlEqualsTrue( + eqInt(intToken(0), KApply('_s