tjayrush / simple_parser

1 stars 1 forks source link

Modern C++ code that parses solidity functions input with mutli-demensional arrays #1

Open tjayrush opened 5 years ago

tjayrush commented 5 years ago
#
# Each group of three lines below contains:
#   1. A solidity function declaration
#   2. An example of the 'input' data field (RLP) from a call to that function
#   3. That same data decoded
#
# Your goal:
#   Simple, straight forward C++ code that parses the RLP correctly and prints out the desired result.
#
# You do not have to worry about clean code. We will be re-editing it entirely. The only requirement is that
# the code works in a generic way.
#
# The main entry point to your solution will have this interface:
#
#   std::string decode(const std::string& function, const std::string& input);
#
# All the code included in your delivery must be licensed with the broadest, least
# restrictive license availble. The project will not complete sucessully if the 
# license restricts our use of the code in any way.
#

function baz(int8)
0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe
-2

function baz(int80)
0x0000000000000000000000000000000000000000000000000000b29c26f344fe
196383738119422

function baz(uint32)
0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe
4294967294

function baz(string)
0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b68656c6c6f20776f726c64000000000000000000000000000000000000000000
hello world

function baz(bytes[] a, bytes32 b)
0x0000000000000000000000000000000000000000000000000000000000000040cb93e7ddea88eb37f5419784b399cf13f7df44079d05905006044dd14bb898110000000000000000000000000000000000000000000000000000000000000003000bf9f2adc93a1da7b9e61f44ee6504f99c467a2812b354d70a07f0b3cdc58c0007cc5734453f8d7bbacd4b3a8e753250dc4a432aaa5be5b048c59e0b5ac5fc00120aa407bdbff1d93ea98dafc5f1da56b589b427167ec414bccbe0cfdfd573
[0x000bf9f2adc93a1da7b9e61f44ee6504f99c467a2812b354d70a07f0b3cdc58c, 0x0007cc5734453f8d7bbacd4b3a8e753250dc4a432aaa5be5b048c59e0b5ac5fc, 0x00120aa407bdbff1d93ea98dafc5f1da56b589b427167ec414bccbe0cfdfd573], 0xcb93e7ddea88eb37f5419784b399cf13f7df44079d05905006044dd14bb89811

function baz(int[3])
0x000000000000000000000000000000000000000000000000000000000000002afffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb
[42, -3, -5]

function baz(uint128[2][3], uint)
0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a
[[1, 2, 3], [4, 5, 6]], 10

function baz(uint128[2][3][2], uint)
0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a
[[[1, 2], [3, 4], [5, 6]], [[1, 2], [3, 4], [5, 6]]], 10

function baz(uint[3][], uint)
0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000006
[[1, 2], [3, 4], [5, 6]], 10

function baz(uint[][3],uint)
0x000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000006
[[1, 2], [3, 4], [5, 6]], 10

function baz(uint256[] a,uint[] b,uint256[] c)
0x000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000015af1d78b58c400000000000000000000000000000000000000000000000000015af1d78b58c4000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000001bc16d674ec80000
[6, 5], [25000000000000000000, 25000000000000000000], [2000000000000000000, 2000000000000000000]
gitcoinbot commented 5 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 1.502 ETH (174.99 USD @ $116.5/ETH) attached to it as part of the Great Hill Corporation fund.

tjayrush commented 5 years ago

Question for you @pbteja1998. The link you referenced to previous work builds a parser for a pre-defined language using bison. Have you looked at the Ethereum RLP definition? Will you be able to describe a language to parse the data? That sounds unnecessarily complicated. What I was hoping for was a minimal string parser that works with the multi-dimensional arrays and the RLP spec. Did you look at that? Your thoughts?

pbteja1998 commented 5 years ago

@tjayrush yes, you are right. I don't think that it is necessary to define a grammar for this purpose. A normal string parser would be enough.

And also can you explain the task at hand more clearly. What do you mean by get desired result? In other words, can you give an example of the input that will be given, and the output that is expected.

pbteja1998 commented 5 years ago

In the description you mentioned that there will be three lines, are all the three lines are part of the input or the first two lines are the input and the third line is the output expected?

pbteja1998 commented 5 years ago

If the second line is the encoded input and the third line is the decoded input that is expected, then what is the function(first line) definition for? Is it just to get the data type of input?

tjayrush commented 5 years ago

@pbteja1998 The third line is desired output. The first line defines the type of input, which is the second line, exactly as you describe.

