Skip to content

accounts/abi: Index inputs are not present in output#15568

Closed
dshulyak wants to merge 3 commits into
ethereum:masterfrom
dshulyak:indexed_inputs
Closed

accounts/abi: Index inputs are not present in output#15568
dshulyak wants to merge 3 commits into
ethereum:masterfrom
dshulyak:indexed_inputs

Conversation

@dshulyak
Copy link
Copy Markdown
Contributor

@dshulyak dshulyak commented Nov 28, 2017

solves: #15567 #15617

@GitCop
Copy link
Copy Markdown

GitCop commented Nov 28, 2017

Thank you for your contribution! Your commits seem to not adhere to the repository coding standards

  • Commit: 1095a29e6a7f2b46531890c3503578694d5dc521
  • Commits must be prefixed with the package(s) they modify

Please check the contribution guidelines for more details.


This message was auto-generated by https://gitcop.com

@dshulyak dshulyak changed the title Index inputs are not present in output accounts/abi: Index inputs are not present in output Nov 28, 2017
@holiman
Copy link
Copy Markdown
Contributor

holiman commented Nov 29, 2017

@VoR0220 Would you mind taking a look at this? I find that code a bit difficult to follow, and don't understand why the fix works, and if there are any other sideeffects of it.

@dshulyak
Copy link
Copy Markdown
Contributor Author

Because of this
https://github.com/ethereum/go-ethereum/pull/15568/files#diff-7af5eed2bdda4c04119f5dba36a637b4R80

if an event has 3 fields, and 2 of them are indexed - following function will expect that data for 3rd field will be in 2*32:96 range of the output. But the encoded output doesn't contain fields that are indexed and following error is returned:

2017/11/28 13:34:28 abi: cannot marshal in to go type: length insufficient 32 require 96

maybe it would be better to have all the fields in log.Data, but then this condition won't be needed https://github.com/ethereum/go-ethereum/pull/15568/files#diff-7af5eed2bdda4c04119f5dba36a637b4R71

@VoR0220
Copy link
Copy Markdown
Member

VoR0220 commented Nov 29, 2017

Yup, this is my bad. While I took into account that indexed types should be skipped, it doesn't appear I did so in terms of how long the bytecode should be. This appears to correct that, however the tests are a little confusing to read.

Comment thread accounts/abi/event.go
input := e.Inputs[i]
if input.Indexed {
// indexed inputs are not available in log output
j--
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fairly elegant. Works for me.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second thought, I'm not sure this plays nicely with a static array element insofar as indexing is concerned.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for review, i added required test, but i think that i spotted another issue with array types. please see my comment below

Copy link
Copy Markdown
Member

@VoR0220 VoR0220 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to take into account static array indexing and how that interacts with the changes prescribed.

Comment thread accounts/abi/event_test.go Outdated
{
definition: `[{"anonymous":false,"inputs":[{"indexed":false,"name":"value1","type":"uint256"},{"indexed":true,"name":"value2","type":"uint256"}],"name":"transfer","type":"event"}]`,
want: testResult{Value1: big.NewInt(100)},
},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test that should be added for the sake of sanity would be in the case of a indexed static array type. Say for example I'm passing in an indexed uint[2], and a non indexed string, this should take into account the length of the static array and ignore it...perhaps this should be handled by another variable in the events.go file above to best handle this.

@GitCop
Copy link
Copy Markdown

GitCop commented Nov 30, 2017

Thank you for your contribution! Your commits seem to not adhere to the repository coding standards

  • Commit: 362fb00fd6e03810242b032c7d37a42ad4c2054b
  • Your commit message body contains a line that is longer than 80 characters

Please check the contribution guidelines for more details.


This message was auto-generated by https://gitcop.com

Comment thread accounts/abi/event.go Outdated
Copy link
Copy Markdown
Contributor Author

@dshulyak dshulyak Nov 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In current codebase array fields are counted before unpacking output.
So, if we have array with 2 fields: toGoType function will try to unpack
values from 64 till 64 + 2*32 which is not correct in my opinion.

Counting will be done after processing array, so in case array is the first
field, and it has 2 elements: we will read it from 0 till 2*32, and next element will start at 64.

Copy link
Copy Markdown
Contributor Author

@dshulyak dshulyak Nov 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using this contract for test:


contract Test {
  
  event Echo(uint8[2] message, address from);
  
  function emit() {
    uint8[2] memory r = [1,2]; 
    Echo(r, msg.sender);
  }

}

Error message:
2017/11/30 12:37:46 abi: cannot marshal in to go array: offset 96 would go over slice boundary (len=128)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would that be incorrect? Sounds right at the beginning.

Copy link
Copy Markdown
Contributor Author

@dshulyak dshulyak Dec 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is that correct? example that i provided actually fails on current master

let's say we will try to unpack an event with ([7,8], 9) all simple integers,
it will be encoded as

0000000000000000000000000000000000000000000000000000000000000007
0000000000000000000000000000000000000000000000000000000000000008
0000000000000000000000000000000000000000000000000000000000000009

without this change we will try to read array from 64 till 128, and integer from 96 till 128, and actually will fail with this error 2017/12/07 16:04:29 abi: cannot marshal in to go array: offset 96 would go over slice boundary (len=128)

with this change first read will be done from 0 till 64 (array), and for integer from 64 till 96

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Okay. Yea I'm sorry for the wait, I've reviewed the code, it looks fairly good, but I would just add a comment about the j += input.Type.Size - 1...specifically why you're subtracting the 1. Just leave a comment on that and I'll approve this...for whatever that's worth.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VoR0220 added a comment

@gballet gballet self-requested a review December 1, 2017 13:29
@dshulyak
Copy link
Copy Markdown
Contributor Author

dshulyak commented Dec 4, 2017

@VoR0220 would you mind taking a look again?

In current codebase array fields are counted before unpacking output.
So, if we have array with 2 fields: toGoType function will try to unpack
values from 64 till 64 + 2*32 which is not correct in my opinion.

I shifted counting to be done after processing array,
so in case array is the first field,
and it has 2 elements: we will read it from 0 till 2*32.

Additionally array doesnt require length prefix, so field that follows array
should be read from 64 byte.
This is why i made additional substitution in this change.
@dshulyak
Copy link
Copy Markdown
Contributor Author

dshulyak commented Dec 7, 2017

@gballet perhaps you can help with review?

@GitCop
Copy link
Copy Markdown

GitCop commented Dec 8, 2017

Thank you for your contribution! Your commits seem to not adhere to the repository coding standards

  • Commit: 9b8e32023bf26405933ca3640d38310dc05bbccb
  • Commits must be prefixed with the package(s) they modify

Please check the contribution guidelines for more details.


This message was auto-generated by https://gitcop.com

@dshulyak
Copy link
Copy Markdown
Contributor Author

dshulyak commented Dec 8, 2017

@VoR0220 @gballet I improved tests for fixes, i believe they do better job at explaining the problem now

@dshulyak dshulyak force-pushed the indexed_inputs branch 2 times, most recently from b959674 to 10c4590 Compare December 8, 2017 11:39
Copy link
Copy Markdown
Member

@VoR0220 VoR0220 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is GTM from my end @gballet @holiman

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants