diff --git a/mx-semantics/main/accounts/configuration.md b/mx-semantics/main/accounts/configuration.md index 992f016..e359eea 100644 --- a/mx-semantics/main/accounts/configuration.md +++ b/mx-semantics/main/accounts/configuration.md @@ -3,6 +3,7 @@ module MX-ACCOUNTS-CONFIGURATION imports INT-SYNTAX imports STRING-SYNTAX + imports MX-STORAGE-CONFIGURATION configuration @@ -19,9 +20,22 @@ module MX-ACCOUNTS-CONFIGURATION 0 + endmodule +module MX-STORAGE-CONFIGURATION + imports MX-COMMON-SYNTAX + + configuration + + + "" + mxWrappedEmpty + + +endmodule + ``` diff --git a/mx-semantics/main/accounts/hooks.md b/mx-semantics/main/accounts/esdt-hooks.md similarity index 91% rename from mx-semantics/main/accounts/hooks.md rename to mx-semantics/main/accounts/esdt-hooks.md index bd9440e..64b715d 100644 --- a/mx-semantics/main/accounts/hooks.md +++ b/mx-semantics/main/accounts/esdt-hooks.md @@ -23,8 +23,8 @@ module MX-ACCOUNTS-HOOKS rule MX#bigIntGetESDTExternalBalance ( mxStringValue(Owner:String) - , mxStringValue(TokenId:String) - , mxIntValue(Nonce:Int) + , mxStringValue(_TokenId:String) + , mxIntValue(_Nonce:Int) , .MxHookArgs ) => MX#bigIntNew(mxIntValue(0)) ... Owner diff --git a/mx-semantics/main/accounts/storage-hooks.md b/mx-semantics/main/accounts/storage-hooks.md new file mode 100644 index 0000000..b27606b --- /dev/null +++ b/mx-semantics/main/accounts/storage-hooks.md @@ -0,0 +1,12 @@ +```k + +module MX-STORAGE-HOOKS + imports MX-COMMON-SYNTAX + imports MX-STORAGE-TOOLS-SYNTAX + + rule MX#storageLoad(mxStringValue(Key:String), Destination:MxValue ) + => storageLoad(getCallee(), Key, Destination) + +endmodule + +``` diff --git a/mx-semantics/main/accounts/storage-tools.md b/mx-semantics/main/accounts/storage-tools.md new file mode 100644 index 0000000..5c31dbb --- /dev/null +++ b/mx-semantics/main/accounts/storage-tools.md @@ -0,0 +1,28 @@ +```k + +module MX-STORAGE-TOOLS-SYNTAX + imports MX-COMMON-SYNTAX + imports STRING-SYNTAX + + syntax MxInstructions ::= storageLoad(address: String, key: String, destination: MxValue) +endmodule + +module MX-STORAGE-TOOLS + imports private COMMON-K-CELL + imports private MX-ACCOUNTS-CONFIGURATION + imports private MX-COMMON-SYNTAX + imports private MX-STORAGE-TOOLS-SYNTAX + imports private STRING-SYNTAX + + rule + + storageLoad(... address: Address:String, key: _Key:String, destination: Destination:MxValue) + => storeHostValue(Destination, mxWrappedEmpty) + ... + + Address + [priority(100)] + +endmodule + +``` diff --git a/mx-semantics/main/calls/configuration.md b/mx-semantics/main/calls/configuration.md index c509fd8..b36434b 100644 --- a/mx-semantics/main/calls/configuration.md +++ b/mx-semantics/main/calls/configuration.md @@ -6,6 +6,7 @@ module MX-CALL-CONFIGURATION configuration "" + "" endmodule diff --git a/mx-semantics/main/calls/tools.md b/mx-semantics/main/calls/tools.md new file mode 100644 index 0000000..6b72a81 --- /dev/null +++ b/mx-semantics/main/calls/tools.md @@ -0,0 +1,11 @@ +```k + +module MX-CALLS-TOOLS + imports MX-COMMON-SYNTAX + imports MX-CALL-CONFIGURATION + + rule [[getCallee() => Callee]] + Callee:String +endmodule + +``` diff --git a/mx-semantics/main/mx-common.md b/mx-semantics/main/mx-common.md index 27bb479..9f501e8 100644 --- a/mx-semantics/main/mx-common.md +++ b/mx-semantics/main/mx-common.md @@ -1,15 +1,21 @@ ```k -requires "accounts/hooks.md" +requires "accounts/esdt-hooks.md" +requires "accounts/storage-hooks.md" +requires "accounts/storage-tools.md" requires "biguint/hooks.md" requires "blocks/hooks.md" requires "calls/hooks.md" +requires "calls/tools.md" module MX-COMMON imports private MX-ACCOUNTS-HOOKS imports private MX-BIGUINT-HOOKS imports private MX-BLOCKS-HOOKS imports private MX-CALLS-HOOKS + imports private MX-CALLS-TOOLS + imports private MX-STORAGE-HOOKS + imports private MX-STORAGE-TOOLS endmodule ``` \ No newline at end of file diff --git a/mx-semantics/main/syntax.md b/mx-semantics/main/syntax.md index 66b1315..f9cbbbb 100644 --- a/mx-semantics/main/syntax.md +++ b/mx-semantics/main/syntax.md @@ -6,9 +6,13 @@ module MX-COMMON-SYNTAX syntax MxValue ::= mxIntValue(Int) | mxStringValue(String) + | MxWrappedValue + syntax MxWrappedValue ::= "mxWrappedEmpty" + syntax MxInstructions ::= storeHostValue(destination: MxValue, value: MxValue) syntax MxHookName ::= r"MX#[a-zA-Z][a-zA-Z0-9]*" [token] syntax MxHookArgs ::= List{MxValue, ","} syntax HookCall ::= MxHookName "(" MxHookArgs ")" + syntax String ::= getCallee() [function, total] endmodule ``` diff --git a/mx-semantics/test/execution.md b/mx-semantics/test/execution.md index cef680c..3a99baf 100644 --- a/mx-semantics/test/execution.md +++ b/mx-semantics/test/execution.md @@ -8,16 +8,21 @@ module MX-TEST-EXECUTION-PARSING-SYNTAX syntax TestInstruction ::= "push" MxValue | "call" argcount:Int MxHookName | "get_big_int" + | "push_store_data" | getBigint(Int) | "check_eq" MxValue | setCaller(String) + | setCallee(String) | addAccount(String) | setBalance(account:String, token:String, nonce:Int, value:Int) + | setStorage(account:String, key:String, value:MxValue) | setBlockTimestamp(Int) syntax MxTest ::= NeList{TestInstruction, ";"} syntax MxValueStack ::= List{MxValue, ","} + + syntax MxWrappedValue ::= wrappedMx(MxValue) endmodule module MX-TEST-EXECUTION @@ -49,6 +54,14 @@ module MX-TEST-EXECUTION get_big_int => testGetBigInt(IntId) ... mxIntValue(IntId) , L:MxValueStack => L + rule + storeHostValue (... destination: Destination:MxValue, value: Value:MxValue) + ~> push_store_data ; Is + => Is + ... + + L:MxValueStack => Destination, Value, L + rule check_eq V => .K ... V , L:MxValueStack => L @@ -95,6 +108,10 @@ module MX-CALL-TEST rule setCaller(S:String) => .K ... _ => S + + rule + setCallee(S:String) => .K ... + _ => S endmodule module MX-ACCOUNTS-TEST @@ -109,6 +126,7 @@ module MX-ACCOUNTS-TEST => S .Bag + .Bag @@ -151,6 +169,37 @@ module MX-ACCOUNTS-TEST [priority(100)] + rule + setStorage + (... account: Account:String + , key: Key:String + , value: Value:MxValue + ) => .K + ... + + Account + Key + _ => Value + [priority(50)] + + rule + setStorage + (... account: Account:String + , key: Key:String + , value: Value:MxValue + ) => .K + ... + + Account + + .Bag => + + Key + wrappedMx(Value) + + + [priority(100)] + endmodule module MX-BLOCKS-TEST diff --git a/tests/mx/storage/data-storage.mx b/tests/mx/storage/data-storage.mx new file mode 100644 index 0000000..4a9e11e --- /dev/null +++ b/tests/mx/storage/data-storage.mx @@ -0,0 +1,10 @@ +addAccount("Owner"); +setCallee("Owner"); +setStorage("Owner", "MyKey", mxStringValue("Hello")); + +push mxIntValue(12); +push mxStringValue("MyKey"); +call 2 MX#storageLoad; +push_store_data; +check_eq mxIntValue(12); +check_eq mxWrappedEmpty diff --git a/tests/mx/storage/empty-storage.mx b/tests/mx/storage/empty-storage.mx new file mode 100644 index 0000000..d008fe2 --- /dev/null +++ b/tests/mx/storage/empty-storage.mx @@ -0,0 +1,9 @@ +addAccount("Owner"); +setCallee("Owner"); + +push mxIntValue(12); +push mxStringValue("MyKey"); +call 2 MX#storageLoad; +push_store_data; +check_eq mxIntValue(12); +check_eq mxWrappedEmpty