Here's a full description of what I'm trying to decode: https://solidity.readthedocs.io/en/develop/abi-spec.html#formal-specification-of-the-encoding (but decoding not encoding).

I have the more simple parts working, but I'm stuck on the multi-dimensional arrays. I shouldn't say we can't use a grammar and use bison, I would just rather not if we don't have to. But if it's easier, then maybe that's the best way to go.

Assuming good response to this, I'll hire you if you think the price is right.

tjayrush commented 5 years ago

@benakan Can you tell me more about your experience and your thoughts on above discussion?

pbteja1998 commented 5 years ago

@tjayrush, I think what you want is a way to decode the encoded input of given type. So I don't think the grammar is necessary or useful for this case. So as you said, a normal string parser will suffice. I can start the work immediately if approved. Also can you post the link to decoding specification. Thanks.

mestorlx commented 5 years ago

@tjayrush I think what you need is already done here header and here source Not sure if the implementation is what you need but I will guess it is. Let me know if there any changes requirements and I can take care of them.

tjayrush commented 5 years ago

@pbteja1998. You were selected. Let me know if you need anything.

@mestorlx. Thanks for the pointer. I will use that code as a reference.

@pbteja1998. Please complete your work exclusive of that code. I'm looking for an implementation that works for the above data file and this specification: https://solidity.readthedocs.io/en/develop/abi-spec.html#formal-specification-of-the-encoding.

One of the purposes of the code is to stand as a totally separate source of potential test cases. Using existing code defeats that part of the process.

pbteja1998 commented 5 years ago

@tjayrush Thanks. I will start the work. Is there a gitter/slack channel that I can join or any other mode of communication to give you the updates directly and clear out any other clarifications in the process?

tjayrush commented 5 years ago

@pbteja1998 http://quickblocks.slack.com

pbteja1998 commented 5 years ago

@tjayrush I think you should give an invitation, for me to be able to join the slack channel. My email id is pbteja1998@gmail.com

tjayrush commented 5 years ago

Sent

pbteja1998 commented 5 years ago

@tjayrush I am a bit occupied for the next 2 weeks. I am going to stop work (from gitcoin) on this right now so that I don't block this issue and some other person can take this up. I will reapply this once I get free(if it were available then). Sorry for the inconvenience.

tjayrush commented 5 years ago

Wow. Serious downvote.

pbteja1998 commented 5 years ago

@tjayrush I am very sorry for wasting your time. Something came up suddenly. I will only stall the project if I would have continued.

gitcoinbot commented 5 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work has been started.

These users each claimed they can complete the work by 8 hours ago. Please review their action plans below:

1) luiserebii has been approved to start work.

Hello, I'm interested in this bounty! I have experience with both C++ and Solidity, so I am excited to tackle this project. From what I understand, I only need to implement this function: std::string decode(const std::string& function, const std::string& input); ?

I look forward to hearing back from you! Thanks :)

Learn more on the Gitcoin Issue Details page.

tjayrush commented 5 years ago

@luiserebii Yes. Write a function decode(func,input) that returns answer for each of the sets of three lines above, where first line is func and the second line input and decode should return the third line answer.

If you give me a reasonable explanation of what you plan to do, and you can start right away, I will accept you.

Luiserebii commented 5 years ago

