casper icon indicating copy to clipboard operation
casper copied to clipboard

Reduce max length of signature in vote message

Open djrtwo opened this issue 7 years ago • 29 comments

Issue

Vote messages must be less that or equal 1024 bytes, defined by the type in the vote method signature. When parsing the signature of the vote from the vote message, we currently only enforce that the signature too is less than or equal to 1024 bytes.

https://github.com/ethereum/casper/blob/d5aed932634e28ab90d31facc6d9944be1a5d426/casper/contracts/simple_casper.v.py#L402

Due to the variable amount of bytes required to encode the other elements in the list, there is a range on the maximum length of a signature depending on the epoch or even the validator_index. To enforce more strict requirements, we propose restricting sig to length less than or equal to 934 bytes. This number assumes the other elements of the vote message take their maximal length to encode.

1024 bytes available 3 to encode the whole list 17 worst case to encode an int128 33 to encode the bytes32 hash 3 to encode the signature bytes

1024 - 3 - 17*3 - 33 - 3 == 934 bytes max for signature

Sanity checked with the following python code

import rlp
validator_index = target_epoch = source_epoch = 2**128 - 1
sig = b'\xff' * 934
target_hash = b'\xff' * 32
len(rlp.encode([validator_index, target_hash, target_epoch, source_epoch, sig])) == 1024

Note, the logout message has fewer elements so the signature could theoretically be larger than 934 for this action, but to reduce complexity, 934 should be used for logout messages as well.

Proposed Implementation

  • Define MAX_SIGNATURE_LENGTH as 934
  • Enforce sig as <= MAX_SIGNATURE_LENGTH in vote, slash, and logout
  • tests.

djrtwo avatar Apr 25 '18 05:04 djrtwo

@djrtwo Would it be better to add this enforcement in validate_signature()?

hrishikeshio avatar May 08 '18 10:05 hrishikeshio

The type declaration should handle the enforcement. I was thinking we just make the type declaration the following anywhere we are referencing the sig which is a number of places at this point (including validate_signature)

sig: bytes <= MAX_SIGNATURE_LENGTH = ...

djrtwo avatar May 08 '18 12:05 djrtwo

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


This issue now has a funding of 200.0 DAI (200.0 USD @ $1.0/DAI) attached to it.

gitcoinbot avatar May 08 '18 21:05 gitcoinbot

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


Work has been started.

These users each claimed they can complete the work by 7 months, 2 weeks ago. Please review their action plans below:

1) mkeen has started work.

Learn more on the Gitcoin Issue Details page.

gitcoinbot avatar May 09 '18 00:05 gitcoinbot

@djrtwo Your proposed solution is syntactically elegant, but from what I can see, it's going to require an enhancement to Vyper. Vyper's RLPList function sets the size of all byte array members equal to the size of the entire RLPList.

For the purposes of decoding incoming data, Vyper's RLPList requires as arguments a bytearray, and a serial list of types -- the latter is used by RLPList to decode the former into an array of native objects. It is used like this by Casper:

https://github.com/ethereum/casper/blob/dcf4caf35937800b04c6bac4a2ab13c1513b6147/casper/contracts/simple_casper.v.py#L491

The above doesn't expose any way to let Vyper's RLPList know how many bytes will be in the byte array members, so (again, linked above) RLPList just allocates a number of bytes equal to the size allocated for the entire message, in our case, 1024.

To summarize, due to the current implementation of RLPList in Vyper, the size of the variable sig referenced below must be equal to the size of the entire message (vote_msg) it's contained in.

https://github.com/ethereum/casper/blob/dcf4caf35937800b04c6bac4a2ab13c1513b6147/casper/contracts/simple_casper.v.py#L486-L496

I've looked into making some enhancements to the Vyper RLPList implementation, but it's a fairly involved undertaking, and I'd need to understand more about related project pyrlp.

Requesting a suggestion on how I should proceed.

mkeen avatar May 10 '18 16:05 mkeen

Thanks for the deep dive! I was unaware. We might decide to truncate or something, but I am going to discuss with the formal verification team that is working with us. Leaving this open for now until we decide on a move forward.

