forked from stellar/rs-soroban-env
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Host function protocol gating (stellar#1348)
### What Allow host functions to specify its supported protocol bounds, e.g. ```diff { "name": "test", "export": "t", "functions": [ { "export": "_", "name": "dummy0", "args": [], "return": "Val", "docs": "A dummy function taking 0 arguments and performs no-op. + "min_supported_protocol": 20, + "max_supported_protocol": 21 } ] }, ``` And adds logic (mostly macro generated) that automatically checks and enforces these protocol bounds in various paths: - Host running as native. Covered by `impl Env for VmCallerEnv`. - Host running from the guest Wasm contract. Covered by Vm link-time check, as well as the dispatch functions (as a redundant safe guard). Tests are added in `tests/protocol_gate.rs`. ### Why [TODO: Why this change is being made. Include any context required to understand the why.] ### Known limitations [TODO or N/A] --------- Co-authored-by: Graydon Hoare <[email protected]>
- Loading branch information
Showing
22 changed files
with
601 additions
and
52 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
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
8 changes: 8 additions & 0 deletions
8
...ervations/test__protocol_gate__ledger_protocol_greater_than_env_protocol_should_fail.json
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,8 @@ | ||
{ | ||
" 0 begin": "cpu:14488, mem:0, prngs:-/9b4a753, objs:-/-, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-", | ||
" 1 call bytes_new_from_slice(80)": "cpu:14535", | ||
" 2 ret bytes_new_from_slice -> Ok(Bytes(obj#1))": "cpu:15516, mem:160, objs:-/1@6105f6e8", | ||
" 3 call upload_wasm(Bytes(obj#1))": "", | ||
" 4 ret upload_wasm -> Err(Error(Context, InternalError))": "cpu:504878, mem:133534", | ||
" 5 end": "cpu:504878, mem:133534, prngs:-/9b4a753, objs:-/1@6105f6e8, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-" | ||
} |
6 changes: 6 additions & 0 deletions
6
...servations/test__protocol_gate__test_additional_protocol_guardrail_during_invocation.json
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,6 @@ | ||
{ | ||
" 0 begin": "cpu:14488, mem:0, prngs:-/9b4a753, objs:-/-, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-", | ||
" 1 call protocol_gated_dummy()": "", | ||
" 2 ret protocol_gated_dummy -> Ok(Void)": "cpu:14810", | ||
" 3 end": "cpu:14810, mem:0, prngs:-/9b4a753, objs:-/-, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-" | ||
} |
38 changes: 38 additions & 0 deletions
38
soroban-env-host/observations/test__protocol_gate__test_host_protocol_gating_for_wasm.json
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,38 @@ | ||
{ | ||
" 0 begin": "cpu:14488, mem:0, prngs:-/9b4a753, objs:-/-, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-", | ||
" 1 call bytes_new_from_slice(80)": "cpu:14535", | ||
" 2 ret bytes_new_from_slice -> Ok(Bytes(obj#1))": "cpu:15516, mem:160, objs:-/1@f7fca391", | ||
" 3 call upload_wasm(Bytes(obj#1))": "", | ||
" 4 ret upload_wasm -> Err(Error(WasmVm, InvalidAction))": "cpu:504878, mem:133534", | ||
" 5 call bytes_new_from_slice(80)": "cpu:504925", | ||
" 6 ret bytes_new_from_slice -> Ok(Bytes(obj#3))": "cpu:505906, mem:133694, objs:-/2@3906a726", | ||
" 7 call upload_wasm(Bytes(obj#3))": "", | ||
" 8 ret upload_wasm -> Err(Error(WasmVm, InvalidAction))": "cpu:995268, mem:267068", | ||
" 9 call bytes_new_from_slice(80)": "cpu:995315", | ||
" 10 ret bytes_new_from_slice -> Ok(Bytes(obj#5))": "cpu:996296, mem:267228, objs:-/3@e4dbdc61", | ||
" 11 call upload_wasm(Bytes(obj#5))": "", | ||
" 12 ret upload_wasm -> Ok(Bytes(obj#7))": "cpu:1490848, mem:401372, objs:-/4@4ac3bfa9, store:-/1@1a0e9b81, foot:1@528fd006", | ||
" 13 call bytes_new_from_slice(32)": "cpu:1491288, mem:401436, objs:-/5@6a4850f0", | ||
" 14 ret bytes_new_from_slice -> Ok(Bytes(obj#11))": "cpu:1492257, mem:401548, objs:-/6@dc239eb6", | ||
" 15 call create_contract(Address(obj#9), Bytes(obj#7), Bytes(obj#11))": "", | ||
" 16 call obj_cmp(Address(obj#13), Address(obj#9))": "cpu:1493900, mem:401726, objs:-/7@cb0ab20f, auth:1@9f16c057/-", | ||
" 17 ret obj_cmp -> Ok(0)": "cpu:1494192", | ||
" 18 call get_ledger_network_id()": "cpu:1494242, auth:1@9f16c057/1@82b76fa7", | ||
" 19 ret get_ledger_network_id -> Ok(Bytes(obj#15))": "cpu:1495272, mem:401838, objs:-/8@e6d133a3", | ||
" 20 ret create_contract -> Ok(Address(obj#17))": "cpu:1513405, mem:404912, objs:-/9@992d388f, store:-/2@dc3a5709, foot:2@ed32f193, auth:-/1@aebeac48", | ||
" 21 call call(Address(obj#17), Symbol(test), Vec(obj#19))": "cpu:1514366, mem:404992, objs:-/10@9c15842c, auth:-/-", | ||
" 22 push VM:a98ace28:test()": "cpu:2006415, mem:539598, objs:-/11@3b5daa87, vm:-/1@32eec24c, stk:1@9ed5379c, auth:1@b1b428e/-", | ||
" 23 call protocol_gated_dummy()": "cpu:2008884, mem:539628, vm:-/-", | ||
" 24 ret protocol_gated_dummy -> Ok(Void)": "cpu:2009470", | ||
" 25 pop VM:a98ace28:test -> Ok(Void)": " vm:-/1@32eec24c", | ||
" 26 ret call -> Ok(Void)": " vm:-/-, stk:-, auth:-/-", | ||
" 27 call bytes_new_from_slice(80)": "cpu:2009517", | ||
" 28 ret bytes_new_from_slice -> Ok(Bytes(obj#23))": "cpu:2010498, mem:539788, objs:-/12@fbaeb755", | ||
" 29 call upload_wasm(Bytes(obj#23))": "", | ||
" 30 ret upload_wasm -> Err(Error(WasmVm, InvalidAction))": "cpu:2499860, mem:673162", | ||
" 31 call bytes_new_from_slice(80)": "cpu:2499907", | ||
" 32 ret bytes_new_from_slice -> Ok(Bytes(obj#25))": "cpu:2500888, mem:673322, objs:-/13@aa6c2723", | ||
" 33 call upload_wasm(Bytes(obj#25))": "", | ||
" 34 ret upload_wasm -> Err(Error(WasmVm, InvalidAction))": "cpu:2990250, mem:806696", | ||
" 35 end": "cpu:2990250, mem:806696, prngs:-/9b4a753, objs:-/13@aa6c2723, vm:-/-, evt:-, store:-/2@dc3a5709, foot:2@ed32f193, stk:-, auth:-/-" | ||
} |
6 changes: 6 additions & 0 deletions
6
...st/observations/test__protocol_gate__test_native_mode_calling_protocol_gated_host_fn.json
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,6 @@ | ||
{ | ||
" 0 begin": "cpu:14488, mem:0, prngs:-/9b4a753, objs:-/-, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-", | ||
" 1 call protocol_gated_dummy()": "", | ||
" 2 ret protocol_gated_dummy -> Ok(Void)": "", | ||
" 3 end": "cpu:14488, mem:0, prngs:-/9b4a753, objs:-/-, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-" | ||
} |
8 changes: 8 additions & 0 deletions
8
...rvations/test__protocol_gate__wasm_protocol_greater_than_ledger_protocol_should_fail.json
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,8 @@ | ||
{ | ||
" 0 begin": "cpu:14488, mem:0, prngs:-/9b4a753, objs:-/-, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-", | ||
" 1 call bytes_new_from_slice(80)": "cpu:14535", | ||
" 2 ret bytes_new_from_slice -> Ok(Bytes(obj#1))": "cpu:15516, mem:160, objs:-/1@6105f6e8", | ||
" 3 call upload_wasm(Bytes(obj#1))": "", | ||
" 4 ret upload_wasm -> Err(Error(WasmVm, InvalidInput))": "cpu:504878, mem:133534", | ||
" 5 end": "cpu:504878, mem:133534, prngs:-/9b4a753, objs:-/1@6105f6e8, vm:-/-, evt:-, store:-/-, foot:-, stk:-, auth:-/-" | ||
} |
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.