Skip to content

Commit

Permalink
Keccak for storage hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
virgil-serbanuta committed Nov 5, 2024
1 parent f06babd commit b14ef68
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 36 deletions.
2 changes: 1 addition & 1 deletion tests/ulm-contracts/bytes_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions tests/ulm-contracts/single_value_mapper.rs
Original file line number Diff line number Diff line change
@@ -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: () }
}
44 changes: 22 additions & 22 deletions tests/ulm-with-contract/erc_20_token.1.run
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions ulm-semantics/main/execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions ulm-semantics/main/hooks/bytes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <Int 0
rule #ulmBytesHash(I:Int) => I requires 0 <=Int I andBool I <Int (1 <<Int 64)
rule #ulmBytesHash(I:Int)
=> #ulmBytesHash
( (I &Int ((1 <<Int 64) -Int 1))
|Int #ulmBytesHash(I >>Int 64)
)
=> ptrValue(null, u256(Int2MInt(Bytes2Int(Keccak256raw(B), BE, Unsigned))))
endmodule
```

0 comments on commit b14ef68

Please sign in to comment.