@tjayrush To put it shortly, using the function signature passed, I will parse each parameter, and iterate over them and, by applying the specification logic used for encoding the RLP, to decode them using the Solidity ABI documentation (https://solidity.readthedocs.io/en/develop/abi-spec.htm). I will also be using Ethereum documentation on RLP encoding to write this function.

In other words, for each parameter, I will determine the number of bytes to parse depending on the type and convert them from hexadecimal into their original forms.

Since this is the RLP and not complete ABI encoding, I won't be testing that the first batch of 32 bytes match the function signature.

Please let me know if this is enough detail; if not, let me know and I will try to add more.

Thanks!

Luiserebii commented 5 years ago

I realize I left out one detail: I can start right away! Apologies if this comes off as impatient, it's more of me being anxious that my app submission is complete, haha.

tjayrush commented 5 years ago

Sorry. I'll accept your proposal now on GitHub (if I can figure out how). Cheers. You can join our slack at quickblocks.slack.com and contact me there with any questions.

Luiserebii commented 5 years ago

No worries, just wanted to make sure! Just wanted to let you know that I've started on it, and will give you updates as time passes. Thanks!

tjayrush commented 5 years ago

Just wondering how it's going or if you need anything.

Luiserebii commented 5 years ago

Hey @tjayrush, things are going well. Still writing and testing the code. I wasn't sure how to join the slack channel, I may need an invite, if you'd likely me to give updates there. Hope all is well!

gitcoinbot commented 5 years ago

@luiserebii Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

tjayrush commented 5 years ago

@Luiserebii https://join.slack.com/t/quickblocks/shared_invite/enQtNDEzNDc0MTY1MDE0LWRhYzlhOTM5ODA0N2JmZTcwNTgxODljMzE3N2JlYzgwN2M2NjZiZTEwNjZmYTgwYzkzNzljMDMyODlkNDU0ZDY

gitcoinbot commented 5 years ago

@luiserebii Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

Luiserebii commented 5 years ago

@gitcoinbot Hello, yes, I am continuing to work on this, looking to finish very soon. Thank you!

tjayrush commented 5 years ago

I extended the reminder bot, so it should bother you for a while.

gitcoinbot commented 5 years ago

@luiserebii Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

tjayrush commented 5 years ago

@Luiserebii Any news?

tjayrush commented 5 years ago

@Luiserebii please contact me via email before taking any further actions on this issue including posting to forums. Jrush@greathill.com

gitcoinbot commented 5 years ago

@luiserebii Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

Luiserebii commented 5 years ago

@tjayrush @gitcoinbot Apologies for the delay, continuing to work on this. And sure, I will contact you when I can! I've been working at this, it's just been a little tougher than expected haha

gitcoinbot commented 5 years ago

@luiserebii Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

gitcoinbot commented 5 years ago

@luiserebii Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

Luiserebii commented 5 years ago

@gitcoinbot I have submitted a WIP PR, at: https://github.com/tjayrush/simple_parser/pull/2. Will continue to work on this in the meantime, thanks!

gitcoinbot commented 5 years ago

@luiserebii Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

gitcoinbot commented 5 years ago

@luiserebii Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

Luiserebii commented 5 years ago

@gitcoinbot Yes, I am still working on this; thank you!

tjayrush commented 5 years ago

I took a look at your work. You've done a good job. Please finish as well as you can, and I will pay this out. Do you have any further work to do? I accepted your pull request.

gitcoinbot commented 5 years ago

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Work for 1.502 ETH (212.83 USD @ $141.7/ETH) has been submitted by:

  1. @luiserebii

@tjayrush please take a look at the submitted work:


Luiserebii commented 5 years ago

@tjayrush Thank you so much, I am glad that you liked what I've done! I've been working hard on getting this to work for you, most of the test cases are thankfully now passing, except for two. I made a new pull request to clean that piece up.

Unless I'm misunderstanding you, I would be very grateful for the offer to receive payment for the closest I can get to on this project! I have made the submission on Gitcoin in case you feel satisfied with this, but no pressure, since this is technically still incomplete. There is some more work to do for me unfortunately, but I will certainly try to keep at it! I hope all is well.

tjayrush commented 5 years ago

I'll pay for it now (assuming I can figure out how). I think you did a good job (the comments are very appreciated). If you open to the idea, I'll post another 1 ETH bounty to finish the work. Would that work for you? I'll try to figure out how to offer a bounty to a particular person. Look for payment on the first bounty now, and then (if you agree) I will post a second bounty to finish the work. Let me know.

tjayrush commented 5 years ago

One comment about the two above test cases: I think I had trouble with these two as well (although my code was not recursive).

Perhaps, before we proceed to try to fix these, we should make sure the 'expected' answers are correct. I tried my best to make sure the 'input' data was correct, but let's double check that first before writing code that correctly parses incorrect test case data.

gitcoinbot commented 5 years ago

@luiserebii Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

Luiserebii commented 5 years ago

@tjayrush Thank you so much! I'd be more than open to doing that, and I am happy the effort I put into the comments were not in vain.

That's a good point, I hadn't considered that. I think I'll see if I can recreate the ABI encoding and check it against those.

gitcoinbot commented 5 years ago

@luiserebii Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions!

Funders only: Snooze warnings for 1 day | 3 days | 5 days | 10 days | 100 days

gitcoinbot commented 5 years ago

⚡️ A tip worth 1.50000 ETH (219.86 USD @ $146.57/ETH) has been granted to @luiserebii for this issue from @tjayrush. ⚡️

Nice work @luiserebii! Your tip has automatically been deposited in the ETH address we have on file.