2

Indexed arguments will not be stored themselves. You can only search for the values, but it is impossible to retrieve the values themselves.

This is a quote from the following docs:

http://solidity.readthedocs.io/en/develop/contracts.html?highlight=topic#events

What does this mean? If I have the log object I can see the topics thus can see the indexed values..

i.e. this is an example log object, I can see the topics here: (topics = indexed arguments)

{'logIndex': 0, 'transactionIndex': 0, 'transactionHash': HexBytes('0x473921c06e0dc928bb81455406f0436489ffabbb51f3be079b9709ddb132e933'),
'blockHash': HexBytes('0x8973f427b65c73d7fc9ead31219046bca9ec8ee82f8126d0441f3a99fa6856df'), 'blockNumber': 9, 'address': '0x345cA3e014Aaf5dcA488057592ee47305D9B3e10', 'data': '0x0000000000000000000000000000000000000000000000000000000000000001', 
'topics': [HexBytes('0x6a0adf17eb20399b431dc509145e9448c952cb299ead47af739fed7289c553f5'), HexBytes('0x000000000000000000000000627306090abab3a6e1400e9345bc60c78a8bef57'), HexBytes('0x000000000000000000000000f17f52151ebef6c7334fad080c5704d77216b732')], 'type': 'mined'}
  • I just found out topics are the hashed versions of values so no way to decrypt (although you can bruteforce expected value range.. i.e. age of a person) but I think this question may rise in the future so decided to keep the question open. – EralpB Feb 16 '18 at 14:06
0

Short answer

You can actually get the value of the indexed values.

Long answer

Let's say in your logs file you get an event with indexed values

{
  address: '0xA339447189Ec1f4CD93A959c4eE758B4fB3ED516',
  topics:
   [ '0x6f60e5b2581736becbd13dcf6c74309cbe82ea5136dc0936a9db0273e8776261',
     '0x00000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1' ],
  data: '0x0000000000000000000000000000000000000000000000000000000000000005',
  blockNumber: 504611,
  transactionHash: '0x2f8e22fabd86f6c35faec5f613ccab3725b45c3340882a0468381b27bfda024c',
  transactionIndex: 0,
  blockHash: '0x3e92bbf536918228df236df3731a92f449161558a892f72a539911479c1ac112',
  logIndex: 0,
  removed: false,
  id: 'log_a41aab0a'
}

The above logs have been created using this event:

event ContractReached(address indexed from, uint number);

And the event is called with the following arguments:

ContractReached(msg.sender, 5);

You can see that the event has 2 values:

  • one indexed which is msg.sender
  • one non-indexed which is 5

The topics array consist of one event signature topic and one additional topic per indexed value (in our case just one).

Event Signature Topic: This is equal to a Keccak-256 hash of the signature of the event in utf-8.

sha3(ContractReached(address,uint256)) would equal to our first topic 6f60e5b2581736becbd13dcf6c74309cbe82ea5136dc0936a9db0273e8776261

Topic per indexed value: These ones are 32 byte hex values of the indexed arguments, they are not hashed like the signature topic was. We can see that this is an address (without the 0x infront of it): 90f8bf6a479f320ead074411a4b0e7944ea8c9c1 padded up to 32 bytes.

Data: The non-indexed values follow the same pattern as the topics containing the indexed values. They are non-hashed 32 byte hex representations of the values. The only difference is that they are all appended to the data field one after another.

Because 1 hex value is equal to a nibble(4 bits or half a byte) we end with the following data string with a length of 64 nibbles (64/2 = 32 bytes).

0000000000000000000000000000000000000000000000000000000000000005

If you then convert the hexadecimal representation of that into a decimal you would end up with 5 which is the value we passed in the event.

If our address wasn't indexed we would have received a data of size 128 nibbles.

e.g.00000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c10000000000000000000000000000000000000000000000000000000000000005

Only by eye-ing the string above you can easily see the two arguments, each being 64 nibbles.

Please feel free to correct me if anyone finds any mistake in my explanation.

  • 3
    Indexed arguments for simple types will be in the topics as is, for example address, uint, bytes; but types like string will be hashed with keccak256 and you will not be able to recover them. – Ismael Feb 17 '18 at 23:34

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.