-
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.
Host functions for the FxDAO test (#27)
* Implement `bytes_new_from_linear_memory`, `bytes_len` * Implement `get_current_contract_address` * Set Version: 0.1.22 * Add no-op implementation for `require_auth` * Implement `kasmer_create_contract` cheatcode * Generalize `<caller>` sort * Move `callContract` to `SOROBAN-SYNTAX` to make it available for hostfun modules * Implement `call` --------- Co-authored-by: devops <[email protected]>
- Loading branch information
1 parent
d73500d
commit b44523a
Showing
16 changed files
with
993 additions
and
10 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.21 | ||
0.1.22 |
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.21" | ||
version = "0.1.22" | ||
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
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,32 @@ | ||
# ADDRESS | ||
|
||
```k | ||
requires "../configuration.md" | ||
requires "../switch.md" | ||
requires "../wasm-ops.md" | ||
requires "integer.md" | ||
module HOST-ADDRESS | ||
imports CONFIG-OPERATIONS | ||
imports WASM-OPERATIONS | ||
imports HOST-INTEGER | ||
imports SWITCH-SYNTAX | ||
``` | ||
|
||
## require_auth | ||
|
||
```k | ||
// TODO This is just a placeholder, as the auth system is out of scope for now. | ||
// This function needs to be properly implemented to handle the authorization. | ||
rule [hostfun-require-auth]: | ||
<instrs> hostCall ( "a" , "0" , [ i64 .ValTypes ] -> [ i64 .ValTypes ] ) | ||
=> toSmall(Void) | ||
... | ||
</instrs> | ||
<locals> | ||
0 |-> < i64 > _ // Address | ||
</locals> | ||
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,69 @@ | ||
# Buffer | ||
|
||
```k | ||
requires "../configuration.md" | ||
requires "../switch.md" | ||
requires "../wasm-ops.md" | ||
requires "integer.md" | ||
module HOST-BUFFER | ||
imports CONFIG-OPERATIONS | ||
imports WASM-OPERATIONS | ||
imports HOST-INTEGER | ||
imports SWITCH-SYNTAX | ||
``` | ||
|
||
## bytes_new_from_linear_memory | ||
|
||
```k | ||
rule [hostfun-bytes-new-from-linear-memory]: | ||
<instrs> hostCall ( "b" , "3" , [ i64 i64 .ValTypes ] -> [ i64 .ValTypes ] ) | ||
=> #memLoad(getMajor(HostVal(LM_POS)), getMajor(HostVal(LEN))) | ||
~> bytesNewFromLinearMemory | ||
... | ||
</instrs> | ||
<locals> | ||
0 |-> < i64 > LM_POS // U32 | ||
1 |-> < i64 > LEN // U32 | ||
</locals> | ||
requires fromSmallValid(HostVal(LM_POS)) | ||
andBool fromSmallValid(HostVal(LEN)) | ||
syntax InternalInstr ::= "bytesNewFromLinearMemory" [symbol(bytesNewFromLinearMemory)] | ||
// --------------------------------------------------------------------------------- | ||
rule [bytesNewFromLinearMemory]: | ||
<instrs> bytesNewFromLinearMemory | ||
=> allocObject(ScBytes(BS)) | ||
~> returnHostVal | ||
... | ||
</instrs> | ||
<hostStack> BS:Bytes : S => S </hostStack> | ||
``` | ||
|
||
## bytes_len | ||
|
||
```k | ||
rule [hostfun-bytes-len]: | ||
<instrs> hostCall ( "b" , "8" , [ i64 .ValTypes ] -> [ i64 .ValTypes ] ) | ||
=> loadObject(HostVal(BYTES)) | ||
~> bytesLen | ||
... | ||
</instrs> | ||
<locals> | ||
0 |-> < i64 > BYTES // Bytes HostVal | ||
</locals> | ||
syntax InternalInstr ::= "bytesLen" [symbol(bytesLen)] | ||
// --------------------------------------------------------------------------------- | ||
rule [bytesLen]: | ||
<instrs> bytesLen | ||
=> toSmall(U32(lengthBytes(BS))) | ||
... | ||
</instrs> | ||
<hostStack> ScBytes(BS) : S => S </hostStack> | ||
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,64 @@ | ||
# Call | ||
|
||
```k | ||
requires "../configuration.md" | ||
requires "../switch.md" | ||
requires "../soroban.md" | ||
requires "integer.md" | ||
module HOST-CALL | ||
imports CONFIG-OPERATIONS | ||
imports SOROBAN-SYNTAX | ||
imports HOST-INTEGER | ||
imports SWITCH-SYNTAX | ||
``` | ||
|
||
## call | ||
|
||
```k | ||
// TODO Check reentry | ||
rule [hostfun-require-auth]: | ||
<instrs> hostCall ( "d" , "_" , [ i64 i64 i64 .ValTypes ] -> [ i64 .ValTypes ] ) | ||
=> loadObject(HostVal(ARGS)) | ||
~> loadObject(HostVal(FUNC)) | ||
~> loadObject(HostVal(ADDR)) | ||
~> call | ||
... | ||
</instrs> | ||
<locals> | ||
0 |-> < i64 > ADDR // Address | ||
1 |-> < i64 > FUNC // Symbol | ||
2 |-> < i64 > ARGS // Vec | ||
</locals> | ||
syntax InternalInstr ::= "call" [symbol(call)] | ||
// ------------------------------------------ | ||
rule [call]: | ||
<instrs> call | ||
=> #waitCommands | ||
~> returnCallResult | ||
... | ||
</instrs> | ||
<hostStack> ScAddress(TO) : Symbol(FUNC) : ScVec(ARGS) : S => S </hostStack> | ||
<callee> FROM </callee> | ||
<k> (.K => callContract(FROM, TO, FUNC, ARGS)) ... </k> | ||
syntax InternalInstr ::= "returnCallResult" [symbol(returnCallResult)] | ||
// ------------------------------------------------------------------------ | ||
rule [returnCallResult-error]: | ||
<instrs> returnCallResult => trap ... </instrs> | ||
<hostStack> Error(_,_) : _ </hostStack> | ||
rule [returnCallResult]: | ||
<instrs> returnCallResult | ||
=> allocObject(RES) | ||
~> returnHostVal | ||
... | ||
</instrs> | ||
<hostStack> RES:ScVal : S => S </hostStack> | ||
[owise] | ||
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
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
Oops, something went wrong.