From b14ef68b05ab99233659396a9b2a34870f98a337 Mon Sep 17 00:00:00 2001 From: Virgil Date: Tue, 5 Nov 2024 17:39:25 +0200 Subject: [PATCH] Keccak for storage hashes --- tests/ulm-contracts/bytes_hooks.rs | 2 +- tests/ulm-contracts/single_value_mapper.rs | 4 +- tests/ulm-with-contract/erc_20_token.1.run | 44 +++++++++++----------- ulm-semantics/main/execution.md | 1 + ulm-semantics/main/hooks/bytes.md | 13 +------ 5 files changed, 28 insertions(+), 36 deletions(-) diff --git a/tests/ulm-contracts/bytes_hooks.rs b/tests/ulm-contracts/bytes_hooks.rs index c14b5ba..74c8a43 100644 --- a/tests/ulm-contracts/bytes_hooks.rs +++ b/tests/ulm-contracts/bytes_hooks.rs @@ -22,5 +22,5 @@ extern "C" { fn decode_u8(bytes_id: u64) -> (u64, u8); fn decode_signature(bytes_id: u64) -> (u64, u64); - fn hash(bytes_id: u64) -> u64; + fn hash(bytes_id: u64) -> u256; } diff --git a/tests/ulm-contracts/single_value_mapper.rs b/tests/ulm-contracts/single_value_mapper.rs index 26be625..7d77761 100644 --- a/tests/ulm-contracts/single_value_mapper.rs +++ b/tests/ulm-contracts/single_value_mapper.rs @@ -1,7 +1,7 @@ #![no_std] -struct SingleValueMapper { key: u64, value_type: () } +struct SingleValueMapper { key: u256, value_type: () } -fn new(key:u64) -> :: single_value_mapper :: SingleValueMapper { +fn new(key:u256) -> :: single_value_mapper :: SingleValueMapper { :: single_value_mapper :: SingleValueMapper { key: key, value_type: () } } diff --git a/tests/ulm-with-contract/erc_20_token.1.run b/tests/ulm-with-contract/erc_20_token.1.run index 1fa507f..e190d1a 100644 --- a/tests/ulm-with-contract/erc_20_token.1.run +++ b/tests/ulm-with-contract/erc_20_token.1.run @@ -1,25 +1,25 @@ -list_mock GetAccountStorageHook ( 7809087261546347641 ) ulmIntResult(0, u256); -list_mock SetAccountStorageHook ( 7809087261546347641 , 10000 ) ulmNoResult(); -list_mock GetAccountStorageHook ( 7089066454178295295 ) ulmIntResult(0, u256); -list_mock SetAccountStorageHook ( 7089066454178295295 , 10000 ) ulmNoResult(); -list_mock GetAccountStorageHook ( 7089066454178295295 ) ulmIntResult(10000, u256); -list_mock GetAccountStorageHook ( 7089066454178295295 ) ulmIntResult(10000, u256); -list_mock GetAccountStorageHook ( 7089066454178295295 ) ulmIntResult(10000, u256); -list_mock SetAccountStorageHook ( 7089066454178295295 , 9900 ) ulmNoResult(); -list_mock GetAccountStorageHook ( 7089066454179379067 ) ulmIntResult(0, u256); -list_mock SetAccountStorageHook ( 7089066454179379067 , 100 ) ulmNoResult(); -list_mock GetAccountStorageHook ( 7089066454178295295 ) ulmIntResult(9900, u256); -list_mock GetAccountStorageHook ( 7089066454179379067 ) ulmIntResult(100, u256); -list_mock SetAccountStorageHook ( 7089066454178299391 , 200 ) ulmNoResult(); -list_mock GetAccountStorageHook ( 7089066454178299391 ) ulmIntResult(200, u256); -list_mock SetAccountStorageHook ( 7089066454178299391 , 0 ) ulmNoResult(); -list_mock GetAccountStorageHook ( 7089066454178295295 ) ulmIntResult(9900, u256); -list_mock GetAccountStorageHook ( 7089066454178295295 ) ulmIntResult(9900, u256); -list_mock SetAccountStorageHook ( 7089066454178295295 , 9700 ) ulmNoResult(); -list_mock GetAccountStorageHook ( 7089066454179379067 ) ulmIntResult(100, u256); -list_mock SetAccountStorageHook ( 7089066454179379067 , 300 ) ulmNoResult(); -list_mock GetAccountStorageHook ( 7089066454178295295 ) ulmIntResult(9700, u256); -list_mock GetAccountStorageHook ( 7089066454179379067 ) ulmIntResult(300, u256); +list_mock GetAccountStorageHook ( 11059124170230400219182520145867018696635045254189466511817698468614930762963 ) ulmIntResult(0, u256); +list_mock SetAccountStorageHook ( 11059124170230400219182520145867018696635045254189466511817698468614930762963 , 10000 ) ulmNoResult(); +list_mock GetAccountStorageHook ( 115494845046723600673943990597816811669707739681772931244236289759170204726560 ) ulmIntResult(0, u256); +list_mock SetAccountStorageHook ( 115494845046723600673943990597816811669707739681772931244236289759170204726560 , 10000 ) ulmNoResult(); +list_mock GetAccountStorageHook ( 115494845046723600673943990597816811669707739681772931244236289759170204726560 ) ulmIntResult(10000, u256); +list_mock GetAccountStorageHook ( 115494845046723600673943990597816811669707739681772931244236289759170204726560 ) ulmIntResult(10000, u256); +list_mock GetAccountStorageHook ( 115494845046723600673943990597816811669707739681772931244236289759170204726560 ) ulmIntResult(10000, u256); +list_mock SetAccountStorageHook ( 115494845046723600673943990597816811669707739681772931244236289759170204726560 , 9900 ) ulmNoResult(); +list_mock GetAccountStorageHook ( 17171626450567201640701347902808840427582371480602455275836469707331258301780 ) ulmIntResult(0, u256); +list_mock SetAccountStorageHook ( 17171626450567201640701347902808840427582371480602455275836469707331258301780 , 100 ) ulmNoResult(); +list_mock GetAccountStorageHook ( 115494845046723600673943990597816811669707739681772931244236289759170204726560 ) ulmIntResult(9900, u256); +list_mock GetAccountStorageHook ( 17171626450567201640701347902808840427582371480602455275836469707331258301780 ) ulmIntResult(100, u256); +list_mock SetAccountStorageHook ( 97321503972240892886219376522881926110074550168465622121824657360422868161783 , 200 ) ulmNoResult(); +list_mock GetAccountStorageHook ( 97321503972240892886219376522881926110074550168465622121824657360422868161783 ) ulmIntResult(200, u256); +list_mock SetAccountStorageHook ( 97321503972240892886219376522881926110074550168465622121824657360422868161783 , 0 ) ulmNoResult(); +list_mock GetAccountStorageHook ( 115494845046723600673943990597816811669707739681772931244236289759170204726560 ) ulmIntResult(9900, u256); +list_mock GetAccountStorageHook ( 115494845046723600673943990597816811669707739681772931244236289759170204726560 ) ulmIntResult(9900, u256); +list_mock SetAccountStorageHook ( 115494845046723600673943990597816811669707739681772931244236289759170204726560 , 9700 ) ulmNoResult(); +list_mock GetAccountStorageHook ( 17171626450567201640701347902808840427582371480602455275836469707331258301780 ) ulmIntResult(100, u256); +list_mock SetAccountStorageHook ( 17171626450567201640701347902808840427582371480602455275836469707331258301780 , 300 ) ulmNoResult(); +list_mock GetAccountStorageHook ( 115494845046723600673943990597816811669707739681772931244236289759170204726560 ) ulmIntResult(9700, u256); +list_mock GetAccountStorageHook ( 17171626450567201640701347902808840427582371480602455275836469707331258301780 ) ulmIntResult(300, u256); push "uint256"; hold_list_values_from_test_stack; diff --git a/ulm-semantics/main/execution.md b/ulm-semantics/main/execution.md index e4b5952..a5034b4 100644 --- a/ulm-semantics/main/execution.md +++ b/ulm-semantics/main/execution.md @@ -6,6 +6,7 @@ requires "execution/dispatch.md" requires "execution/storage.md" requires "execution/syntax.md" requires "hooks.md" +requires "plugin/krypto.md" requires "representation.md" module ULM-EXECUTION diff --git a/ulm-semantics/main/hooks/bytes.md b/ulm-semantics/main/hooks/bytes.md index b46dae0..80b2046 100644 --- a/ulm-semantics/main/hooks/bytes.md +++ b/ulm-semantics/main/hooks/bytes.md @@ -19,6 +19,7 @@ module ULM-SEMANTICS-HOOKS-BYTES imports private BYTES imports private COMMON-K-CELL imports private K-EQUAL-SYNTAX + imports private KRYPTO imports private RUST-HELPERS imports private RUST-REPRESENTATION imports private ULM-SEMANTICS-HOOKS-BYTES-CONFIGURATION @@ -345,18 +346,8 @@ module ULM-SEMANTICS-HOOKS-BYTES rule ulmBytesHash(ptrValue(_, u64(BytesId))) => ulmBytesHash(ulmBytesId(BytesId)) - // TODO: use Keccack here. rule ulmBytesHash(ulmBytesValue(B:Bytes)) - => ptrValue(null, u64(Int2MInt(#ulmBytesHash(Bytes2Int(B, BE, Unsigned))))) - - syntax Int ::= #ulmBytesHash(Int) [function, total] - rule #ulmBytesHash(I:Int) => #ulmBytesHash(0 -Int I) requires I I requires 0 <=Int I andBool I #ulmBytesHash - ( (I &Int ((1 <>Int 64) - ) + => ptrValue(null, u256(Int2MInt(Bytes2Int(Keccak256raw(B), BE, Unsigned)))) endmodule ```