Skip to content

Commit

Permalink
Run constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
virgil-serbanuta committed Oct 25, 2024
1 parent 3431b0b commit 8a356c6
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 23 deletions.
6 changes: 2 additions & 4 deletions tests/ukm-with-contract/erc_20_token.1.run
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ list_mock SetAccountStorageHook ( 7089066454179379067 , 300 ) ukmNoResult();
list_mock GetAccountStorageHook ( 7089066454178295295 ) ukmIntResult(9700, u256);
list_mock GetAccountStorageHook ( 7089066454179379067 ) ukmIntResult(300, u256);

push "#init";
hold_string_from_test_stack;
push "uint256";
hold_list_values_from_test_stack;
push 10000_u256;
hold_list_values_from_test_stack;
encode_call_data;
encode_constructor_data;


return_value;
Expand All @@ -36,7 +34,7 @@ mock CallData;
push_value 1010101_u160;
mock Caller;

call_contract 12345;
init_contract 12345;
return_value;
check_eq ();

Expand Down
2 changes: 2 additions & 0 deletions ukm-semantics/main/encoding/encoder.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ module UKM-CALLDATA-ENCODER
// then use it here and in the rules below.
rule encodeCallData(FN:String, FAT:List, FAL:List) =>
encodeFunctionSignature(FN, FAT) +Bytes encodeFunctionParams(FAL, FAT, b"")
rule encodeConstructorData(FAT:List, FAL:List) =>
encodeFunctionParams(FAL, FAT, b"")
// Function signature encoding
rule encodeFunctionSignature(FuncName:String, RL:List) =>
Expand Down
1 change: 1 addition & 0 deletions ukm-semantics/main/encoding/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module UKM-ENCODING-SYNTAX
// TODO: Make these functions total and returning BytesOrError
syntax Bytes ::= encodeCallData (String, List, List) [function] //Function name, argument types, argument list
| encodeConstructorData (List, List) [function] // argument types, argument list
| encodeFunctionSignature (String, List) [function]
| encodeFunctionSignatureHelper (List, String) [function]
| encodeFunctionParams (List, List, Bytes) [function]
Expand Down
14 changes: 9 additions & 5 deletions ukm-semantics/main/execution/dispatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,25 @@ module UKM-EXECUTION-DISPATCH
imports private UKM-EXECUTION-SYNTAX
imports private UKM-PREPROCESSING-CONFIGURATION
syntax UkmInstruction ::= ukmExecute(contract:Value, gas: ValueOrError)
syntax UkmInstruction ::= ukmExecute(create: Bool, contract:Value, gas: ValueOrError)
rule
<k>
ukmExecute(_AccountId:Int, Gas:Int)
=> ukmExecute(struct(ContractTrait, .Map), integerToValue(Gas, u64))
ukmExecute(Createy:Bool, _AccountId:Int, Gas:Int)
=> ukmExecute(Createy, struct(ContractTrait, .Map), integerToValue(Gas, u64))
...
</k>
<ukm-contract-trait>
ContractTrait:TypePath
</ukm-contract-trait>
rule
<k>
ukmExecute(... contract: Contract:Value, gas: Gas:Value)
=> ptr(NVI) . dispatcherMethodIdentifier ( ptrValue(null, Gas), .CallParamsList )
ukmExecute(... create: Createy:Bool, contract: Contract:Value, gas: Gas:Value)
=> ptr(NVI) . dispatcherMethodIdentifier
( ptrValue(null, Createy)
, ptrValue(null, Gas)
, .CallParamsList
)
...
</k>
<values> Values:Map => Values[NVI <- Contract] </values>
Expand Down
3 changes: 2 additions & 1 deletion ukm-semantics/main/execution/syntax.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
```k
module UKM-EXECUTION-SYNTAX
imports BOOL-SYNTAX
imports INT-SYNTAX
syntax UKMInstruction ::= ukmExecute(accountId: Int, gas: Int)
syntax UKMInstruction ::= ukmExecute(create: Bool, accountId: Int, gas: Int)
endmodule
Expand Down
29 changes: 18 additions & 11 deletions ukm-semantics/main/preprocessing/endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,27 @@ module UKM-PREPROCESSING-ENDPOINTS
typePathToPathInExpression(append(TypePath, dispatcherMethodIdentifier))
</method-name>
<method-params>
self : $selftype , gas : u64, .NormalizedFunctionParameterList
self : $selftype , create : bool , gas : u64 , .NormalizedFunctionParameterList
</method-params>
<method-return-type> ():Type </method-return-type>
<method-implementation>
block({
.InnerAttributes
concatNonEmptyStatements
( let buffer_id = :: ukm :: CallData();
let ( buffer_id | .PatternNoTopAlts
, signature | .PatternNoTopAlts
, .Patterns
) = decodeSignature(buffer_id);
.NonEmptyStatements
, signatureToCall(signature, keys_list(Signatures), Signatures, buffer_id, gas)
.NonEmptyStatements
)
let buffer_id = :: ukm :: CallData();
if create {
.InnerAttributes
self . ukmWrap##init ( buffer_id , gas , .CallParamsList );
.NonEmptyStatements
} else {
.InnerAttributes
let ( buffer_id | .PatternNoTopAlts
, signature | .PatternNoTopAlts
, .Patterns
) = decodeSignature(buffer_id);
signatureToCall(signature, keys_list(Signatures), Signatures, buffer_id, gas)
.NonEmptyStatements
};
.NonEmptyStatements
})
</method-implementation>
<method-outer-attributes> `emptyOuterAttributes`(.KList) </method-outer-attributes>
Expand All @@ -142,6 +147,7 @@ module UKM-PREPROCESSING-ENDPOINTS
</methods>
syntax Identifier ::= "buffer_id" [token]
| "create" [token]
| "signature" [token]
| "gas" [token]
| "state_hooks" [token]
Expand Down Expand Up @@ -170,6 +176,7 @@ module UKM-PREPROCESSING-ENDPOINTS
| "empty" [token]
| "equals" [token]
| "ukm" [token]
| "ukmWrap##init" [token]
| "CallData" [token]
| "EVMC_BAD_JUMP_DESTINATION" [token]
| "EVMC_SUCCESS" [token]
Expand Down
2 changes: 1 addition & 1 deletion ukm-semantics/targets/execution/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module COMMON-K-CELL
configuration
<k>
ukmDecodePreprocessedCell($PGM:Bytes)
~> ukmExecute($ACCTCODE:Int, $GAS:Int)
~> ukmExecute($CREATE, $ACCTCODE:Int, $GAS:Int)
</k>
endmodule
Expand Down
17 changes: 16 additions & 1 deletion ukm-semantics/test/execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ module UKM-TEST-SYNTAX
| "list_mock" UkmHook UkmHookResult
| "encode_call_data"
| "encode_call_data_to_string"
| "encode_constructor_data"
| "call_contract" Int
| "init_contract" Int
| "hold" KItem
| "output_to_arg"
| "push_status"
Expand Down Expand Up @@ -111,6 +113,17 @@ module UKM-TEST-EXECUTION
...
</k> [owise]
rule <k> encode_constructor_data
~> list_values_holder ARGS , list_values_holder PTYPES , .UKMTestTypeHolderList
=> ukmBytesNew(encodeConstructorData(PTYPES, ARGS))
...
</k>
rule <k> encode_constructor_data
=> ukmBytesNew(encodeConstructorData(.List, .List))
...
</k> [owise]
rule
<k> mock CallData => mock(CallDataHook(), V) ... </k>
<test-stack>
Expand All @@ -128,7 +141,9 @@ module UKM-TEST-EXECUTION
rule mock Hook:UkmHook Result:UkmHookResult => mock(Hook, Result)
rule list_mock Hook:UkmHook Result:UkmHookResult => listMock(Hook, Result)
rule call_contract Account => ukmExecute(Account, 100)
rule call_contract Account => ukmExecute(false, Account, 100)
rule init_contract Account => ukmExecute(true, Account, 100)
rule
<k>
Expand Down

0 comments on commit 8a356c6

Please sign in to comment.