Skip to content

Commit

Permalink
fix v1 array
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetbout committed Aug 9, 2024
1 parent 024ffeb commit b7c252f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ cairo_test = "2.7.0"
SimpleStruct = "npx ts-node scripts/v0/SimpleStruct.ts"
SimpleStructV1 = "npx ts-node scripts/v1/SimpleStruct.ts"
StructWithArray = "npx ts-node scripts/v0/StructWithArray.ts"
StructWithArrayV1 = "npx ts-node scripts/v1/StructWithArray.ts"
StructWithMerkletree = "npx ts-node scripts/v0/StructWithMerkletree.ts"
StructWithMerkletreeV1 = "npx ts-node scripts/v1/StructWithMerkletree.ts"
StructWithU256 = "npx ts-node scripts/v0/StructWithU256.ts"
StructWithU256V1 = "npx ts-node scripts/v1/StructWithU256.ts"
format = "scarb fmt && npx prettier --write ."
Expand Down
12 changes: 7 additions & 5 deletions src/examples/v1/struct_with_array.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use hash::{LegacyHash, HashStateTrait, HashStateExTrait};
use off_chain_signature::interfaces::{IOffChainMessageHash, IStructHash, v1::StarknetDomain};

const STRUCT_WITH_ARRAY_TYPE_HASH: felt252 =
selector!("StructWithArray(some_felt252:felt,some_array:felt*)");
selector!("\"StructWithArray\"(\"some_felt252\":\"felt\",\"some_array\":\"felt*\")");

#[derive(Drop, Copy)]
struct StructWithArray {
Expand Down Expand Up @@ -41,9 +41,11 @@ impl StructHashStructWithArray of IStructHash<StructWithArray> {

impl StructHashSpanFelt252 of IStructHash<Span<felt252>> {
fn get_struct_hash(self: @Span<felt252>) -> felt252 {
let mut call_data_state = LegacyHash::hash(0, *self);
call_data_state = LegacyHash::hash(call_data_state, (*self).len());
call_data_state
let mut state = PoseidonTrait::new();
for el in (*self) {
state = state.update_with(*el);
};
state.finalize()
}
}

Expand All @@ -65,7 +67,7 @@ mod tests {
#[test]
fn test_valid_hash() {
// This value was computed using StarknetJS
let message_hash = 0x266b2350f2febce38581c6aa5b1afb829bb1466840400305fe51548ba32544e;
let message_hash = 0x723b50f650b3b037620c51955e482aeb7786fadeb0d7a384ef99278102f038f;
let mut some_array = ArrayTrait::new();
some_array.append(4);
some_array.append(2);
Expand Down
2 changes: 1 addition & 1 deletion src/examples/v1/struct_with_merkletree.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mod tests {
#[test]
fn test_valid_hash() {
// This value was computed using StarknetJS
let message_hash = 0x4e4aa6e92e1250e5277a99686aa17c411b28b83fc948df78c10f848f1b0ad30;
let message_hash = 0x2a89d9f00b3ead36ea204b956bc9ac862a5e7e0f2ad2bf790322dda9690629e;
let simple_struct = StructWithMerkletree {
some_felt252: 712,
some_merkletree_root: 0x1e3fb24d6eeb2fdf4308dd358adfb0169dcdb21b3c6bac8ca223a9af6a2bbd9
Expand Down

0 comments on commit b7c252f

Please sign in to comment.