Skip to content
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

Add empty <commands> to Mandos rules #126

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ else
endif
K_BIN := $(K_RELEASE)/bin
K_LIB := $(K_RELEASE)/lib/kframework
export K_OPTS ?= -Xmx12G -Xss512m
export K_OPTS ?= -Xmx8G -Xss512m
export K_RELEASE

PYTHONPATH := $(K_LIB):$(KWASM_BINARY_PARSER):$(PYTHONPATH)
Expand Down
67 changes: 61 additions & 6 deletions mandos.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ Only take the next step once both the Elrond node and Wasm are done executing.

syntax Steps ::= List{Step, ""} [klabel(mandosSteps), symbol]
// -------------------------------------------------------------
rule <k> .Steps => . </k> [priority(60)]
rule <k> S:Step SS:Steps => S ~> SS ... </k> [priority(60)]
rule [steps-empty]:
<k> .Steps => . </k>
<commands> . </commands>
[priority(60)]

rule [steps-seq]:
<k> S:Step SS:Steps => S ~> SS ... </k>
<commands> . </commands>
[priority(60)]

syntax Step ::= "setExitCode" Int
// ---------------------------------
Expand All @@ -60,16 +67,19 @@ Only take the next step once both the Elrond node and Wasm are done executing.
// --------------------------
rule <k> (module _:OptionalId _:Defns):ModuleDecl #as M => #wait ... </k>
<instrs> . => sequenceStmts(text2abstract(M .Stmts)) </instrs>
<commands> . </commands>

rule <k> M:ModuleDecl => #wait ... </k>
<instrs> . => M </instrs>
<commands> . </commands>
[owise]

syntax Step ::= "register" String [klabel(register), symbol]
// ------------------------------------------------------------
rule <k> register NAME => . ... </k>
<moduleRegistry> REG => REG [NAME <- IDX -Int 1] </moduleRegistry>
<nextModuleIdx> IDX </nextModuleIdx>
<commands> . </commands>
[priority(60)]
```

Expand Down Expand Up @@ -108,6 +118,7 @@ Only take the next step once both the Elrond node and Wasm are done executing.
// -------------------------------------------------------------------------------
rule <k> setAccount(ADDRESS, NONCE, BALANCE, CODE, OWNER, STORAGE)
=> setAccountAux(#address2Bytes(ADDRESS), NONCE, BALANCE, CODE, #address2Bytes(OWNER), STORAGE) ... </k>
<commands> . </commands>
[priority(60)]

rule <k> setAccountAux(ADDRESS, NONCE, BALANCE, CODE, OWNER, STORAGE) => #wait ... </k>
Expand All @@ -129,6 +140,7 @@ Only take the next step once both the Elrond node and Wasm are done executing.
</esdtData>
...
</account>
<commands> . </commands>
[priority(60)]

rule <k> setEsdtBalance( ADDR , TokId , Value ) => . ... </k>
Expand All @@ -144,17 +156,20 @@ Only take the next step once both the Elrond node and Wasm are done executing.
</esdtDatas>
...
</account>
<commands> . </commands>
[priority(61)]

syntax Step ::= newAddress ( Address, Int, Address ) [klabel(newAddress), symbol]
| newAddressAux ( Bytes, Int, Bytes ) [klabel(newAddressAux), symbol]
// ---------------------------------------------------------------------------------------
rule <k> newAddress(CREATOR, NONCE, NEW)
=> newAddressAux(#address2Bytes(CREATOR), NONCE, #address2Bytes(NEW)) ... </k>
<commands> . </commands>
[priority(60)]

rule <k> newAddressAux(CREATOR, NONCE, NEW) => . ... </k>
<newAddresses> NEWADDRESSES => NEWADDRESSES [tuple(CREATOR, NONCE) <- NEW] </newAddresses>
<commands> . </commands>
[priority(60)]

syntax AddressNonce ::= tuple( Bytes , Int )
Expand All @@ -170,42 +185,52 @@ Only take the next step once both the Elrond node and Wasm are done executing.
// --------------------------------------------------------------------------------
rule <k> setCurBlockInfo(blockTimestamp(TIMESTAMP)) => . ... </k>
<curBlockTimestamp> _ => TIMESTAMP </curBlockTimestamp>
<commands> . </commands>
[priority(60)]

rule <k> setCurBlockInfo(blockNonce(NONCE)) => . ... </k>
<curBlockNonce> _ => NONCE </curBlockNonce>
<commands> . </commands>
[priority(60)]

rule <k> setCurBlockInfo(blockRound(ROUND)) => . ... </k>
<curBlockRound> _ => ROUND </curBlockRound>
<commands> . </commands>
[priority(60)]

rule <k> setCurBlockInfo(blockEpoch(EPOCH)) => . ... </k>
<curBlockEpoch> _ => EPOCH </curBlockEpoch>
<commands> . </commands>
[priority(60)]

rule <k> setCurBlockInfo(blockRandomSeed(SEED)) => . ... </k>
<curBlockRandomSeed> _ => SEED </curBlockRandomSeed>
<commands> . </commands>
[priority(60)]

rule <k> setPrevBlockInfo(blockTimestamp(TIMESTAMP)) => . ... </k>
<prevBlockTimestamp> _ => TIMESTAMP </prevBlockTimestamp>
<commands> . </commands>
[priority(60)]

rule <k> setPrevBlockInfo(blockNonce(NONCE)) => . ... </k>
<prevBlockNonce> _ => NONCE </prevBlockNonce>
<commands> . </commands>
[priority(60)]

rule <k> setPrevBlockInfo(blockRound(ROUND)) => . ... </k>
<prevBlockRound> _ => ROUND </prevBlockRound>
<commands> . </commands>
[priority(60)]

rule <k> setPrevBlockInfo(blockEpoch(EPOCH)) => . ... </k>
<prevBlockEpoch> _ => EPOCH </prevBlockEpoch>
<commands> . </commands>
[priority(60)]

rule <k> setPrevBlockInfo(blockRandomSeed(SEED)) => . ... </k>
<prevBlockRandomSeed> _ => SEED </prevBlockRandomSeed>
<commands> . </commands>
[priority(60)]
```