djrtwo avatar May 11 '18 00:05 djrtwo

@mkeen 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!

  • [x] warning (3 days)
  • [ ] escalation to mods (6 days)

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

gitcoinbot avatar May 15 '18 16:05 gitcoinbot

I am still working on this. Submitted a proposal to make this possible with a change to Vyper.

mkeen avatar May 17 '18 23:05 mkeen

@mkeen 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!

  • [x] warning (3 days)
  • [ ] escalation to mods (6 days)

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

gitcoinbot avatar May 21 '18 16:05 gitcoinbot

@djrtwo Can I get a 10 day snooze on this? RLPList is undergoing heavy changes RN.

mkeen avatar May 21 '18 20:05 mkeen

@mkeen I can't snooze as I'm not the founder. will have to ask @gdipri01

djrtwo avatar May 24 '18 12:05 djrtwo

Cool I just saw that the VIP got approved. Congrats!

djrtwo avatar May 24 '18 12:05 djrtwo

Thanks!

mkeen avatar May 24 '18 21:05 mkeen

@mkeen @djrtwo Just 10-day-snoozed Gitcoin Bot, appreciate the request and patience as we work out the kinks 🙂

vs77bb avatar May 25 '18 18:05 vs77bb

Hi @mkeen just checking in, is this one still pending? Hope you are doing well 🙂

vs77bb avatar Jun 06 '18 20:06 vs77bb

This is blocked by the implementation of a VIP https://github.com/ethereum/vyper/issues/818

It appears to be in their "final countdown" before beta. So I expect it to be finished in the relative short term

djrtwo avatar Jun 07 '18 12:06 djrtwo

@mkeen 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!

  • [x] warning (3 days)
  • [ ] escalation to mods (6 days)

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

gitcoinbot avatar Jun 08 '18 16:06 gitcoinbot

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


@mkeen due to inactivity, we have escalated this issue to Gitcoin's moderation team. Let us know if you believe this has been done in error!

  • [x] warning (3 days)
  • [x] escalation to mods (6 days)

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

gitcoinbot avatar Jun 11 '18 16:06 gitcoinbot

Hi @vs77bb yes still pending! But I am keeping an eye on it.

mkeen avatar Jun 11 '18 16:06 mkeen

Awesome. Thanks for the feedback!

vs77bb avatar Jun 13 '18 13:06 vs77bb

Hi there everyone. Is this issue still blocked due to your dependencies? Let me know if we can help you in any ways!

Thanks!

kuhnchris avatar Jan 21 '19 22:01 kuhnchris

@kuhnchris The repo is deprecated. No commits since Jun 2018.

hrishikeshio avatar Jan 24 '19 07:01 hrishikeshio

Well, there are still 200$ in DAI stashed in the bounty from Greg. If this repository is deprecated he should cancel the bounty so he can at least get his funds back. We'll try to mail him, thanks for the info! May I note that if this is deprecated that maybe the repository should be changed to read-only, respectively archived?

Thanks! Chris

kuhnchris avatar Jan 24 '19 07:01 kuhnchris

The repo isn't deprecated as far as I know. It would be nice to at least partially claim the bounty, since I did a bunch of analysis and spec'ed out a fix upstream. Just a thought :)

mkeen avatar Jun 10 '19 01:06 mkeen

@djrtwo @hrishikeshio your calls. cc @vs77bb

kuhnchris avatar Jun 10 '19 09:06 kuhnchris

@djrtwo @hrishikeshio @vs77bb LMK. I think it's only fair.

mkeen avatar Jun 19 '19 01:06 mkeen

Its deprecated according to https://github.com/ethereum/casper/blob/master/README.md. Anyways, I am not the decision maker or bounty sponsorer. So its not my decision. good luck.

hrishikeshio avatar Jun 19 '19 12:06 hrishikeshio

Yikes.

mkeen avatar Jun 19 '19 14:06 mkeen

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


Work for 200.0 DAI (200.0 USD @ $1.0/DAI) has been submitted by:

  1. @mkeen

@gdipri01 please take a look at the submitted work:

  • (Link Not Provided) by @mkeen

gitcoinbot avatar Jun 20 '19 15:06 gitcoinbot