-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement `loadObjectFull` for converting HostVals to ScVals on the stack * add wasm tests * add rust test * define storage configuration cells * implement host functions * Set Version: 0.1.14 --------- Co-authored-by: devops <[email protected]>
- Loading branch information
1 parent
4f2496a
commit 4bb7100
Showing
10 changed files
with
902 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.1.13 | ||
0.1.14 |
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" | |
|
||
[tool.poetry] | ||
name = "ksoroban" | ||
version = "0.1.13" | ||
version = "0.1.14" | ||
description = "K tooling for the Soroban platform" | ||
authors = [ | ||
"Runtime Verification, Inc. <[email protected]>", | ||
|
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
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,147 @@ | ||
# Ledger Host Functions | ||
|
||
```k | ||
requires "integer.md" | ||
module HOST-LEDGER | ||
imports HOST-INTEGER | ||
``` | ||
|
||
## put_contract_data | ||
|
||
```k | ||
rule [hostfun-put-contract-data]: | ||
<instrs> hostCall ( "l" , "_" , [ i64 i64 i64 .ValTypes ] -> [ i64 .ValTypes ] ) | ||
=> loadObjectFull(HostVal(VAL)) | ||
~> loadObjectFull(HostVal(KEY)) | ||
~> putContractData(Int2StorageType(STORAGE_TYPE)) | ||
... | ||
</instrs> | ||
<locals> | ||
0 |-> < i64 > KEY // HostVal | ||
1 |-> < i64 > VAL // HostVal | ||
2 |-> < i64 > STORAGE_TYPE // 0: temp, 1: persistent, 2: instance | ||
</locals> | ||
requires Int2StorageTypeValid(STORAGE_TYPE) | ||
syntax InternalInstr ::= putContractData(StorageType) [symbol(putContractData)] | ||
// --------------------------------------------------------------------------------- | ||
rule [putContractData-instance]: | ||
<instrs> putContractData(#instance) => toSmall(Void) ... </instrs> | ||
<hostStack> KEY : VAL : S => S </hostStack> | ||
<callee> CONTRACT </callee> | ||
<contract> | ||
<contractId> CONTRACT </contractId> | ||
<instanceStorage> STORAGE => STORAGE [ KEY <- VAL ] </instanceStorage> | ||
... | ||
</contract> | ||
rule [putContractData-other]: | ||
<instrs> putContractData(DUR:Durability) => toSmall(Void) ... </instrs> | ||
<hostStack> KEY : VAL : S => S </hostStack> | ||
<callee> CONTRACT </callee> | ||
<contractData> | ||
STORAGE => STORAGE [ #skey(CONTRACT, DUR, KEY) <- VAL ] | ||
</contractData> | ||
``` | ||
|
||
## has_contract_data | ||
|
||
```k | ||
rule [hostfun-has-contract-data]: | ||
<instrs> hostCall ( "l" , "0" , [ i64 i64 .ValTypes ] -> [ i64 .ValTypes ] ) | ||
=> loadObjectFull(HostVal(KEY)) | ||
~> hasContractData(Int2StorageType(STORAGE_TYPE)) | ||
... | ||
</instrs> | ||
<locals> | ||
0 |-> < i64 > KEY // HostVal | ||
1 |-> < i64 > STORAGE_TYPE // 0: temp, 1: persistent, 2: instance | ||
</locals> | ||
requires Int2StorageTypeValid(STORAGE_TYPE) | ||
syntax InternalInstr ::= hasContractData(StorageType) [symbol(hasContractData)] | ||
// --------------------------------------------------------------------------------- | ||
rule [hasContractData-instance]: | ||
<instrs> hasContractData(#instance) | ||
=> toSmall(SCBool( KEY in_keys(STORAGE) )) | ||
... | ||
</instrs> | ||
<hostStack> KEY : S => S </hostStack> | ||
<callee> CONTRACT </callee> | ||
<contract> | ||
<contractId> CONTRACT </contractId> | ||
<instanceStorage> STORAGE </instanceStorage> | ||
... | ||
</contract> | ||
rule [hasContractData-other]: | ||
<instrs> hasContractData(DUR:Durability) | ||
=> toSmall(SCBool( #skey(CONTRACT, DUR, KEY) in_keys(STORAGE) )) | ||
... | ||
</instrs> | ||
<hostStack> KEY : S => S </hostStack> | ||
<callee> CONTRACT </callee> | ||
<contractData> STORAGE </contractData> | ||
``` | ||
|
||
## get_contract_data | ||
|
||
```k | ||
rule [hostfun-get-contract-data]: | ||
<instrs> hostCall ( "l" , "1" , [ i64 i64 .ValTypes ] -> [ i64 .ValTypes ] ) | ||
=> loadObjectFull(HostVal(KEY)) | ||
~> getContractData(Int2StorageType(STORAGE_TYPE)) | ||
... | ||
</instrs> | ||
<locals> | ||
0 |-> < i64 > KEY // HostVal | ||
1 |-> < i64 > STORAGE_TYPE // 0: temp, 1: persistent, 2: instance | ||
</locals> | ||
requires Int2StorageTypeValid(STORAGE_TYPE) | ||
syntax InternalInstr ::= getContractData(StorageType) [symbol(getContractData)] | ||
// --------------------------------------------------------------------------------- | ||
rule [getContractData-instance]: | ||
<instrs> getContractData(#instance) | ||
=> allocObject(VAL) | ||
~> returnHostVal | ||
... | ||
</instrs> | ||
<hostStack> KEY : S => S </hostStack> | ||
<callee> CONTRACT </callee> | ||
<contract> | ||
<contractId> CONTRACT </contractId> | ||
<instanceStorage> ... KEY |-> VAL ... </instanceStorage> | ||
... | ||
</contract> | ||
rule [getContractData-other]: | ||
<instrs> getContractData(DUR:Durability) | ||
=> allocObject(VAL) | ||
~> returnHostVal | ||
... | ||
</instrs> | ||
<hostStack> KEY : S => S </hostStack> | ||
<callee> CONTRACT </callee> | ||
<contractData> ... #skey(CONTRACT, DUR, KEY) |-> VAL ... </contractData> | ||
``` | ||
|
||
## Helpers | ||
|
||
```k | ||
syntax StorageType ::= Int2StorageType(Int) [function, total] | ||
// ------------------------------------------------------------------------------- | ||
rule Int2StorageType(0) => #temporary | ||
rule Int2StorageType(1) => #persistent | ||
rule Int2StorageType(_) => #instance [owise] | ||
syntax Bool ::= Int2StorageTypeValid(Int) [function, total] | ||
// ------------------------------------------------------------ | ||
rule Int2StorageTypeValid(I) => 0 <=Int I andBool I <=Int 2 | ||
endmodule | ||
``` |
Oops, something went wrong.