Expand All @@ -225,13 +250,15 @@ Only take the next step once both the Elrond node and Wasm are done executing.
<nonce> NONCE </nonce>
...
</account>
<commands> . </commands>
[priority(60)]

syntax Step ::= checkAccountBalance ( Address, Int ) [klabel(checkAccountBalance), symbol]
| checkAccountBalanceAux ( Bytes, Int ) [klabel(checkAccountBalanceAux), symbol]
// ------------------------------------------------------------------------------------------------
rule <k> checkAccountBalance(ADDRESS, BALANCE)
=> checkAccountBalanceAux(#address2Bytes(ADDRESS), BALANCE) ... </k>
<commands> . </commands>
[priority(60)]

rule <k> checkAccountBalanceAux(ADDR, BALANCE) => . ... </k>
Expand All @@ -240,13 +267,15 @@ Only take the next step once both the Elrond node and Wasm are done executing.
<balance> BALANCE </balance>
...
</account>
<commands> . </commands>
[priority(60)]

syntax Step ::= checkAccountStorage ( Address, MapBytesToBytes ) [klabel(checkAccountStorage), symbol]
| checkAccountStorageAux ( Bytes, MapBytesToBytes ) [klabel(checkAccountStorageAux), symbol]
// ------------------------------------------------------------------------------------------------
rule <k> checkAccountStorage(ADDRESS, STORAGE)
=> checkAccountStorageAux(#address2Bytes(ADDRESS), STORAGE) ... </k>
<commands> . </commands>
[priority(60)]

rule <k> checkAccountStorageAux(ADDR, STORAGE) => . ... </k>
Expand All @@ -255,6 +284,7 @@ Only take the next step once both the Elrond node and Wasm are done executing.
<storage> ACCTSTORAGE </storage>
...
</account>
<commands> . </commands>
requires ACCTSTORAGE ==K #removeEmptyBytes(STORAGE)
[priority(60)]

Expand All @@ -263,6 +293,7 @@ Only take the next step once both the Elrond node and Wasm are done executing.
// ---------------------------------------------------------------------------------------------
rule <k> checkAccountCode(ADDRESS, CODEPATH)
=> checkAccountCodeAux(#address2Bytes(ADDRESS), CODEPATH) ... </k>
<commands> . </commands>
[priority(60)]

syntax OptionalString ::= #getModuleCodePath(ModuleDecl) [function, total]
Expand All @@ -277,6 +308,7 @@ Only take the next step once both the Elrond node and Wasm are done executing.
<code> .Code </code>
...
</account>
<commands> . </commands>
[priority(60)]

rule <k> checkAccountCodeAux(ADDR, CODEPATH) => . ... </k>
Expand All @@ -285,6 +317,7 @@ Only take the next step once both the Elrond node and Wasm are done executing.
<code> CODE:ModuleDecl </code>
...
</account>
<commands> . </commands>
requires CODEPATH ==K #getModuleCodePath(CODE)
[priority(60)]

Expand All @@ -293,23 +326,27 @@ Only take the next step once both the Elrond node and Wasm are done executing.
// ---------------------------------------------------------------------------------
rule <k> checkedAccount(ADDRESS)
=> checkedAccountAux(#address2Bytes(ADDRESS)) ... </k>
<commands> . </commands>
[priority(60)]

rule <k> checkedAccountAux(ADDR) => . ... </k>
<checkedAccounts> ... (.Set => SetItem(ADDR)) ... </checkedAccounts>
<commands> . </commands>
[priority(60)]

syntax Step ::= checkNoAdditionalAccounts( Set ) [klabel(checkNoAdditionalAccounts), symbol]
// ---------------------------------------------------------------------------------------
rule <k> checkNoAdditionalAccounts(EXPECTED) => . ... </k>
<checkedAccounts> CHECKEDACCTS </checkedAccounts>
<commands> . </commands>
requires EXPECTED ==K CHECKEDACCTS
[priority(60)]

syntax Step ::= "clearCheckedAccounts" [klabel(clearCheckedAccounts), symbol]
// -----------------------------------------------------------------------------
rule <k> clearCheckedAccounts => . ... </k>
<checkedAccounts> _ => .Set </checkedAccounts>
<commands> . </commands>
[priority(60)]
```

Expand All @@ -323,6 +360,7 @@ Only take the next step once both the Elrond node and Wasm are done executing.
<k> callTx(FROM, TO, VALUE, ESDT, FUNCTION, ARGS, GASLIMIT, GASPRICE)
=> callTxAux(#address2Bytes(FROM), #address2Bytes(TO), VALUE, ESDT, FUNCTION, ARGS, GASLIMIT, GASPRICE) ...
</k>
<commands> . </commands>
[priority(60)]

rule [callTxAux]:
Expand Down Expand Up @@ -354,27 +392,32 @@ Only take the next step once both the Elrond node and Wasm are done executing.
// --------------------------------------------------------------------------
rule <k> checkExpectOut(OUT) => . ... </k>
<vmOutput> VMOutput(... out: OUT) </vmOutput>
<commands> . </commands>
[priority(60)]

syntax Step ::= checkExpectStatus ( ReturnCode ) [klabel(checkExpectStatus), symbol]
// ------------------------------------------------------------------------------------
rule <k> checkExpectStatus(RETURNCODE) => . ... </k>
<vmOutput> VMOutput(... returnCode: RETURNCODE) </vmOutput>
<commands> . </commands>
[priority(60)]

syntax Step ::= checkExpectMessage ( Bytes ) [klabel(checkExpectMessage), symbol]
// ---------------------------------------------------------------------------------
rule <k> checkExpectMessage(MSG) => . ... </k>
<vmOutput> VMOutput(... returnMessage: MSG) </vmOutput>
<commands> . </commands>
[priority(60)]

syntax Step ::= checkExpectLogs ( List ) [klabel(checkExpectLogs), symbol]
// --------------------------------------------------------------------------
rule <k> checkExpectLogs(LOGS) => . ... </k>
<vmOutput> VMOutput(... logs: LOGS) </vmOutput>
<commands> . </commands>
[priority(60)]
// TODO implement event logs (some host functions like ESDT transfer should emit event logs. see crowdfunding-claim-successful.json)
rule <k> checkExpectLogs(_LOGS) => . ... </k>
<commands> . </commands>
[priority(61)]

```
Expand Down Expand Up @@ -418,6 +461,7 @@ TODO make sure that none of the state changes are persisted -- [Doc](https://doc
rule <k> deployTx(FROM, VALUE, MODULE, ARGS, GASLIMIT, GASPRICE)
=> deployTxAux(#address2Bytes(FROM), VALUE, MODULE, ARGS, GASLIMIT, GASPRICE) ...
</k>
<commands> . </commands>
[priority(60)]

rule [deployTxAux]:
Expand Down Expand Up @@ -456,12 +500,18 @@ TODO make sure that none of the state changes are persisted -- [Doc](https://doc
```k
syntax Step ::= transfer(TransferTx) [klabel(transfer), symbol]
// -----------------------------------------------------
rule <k> transfer(TX) => TX ... </k> [priority(60)]
rule <k> transfer(TX) => TX ... </k>
<commands> . </commands>
[priority(60)]

syntax TransferTx ::= transferTx ( from: Address, to: Bytes, value: Int ) [klabel(transferTx), symbol]
| transferTxAux ( from: Bytes, to: Bytes, value: Int ) [klabel(transferTxAux), symbol]
// ------------------------------------------------------------------------------------------------------------
rule <k> transferTx(FROM, TO, VAL) => transferTxAux(#address2Bytes(FROM), #address2Bytes(TO), VAL) ... </k> [priority(60)]
rule <k> transferTx(FROM, TO, VAL)
=> transferTxAux(#address2Bytes(FROM), #address2Bytes(TO), VAL) ...
</k>
<commands> . </commands>
[priority(60)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the priority still needed after you added an empty commands cell to the rule? (it may be, I don't know/remember why it was useful before)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is not necessary since we have #wait and #endWasm to switch between k, commands, and instrs, but I'm not sure either.


rule <k> transferTxAux(FROM, TO, VAL) => #wait ... </k>
<commands> . => transferFunds(FROM, TO, VAL) </commands>
Expand All @@ -473,12 +523,16 @@ TODO make sure that none of the state changes are persisted -- [Doc](https://doc
```k
syntax Step ::= validatorReward(ValidatorRewardTx) [klabel(validatorReward), symbol]
// ------------------------------------------------------------------------------------
rule <k> validatorReward(TX) => TX ... </k> [priority(60)]
rule <k> validatorReward(TX) => TX ... </k>
<commands> . </commands>
[priority(60)]

syntax ValidatorRewardTx ::= validatorRewardTx ( to: Address, value: Int) [klabel(validatorRewardTx), symbol]
| validatorRewardTxAux ( to: Bytes, value: Int ) [klabel(validatorRewardTxAux), symbol]
// -------------------------------------------------------------------------------------------------------------------
rule <k> validatorRewardTx(TO, VAL) => validatorRewardTxAux(#address2Bytes(TO), VAL) ... </k> [priority(60)]
rule <k> validatorRewardTx(TO, VAL) => validatorRewardTxAux(#address2Bytes(TO), VAL) ... </k>
<commands> . </commands>
[priority(60)]

rule <k> validatorRewardTxAux(TO, VAL) => . ... </k>
<account>
Expand All @@ -490,6 +544,7 @@ TODO make sure that none of the state changes are persisted -- [Doc](https://doc
<balance> TO_BAL => TO_BAL +Int VAL </balance>
...
</account>
<commands> . </commands>
[priority(60)]

syntax Bytes ::= #incBytes(val : Bytes, inc : Int) [function]
Expand Down