Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Update is_valid_opcode security#75

Merged
pipermerriam merged 3 commits intoethereum:masterfrom
njgheorghita:codestream-security
Aug 16, 2017
Merged

Update is_valid_opcode security#75
pipermerriam merged 3 commits intoethereum:masterfrom
njgheorghita:codestream-security

Conversation

@njgheorghita
Copy link
Contributor

What was wrong?

Codestream processing was insecure

How was it fixed?

Updated codestream processing algorithm

Cute Animal Picture

giphy 15

@njgheorghita
Copy link
Contributor Author

njgheorghita commented Aug 10, 2017

Hey @pipermerriam / @gsalgado still some cleaning and refactoring to be done, but if you don't mind giving this a quick lookover to make sure i'm on the right track/didn't miss anything important, that would be awesome!

Copy link
Member

@pipermerriam pipermerriam left a comment

Choose a reason for hiding this comment

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

Bits of feedback. Looks really good in general.

validate_is_bytes(code_bytes)
self.stream = io.BytesIO(code_bytes)
self._validity_cache = {}
self._validity_cache = set(range(0))
Copy link
Member

Choose a reason for hiding this comment

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

This should probably be changed to just set() as I think the range(0) part is not necessary. And can we now rename this to invalid_positions since it's no longer really a cache.

self.stream = io.BytesIO(code_bytes)
self._validity_cache = {}
self._validity_cache = set(range(0))
self.deepest = 0
Copy link
Member

Choose a reason for hiding this comment

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

name nitpick:

Thoughts on renaming to depth_processed to be a bit more explicit?

i = self.deepest
while i <= position:
# get opcode
with self.seek(i):
Copy link
Member

Choose a reason for hiding this comment

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

It'd be nice to do this without seeking into it. Can we just add an __getitem__ to this object so you can just do self[i] to grab the value at the given length?

# if opcode = pushxx
if opcode >= opcode_values.PUSH1 and opcode <= opcode_values.PUSH32:
# add range(xx) to val_cache
self._validity_cache.update(range((i + 1), ((i + 1) + (opcode - 95))))
Copy link
Member

Choose a reason for hiding this comment

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

For lines of code like this I've found that the following pattern makes a lot better readability

left_bound = ....
right_bound = ....
invalid_range = range(left_bound, right_bound)
self._validity_cache.update(invalid_range)

That way each line only contains a single concept which makes it easier to ingest one piece at a time.

@njgheorghita njgheorghita changed the title [WIP] Update is_valid_opcode security Update is_valid_opcode security Aug 14, 2017
@pipermerriam pipermerriam merged commit 632607c into ethereum:master Aug 16, 2017
@njgheorghita njgheorghita deleted the codestream-security branch September 7, 2017 20:40
pacrob added a commit to pacrob/py-evm that referenced this pull request Apr 11, 2023
pacrob added a commit to pacrob/py-evm that referenced this pull request Dec 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants