-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Mx BigUint hooks (#66) * Framework for Mx tests * BigUint operations - new+add * bigIntSub hook * Add bigIntMul hook * Add a bigIntDiv hook * BigInt comparison --------- Co-authored-by: Virgil Serbanuta <Virgil Serbanuta> * Mx blockchain hooks (#67) * MX getCaller hook * Mx get-sc-balance hook * MX getBlockTimestamp hook --------- Co-authored-by: Virgil <[email protected]>
- Loading branch information
1 parent
8d7551e
commit e012fe1
Showing
28 changed files
with
618 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
```k | ||
module MX-ACCOUNTS-CONFIGURATION | ||
imports INT-SYNTAX | ||
imports STRING-SYNTAX | ||
configuration | ||
<mx-accounts> | ||
<mx-account multiplicity="*" type="Map"> | ||
// TODO: The address should be bytes. | ||
<mx-account-address> "" </mx-account-address> | ||
<mx-esdt-datas> | ||
<mx-esdt-data multiplicity="*" type="Map"> | ||
// TODO: The esdt-id should be bytes. | ||
<mx-esdt-id> | ||
<mx-esdt-id-name> "" </mx-esdt-id-name> | ||
<mx-esdt-id-nonce> 0 </mx-esdt-id-nonce> | ||
</mx-esdt-id> | ||
<mx-esdt-balance> 0 </mx-esdt-balance> | ||
</mx-esdt-data> | ||
</mx-esdt-datas> | ||
</mx-account> | ||
</mx-accounts> | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
```k | ||
module MX-ACCOUNTS-HOOKS | ||
imports private COMMON-K-CELL | ||
imports private MX-ACCOUNTS-CONFIGURATION | ||
imports private MX-COMMON-SYNTAX | ||
rule | ||
<k> MX#bigIntGetESDTExternalBalance | ||
( mxStringValue(Owner:String) | ||
, mxStringValue(TokenId:String) | ||
, mxIntValue(Nonce:Int) | ||
, .MxHookArgs | ||
) => MX#bigIntNew(mxIntValue(Balance)) ... </k> | ||
<mx-account-address> Owner </mx-account-address> | ||
<mx-esdt-id> | ||
<mx-esdt-id-name> TokenId </mx-esdt-id-name> | ||
<mx-esdt-id-nonce> Nonce </mx-esdt-id-nonce> | ||
</mx-esdt-id> | ||
<mx-esdt-balance> Balance:Int </mx-esdt-balance> | ||
[priority(50)] | ||
rule | ||
<k> MX#bigIntGetESDTExternalBalance | ||
( mxStringValue(Owner:String) | ||
, mxStringValue(TokenId:String) | ||
, mxIntValue(Nonce:Int) | ||
, .MxHookArgs | ||
) => MX#bigIntNew(mxIntValue(0)) ... </k> | ||
<mx-account-address> Owner </mx-account-address> | ||
[priority(100)] | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
```k | ||
module MX-BIGUINT-CONFIGURATION | ||
imports INT | ||
imports MAP | ||
configuration | ||
<mx-biguint> | ||
<bigIntHeap> .Map </bigIntHeap> | ||
<bigIntHeapNextId> 0 </bigIntHeapNextId> | ||
</mx-biguint> | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
```k | ||
module MX-BIGUINT-HOOKS | ||
imports private BOOL | ||
imports private COMMON-K-CELL | ||
imports private K-EQUAL-SYNTAX | ||
imports private MX-BIGUINT-CONFIGURATION | ||
imports private MX-COMMON-SYNTAX | ||
rule | ||
<k> MX#bigIntNew(mxIntValue(Value:Int)) => mxIntValue(NextId) ... </k> | ||
<bigIntHeap> Ints:Map => Ints[NextId <- Value] </bigIntHeap> | ||
<bigIntHeapNextId> NextId => NextId +Int 1 </bigIntHeapNextId> | ||
rule | ||
<k> MX#bigIntAdd(mxIntValue(Id1:Int) , mxIntValue(Id2:Int)) | ||
=> mxIntValue(NextId) | ||
... | ||
</k> | ||
<bigIntHeap> | ||
Ints:Map | ||
=> Ints [ NextId | ||
<- {Ints[Id1] orDefault 0}:>Int | ||
+Int {Ints[Id2] orDefault 0}:>Int | ||
] | ||
</bigIntHeap> | ||
<bigIntHeapNextId> NextId => NextId +Int 1 </bigIntHeapNextId> | ||
requires Id1 in_keys(Ints) andBool isInt(Ints[Id1] orDefault 0) | ||
andBool Id2 in_keys(Ints) andBool isInt(Ints[Id2] orDefault 0) | ||
rule | ||
<k> MX#bigIntSub(mxIntValue(Id1:Int) , mxIntValue(Id2:Int)) | ||
=> mxIntValue(NextId) | ||
... | ||
</k> | ||
<bigIntHeap> | ||
Ints:Map | ||
=> Ints [ NextId | ||
<- {Ints[Id1] orDefault 0}:>Int | ||
-Int {Ints[Id2] orDefault 0}:>Int | ||
] | ||
</bigIntHeap> | ||
<bigIntHeapNextId> NextId => NextId +Int 1 </bigIntHeapNextId> | ||
requires Id1 in_keys(Ints) andBool isInt(Ints[Id1] orDefault 0) | ||
andBool Id2 in_keys(Ints) andBool isInt(Ints[Id2] orDefault 0) | ||
rule | ||
<k> MX#bigIntMul(mxIntValue(Id1:Int) , mxIntValue(Id2:Int)) | ||
=> mxIntValue(NextId) | ||
... | ||
</k> | ||
<bigIntHeap> | ||
Ints:Map | ||
=> Ints [ NextId | ||
<- {Ints[Id1] orDefault 0}:>Int | ||
*Int {Ints[Id2] orDefault 0}:>Int | ||
] | ||
</bigIntHeap> | ||
<bigIntHeapNextId> NextId => NextId +Int 1 </bigIntHeapNextId> | ||
requires Id1 in_keys(Ints) andBool isInt(Ints[Id1] orDefault 0) | ||
andBool Id2 in_keys(Ints) andBool isInt(Ints[Id2] orDefault 0) | ||
rule | ||
<k> MX#bigIntDiv(mxIntValue(Id1:Int) , mxIntValue(Id2:Int)) | ||
=> mxIntValue(NextId) | ||
... | ||
</k> | ||
<bigIntHeap> | ||
Ints:Map | ||
=> Ints [ NextId | ||
<- {Ints[Id1] orDefault 0}:>Int | ||
/Int {Ints[Id2] orDefault 0}:>Int | ||
] | ||
</bigIntHeap> | ||
<bigIntHeapNextId> NextId => NextId +Int 1 </bigIntHeapNextId> | ||
requires Id1 in_keys(Ints) andBool isInt(Ints[Id1] orDefault 0) | ||
andBool Id2 in_keys(Ints) andBool isInt(Ints[Id2] orDefault 0) | ||
andBool Ints[Id2] orDefault 0 =/=K 0 | ||
rule | ||
<k> MX#bigIntCmp(mxIntValue(Id1:Int) , mxIntValue(Id2:Int)) | ||
=> mxIntValue | ||
( #cmpInt | ||
( {Ints[Id1] orDefault 0}:>Int | ||
, {Ints[Id2] orDefault 0}:>Int | ||
) | ||
) | ||
... | ||
</k> | ||
<bigIntHeap> Ints:Map </bigIntHeap> | ||
requires Id1 in_keys(Ints) andBool isInt(Ints[Id1] orDefault 0) | ||
andBool Id2 in_keys(Ints) andBool isInt(Ints[Id2] orDefault 0) | ||
syntax Int ::= #cmpInt ( Int , Int ) [function, total, symbol(cmpInt), smtlib(cmpInt)] | ||
rule #cmpInt(I1, I2) => -1 requires I1 <Int I2 | ||
rule #cmpInt(I1, I2) => 1 requires I1 >Int I2 | ||
rule #cmpInt(I1, I2) => 0 requires I1 ==Int I2 | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
```k | ||
module MX-BLOCKS-CONFIGURATION | ||
imports INT-SYNTAX | ||
configuration | ||
<mx-blocks> | ||
<mx-current-block> | ||
<mx-current-block-timestamp> 0 </mx-current-block-timestamp> | ||
</mx-current-block> | ||
</mx-blocks> | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
```k | ||
module MX-BLOCKS-HOOKS | ||
imports private COMMON-K-CELL | ||
imports private MX-BLOCKS-CONFIGURATION | ||
imports private MX-COMMON-SYNTAX | ||
rule | ||
<k> MX#getBlockTimestamp ( .MxHookArgs ) => mxIntValue(T) ... </k> | ||
<mx-current-block-timestamp> T </mx-current-block-timestamp> | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
```k | ||
module MX-CALL-CONFIGURATION | ||
imports STRING | ||
configuration | ||
<mx-call-data> | ||
<mx-caller> "" </mx-caller> | ||
</mx-call-data> | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
```k | ||
module MX-CALLS-HOOKS | ||
imports private COMMON-K-CELL | ||
imports private MX-CALL-CONFIGURATION | ||
imports private MX-COMMON-SYNTAX | ||
rule | ||
<k> MX#getCaller ( .MxHookArgs ) => mxStringValue(Caller) ... </k> | ||
<mx-caller> Caller:String </mx-caller> | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
```k | ||
requires "accounts/configuration.md" | ||
requires "biguint/configuration.md" | ||
requires "blocks/configuration.md" | ||
requires "calls/configuration.md" | ||
module MX-COMMON-CONFIGURATION | ||
imports MX-ACCOUNTS-CONFIGURATION | ||
imports MX-BIGUINT-CONFIGURATION | ||
imports MX-BLOCKS-CONFIGURATION | ||
imports MX-CALL-CONFIGURATION | ||
configuration | ||
<mx-common> | ||
<mx-call-data/> | ||
<mx-biguint/> | ||
<mx-blocks/> | ||
<mx-accounts/> | ||
</mx-common> | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
```k | ||
requires "accounts/hooks.md" | ||
requires "biguint/hooks.md" | ||
requires "blocks/hooks.md" | ||
requires "calls/hooks.md" | ||
module MX-COMMON | ||
imports private MX-ACCOUNTS-HOOKS | ||
imports private MX-BIGUINT-HOOKS | ||
imports private MX-BLOCKS-HOOKS | ||
imports private MX-CALLS-HOOKS | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
```k | ||
module MX-COMMON-SYNTAX | ||
imports INT-SYNTAX | ||
imports STRING-SYNTAX | ||
syntax MxValue ::= mxIntValue(Int) | ||
| mxStringValue(String) | ||
syntax MxHookName ::= r"MX#[a-zA-Z][a-zA-Z0-9]*" [token] | ||
syntax MxHookArgs ::= List{MxValue, ","} | ||
syntax HookCall ::= MxHookName "(" MxHookArgs ")" | ||
endmodule | ||
``` |
Oops, something went wrong.