0

So what I am trying to do is create a keccak256 of an array of structs.

pragma solidity ^0.4.24;
pragma experimental ABIEncoderV2;

contract Test 
{
    struct test1 {
        address test;
        address test2;
    }

    struct test2 {
        address test3;
        test1[] test4;
    } 

    function encode (test2[] test)
      external
      returns (bytes32)
    {
         return keccak256(abi.encodePacked(  ??  ));
    }
}

So I have a structure called test1 and a structure test2 that contains an array of test1.

How can I hash them?

If I do abi.encodePacked() on test2 I get an error, if I do it on an array of test2 I get an error but If I do it like:

abi.encodePacked(test.test3, test.test4)

Then it works, but I'm not sure if it produces the expected results. Since array of test2 should work as well if that is the case.

Does anyone know exactly how this works and what concept should I use for hashing an array of structs?

  • 'Then it works, but I'm not sure if it produces the expected results. ' What do you mean by 'expected results'? – Henk Aug 3 '18 at 11:43
  • Well solidity does not give me an error and I do get a hash but I suspect it is not made from the correct data. One reason I suspect this is that I cannot make a hash from array of struct but if a struct contains an array of structs and I reference it than it is ok. The other reason is that because of this I started to do research about it and one comment I found was that It makes a hash from the memory address instead of the actual data. But I cannot find any definitive data about this so that is why I am asking here. – Tadej Vengust Aug 3 '18 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.