Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call data coding #167

Merged
merged 18 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.build
.DS_store
blockchain-k-plugin
tmp
tmp.*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "blockchain-k-plugin"]
path = deps/blockchain-k-plugin
url = https://github.com/runtimeverification/blockchain-k-plugin
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ FROM runtimeverificationinc/kframework-k:ubuntu-noble-${K_COMMIT}
RUN apt-get update \
&& apt-get upgrade --yes \
&& apt-get install --yes \
curl
curl \
libcrypto++-dev \
libsecp256k1-dev \
libssl-dev

ARG USER_ID=1001
ARG GROUP_ID=1001
Expand Down
24 changes: 18 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ ukm-no-contracts-test: $(UKM_NO_CONTRACT_TESTING_OUTPUTS)

ukm-with-contracts-test: $(UKM_WITH_CONTRACT_TESTING_OUTPUTS)

deps/blockchain-k-plugin/build/krypto/lib/krypto.a:
make -C deps/blockchain-k-plugin build

$(RUST_PREPROCESSING_TIMESTAMP): $(RUST_SEMANTICS_FILES)
# Workaround for https://github.com/runtimeverification/k/issues/4141
-rm -r $(RUST_PREPROCESSING_KOMPILED)
Expand Down Expand Up @@ -181,30 +184,39 @@ $(MX_RUST_TWO_CONTRACTS_TESTING_TIMESTAMP): $(MX_SEMANTICS_FILES) $(RUST_SEMANTI
-I . \
--debug

$(UKM_EXECUTION_TIMESTAMP): $(UKM_SEMANTICS_FILES) $(RUST_SEMANTICS_FILES)
$(UKM_EXECUTION_TIMESTAMP): $(UKM_SEMANTICS_FILES) $(RUST_SEMANTICS_FILES) deps/blockchain-k-plugin/build/krypto/lib/krypto.a
# Workaround for https://github.com/runtimeverification/k/issues/4141
-rm -r $(UKM_EXECUTION_KOMPILED)
$$(which kompile) ukm-semantics/targets/execution/ukm-target.md \
$$(which kompile) ukm-semantics/targets/execution/ukm-target.md \
--hook-namespaces KRYPTO -ccopt -g -ccopt -std=c++17 -ccopt -lcrypto \
-ccopt -lsecp256k1 -ccopt -lssl -ccopt 'deps/blockchain-k-plugin/build/krypto/lib/krypto.a' \
--emit-json -o $(UKM_EXECUTION_KOMPILED) \
-I kllvm \
-I deps/blockchain-k-plugin \
-I . \
--debug

$(UKM_PREPROCESSING_TIMESTAMP): $(UKM_SEMANTICS_FILES) $(RUST_SEMANTICS_FILES)
$(UKM_PREPROCESSING_TIMESTAMP): $(UKM_SEMANTICS_FILES) $(RUST_SEMANTICS_FILES) deps/blockchain-k-plugin/build/krypto/lib/krypto.a
# Workaround for https://github.com/runtimeverification/k/issues/4141
-rm -r $(UKM_PREPROCESSING_KOMPILED)
$$(which kompile) ukm-semantics/targets/preprocessing/ukm-target.md \
$$(which kompile) ukm-semantics/targets/preprocessing/ukm-target.md \
--hook-namespaces KRYPTO -ccopt -g -ccopt -std=c++17 -ccopt -lcrypto \
-ccopt -lsecp256k1 -ccopt -lssl -ccopt 'deps/blockchain-k-plugin/build/krypto/lib/krypto.a' \
--emit-json -o $(UKM_PREPROCESSING_KOMPILED) \
-I . \
-I deps/blockchain-k-plugin \
--debug

$(UKM_TESTING_TIMESTAMP): $(UKM_SEMANTICS_FILES) $(RUST_SEMANTICS_FILES)
$(UKM_TESTING_TIMESTAMP): $(UKM_SEMANTICS_FILES) $(RUST_SEMANTICS_FILES) deps/blockchain-k-plugin/build/krypto/lib/krypto.a
# Workaround for https://github.com/runtimeverification/k/issues/4141
-rm -r $(UKM_TESTING_KOMPILED)
$$(which kompile) ukm-semantics/targets/testing/ukm-target.md \
$$(which kompile) ukm-semantics/targets/testing/ukm-target.md \
--hook-namespaces KRYPTO -ccopt -g -ccopt -std=c++17 -ccopt -lcrypto \
-ccopt -lsecp256k1 -ccopt -lssl -ccopt 'deps/blockchain-k-plugin/build/krypto/lib/krypto.a' \
${PLUGIN_FLAGS} \
--emit-json -o $(UKM_TESTING_KOMPILED) \
-I . \
-I deps/blockchain-k-plugin \
-I kllvm \
--debug

Expand Down
1 change: 1 addition & 0 deletions deps/blockchain-k-plugin
Submodule blockchain-k-plugin added at e6994c
1 change: 1 addition & 0 deletions tests/ukm-contracts/bytes_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ extern "C" {
fn decode_u8(bytes_id: u64) -> (u64, u8);
fn decode_str(bytes_id: u64) -> (u64, str);

fn decode_signature(bytes_id: u64) -> (u64, str);
virgil-serbanuta marked this conversation as resolved.
Show resolved Hide resolved
fn hash(bytes_id: u64) -> u64;
}
32 changes: 14 additions & 18 deletions tests/ukm-with-contract/endpoints.1.run
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
call :: bytes_hooks :: empty;
return_value_to_arg;
push "myEndpoint(Uint64)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push 123_u64;
call :: bytes_hooks :: append_u64;
return_value;
mock CallData;
push "myEndpoint";
hold_string_from_test_stack;
push "uint64";
hold_list_values_from_test_stack;
push 123_u64;
hold_list_values_from_test_stack;
encode_call_data;

return_value;
mock CallData;

call_contract 12345;
return_value;
check_eq ();

push_status;
check_eq 2;

output_to_arg;
call :: test_helpers :: decode_single_u64;
return_value;

check_eq 126_u64

push_status;
check_eq 2;
output_to_arg; call :: test_helpers :: decode_single_u64; return_value;
check_eq 126_u64
9 changes: 9 additions & 0 deletions tests/ukm-with-contract/endpoints.2.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
push "myEndpoint";
hold_string_from_test_stack;
push "uint64";
hold_list_values_from_test_stack;
push 1_u64;
hold_list_values_from_test_stack;
encode_call_data_to_string;
return_value;
check_eq "81922854\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"
135 changes: 60 additions & 75 deletions tests/ukm-with-contract/erc_20_token.1.run
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ list_mock SetAccountStorageHook ( 7162266444908917614 , 300 ) ukmNoResult();
list_mock GetAccountStorageHook ( 7162266444907899391 ) ukmIntResult(9700, u256);
list_mock GetAccountStorageHook ( 7162266444908917614 ) ukmIntResult(300, u256);

call :: bytes_hooks :: empty;
return_value_to_arg;
push "#init(Uint256)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "#init";
hold_string_from_test_stack;
push "uint256";
hold_list_values_from_test_stack;
push 10000_u256;
call :: bytes_hooks :: append_u256;
hold_list_values_from_test_stack;
encode_call_data;


return_value;
mock CallData;

Expand All @@ -49,14 +51,13 @@ check_eq 0_u32;




call :: bytes_hooks :: empty;
return_value_to_arg;
push "balanceOf(Uint160)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "balanceOf";
hold_string_from_test_stack;
push "uint160";
hold_list_values_from_test_stack;
push 1010101_u160;
call :: bytes_hooks :: append_u160;
hold_list_values_from_test_stack;
encode_call_data;
return_value;
mock CallData;

Expand All @@ -74,17 +75,15 @@ return_value;
check_eq 10000_u256;



call :: bytes_hooks :: empty;
return_value_to_arg;
push "transfer(Uint160,Uint256)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "transfer";
hold_string_from_test_stack;
push "uint160";
push "uint256";
hold_list_values_from_test_stack;
push 2020202_u160;
call :: bytes_hooks :: append_u160;
return_value_to_arg;
push 100_u256;
call :: bytes_hooks :: append_u256;
hold_list_values_from_test_stack;
encode_call_data;
return_value;
mock CallData;

Expand All @@ -105,14 +104,13 @@ return_value;
check_eq 1_u64;



call :: bytes_hooks :: empty;
return_value_to_arg;
push "balanceOf(Uint160)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "balanceOf";
hold_string_from_test_stack;
push "uint160";
hold_list_values_from_test_stack;
push 1010101_u160;
call :: bytes_hooks :: append_u160;
hold_list_values_from_test_stack;
encode_call_data;
return_value;
mock CallData;

Expand All @@ -130,15 +128,13 @@ return_value;
check_eq 9900_u256;




call :: bytes_hooks :: empty;
return_value_to_arg;
push "balanceOf(Uint160)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "balanceOf";
hold_string_from_test_stack;
push "uint160";
hold_list_values_from_test_stack;
push 2020202_u160;
call :: bytes_hooks :: append_u160;
hold_list_values_from_test_stack;
encode_call_data;
return_value;
mock CallData;

Expand All @@ -156,20 +152,15 @@ return_value;
check_eq 100_u256;






call :: bytes_hooks :: empty;
return_value_to_arg;
push "approve(Uint160,Uint256)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "approve";
hold_string_from_test_stack;
push "uint160";
push "uint256";
hold_list_values_from_test_stack;
push 3030303_u160;
call :: bytes_hooks :: append_u160;
return_value_to_arg;
push 200_u256;
call :: bytes_hooks :: append_u256;
hold_list_values_from_test_stack;
encode_call_data;
return_value;
mock CallData;

Expand All @@ -190,20 +181,17 @@ return_value;
check_eq 1_u64;



call :: bytes_hooks :: empty;
return_value_to_arg;
push "transferFrom(Uint160,Uint160,Uint256)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "transferFrom";
hold_string_from_test_stack;
push "uint160";
push "uint160";
push "uint256";
hold_list_values_from_test_stack;
push 1010101_u160;
call :: bytes_hooks :: append_u160;
return_value_to_arg;
push 2020202_u160;
call :: bytes_hooks :: append_u160;
return_value_to_arg;
push 200_u256;
call :: bytes_hooks :: append_u256;
hold_list_values_from_test_stack;
encode_call_data;
return_value;
mock CallData;

Expand All @@ -225,15 +213,13 @@ check_eq 1_u64;





call :: bytes_hooks :: empty;
return_value_to_arg;
push "balanceOf(Uint160)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "balanceOf";
hold_string_from_test_stack;
push "uint160";
hold_list_values_from_test_stack;
push 1010101_u160;
call :: bytes_hooks :: append_u160;
hold_list_values_from_test_stack;
encode_call_data;
return_value;
mock CallData;

Expand All @@ -252,14 +238,13 @@ check_eq 9700_u256;




call :: bytes_hooks :: empty;
return_value_to_arg;
push "balanceOf(Uint160)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "balanceOf";
hold_string_from_test_stack;
push "uint160";
hold_list_values_from_test_stack;
push 2020202_u160;
call :: bytes_hooks :: append_u160;
hold_list_values_from_test_stack;
encode_call_data;
return_value;
mock CallData;

Expand Down
19 changes: 9 additions & 10 deletions tests/ukm-with-contract/events.1.run
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
call :: bytes_hooks :: empty;
return_value_to_arg;
push "logEvent(Uint64,Uint64)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "logEvent";
hold_string_from_test_stack;
push "uint64";
push "uint64";
hold_list_values_from_test_stack;
push 123_u64;
call :: bytes_hooks :: append_u64;
return_value_to_arg;
push 555_u64;
call :: bytes_hooks :: append_u64;
return_value;
push 555_u64;
hold_list_values_from_test_stack;
encode_call_data;
return_value;
mock CallData;

call_contract 12345;
Expand Down
12 changes: 6 additions & 6 deletions tests/ukm-with-contract/require.false.run
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
call :: bytes_hooks :: empty;
return_value_to_arg;
push "myEndpoint(Uint64)";
call :: bytes_hooks :: append_str;
return_value_to_arg;
push "myEndpoint";
hold_string_from_test_stack;
push "uint64";
hold_list_values_from_test_stack;
push 0_u64;
call :: bytes_hooks :: append_u64;
hold_list_values_from_test_stack;
encode_call_data;
return_value;
mock CallData;

Expand Down
Loading
Loading