Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes reference to sha3 to keccak256. #2316

Merged
merged 3 commits into from
Jun 9, 2020
Merged

Conversation

MicahZoltu
Copy link
Contributor

Ethereum doesn't use sha3 anywhere, and later in the document it explicitly states that this is actually keccak256. To avoid people implementing SHA3 only to find out it doesn't work (like I did), I'm fixing this to be keccak256.

Ethereum doesn't use `sha3` anywhere, and later in the document it explicitly states that this is actually `keccak256`.  To avoid people implementing SHA3 only to find out it doesn't work (like I did), I'm fixing this to be `keccak256`.
Copy link
Member

@axic axic left a comment

Choose a reason for hiding this comment

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

I think this makes sense.

@axic
Copy link
Member

axic commented Oct 25, 2019

@vbuterin @alexvandesande any objections?

@alexvansande
Copy link

So my understanding is that the sha3 is the standardization of the Keccak algorithm, but with a small implementation differences regarding padding of data, correct? I see no issue at all with the change honestly.

@axic
Copy link
Member

axic commented Oct 30, 2019

Correct.

but with a small implementation differences regarding padding of data

That small difference is enough to result in an entirely different output and hence they are referred to independently for clarity.

@axic
Copy link
Member

axic commented Oct 30, 2019

@MicahZoltu there is one annoying fact here, that piece of code actually works and uses this package https://pypi.org/project/ethereum/. Just checked, and it still only has sha3 and not keccak256 as a function. Perhaps keep the code as is and leave a disclaimer in a comment above it?

@MicahZoltu
Copy link
Contributor Author

For a reference implementation, I don't think it is appropriate to have code that reads incorrectly but then has a comment indicating what the correct thing to do is. Instead, I would prefer to either:

  1. turn the snippet into pseudocode (remove the import and just reference made-up functions with descriptive names)
  2. find an alternative dependency library with proper names.
  3. swap out the reference implementation with a different language that allows us to write a reference implementation that properly names things (e.g., JavaScript).

@axic axic mentioned this pull request Nov 1, 2019
@carver
Copy link
Contributor

carver commented Feb 18, 2020

  1. find an alternative dependency library with proper names.

ethereum/eth-utils is a reasonable option for this. Some (working) example code:

import eth_utils
  

def checksum_encode(addr): # Takes a 20-byte binary address as input
    hex_addr = addr.hex()
    checksummed_buffer = ""
     
    # Treat the hex address as ascii/utf-8 for keccak256 hashing
    hashed_address = eth_utils.keccak(text=hex_addr).hex()
    
    # Iterate over each character in the hex address
    for nibble_index, character in enumerate(hex_addr):

        if character in "0123456789":
            # We can't upper-case the decimal digits 
            checksummed_buffer += character
        elif character in "abcdef":
            # Check if the corresponding hex digit (nibble) in the hash is 8 or higher 
            hashed_address_nibble = int(hashed_address[nibble_index], 16)
            if hashed_address_nibble > 7:
                checksummed_buffer += character.upper()
            else:
                checksummed_buffer += character
        else:
            raise eth_utils.ValidationError(
                f"Unrecognized hex character {character!r} at position {nibble_index}"
            )

    return "0x" + checksummed_buffer
 

def test(addr_str):
    addr_bytes = eth_utils.to_bytes(hexstr=addr_str)
    checksum_encoded = checksum_encode(addr_bytes)
    assert checksum_encoded == addr_str, f"{checksum_encoded} != expected {addr_str}"
   

test("0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed")
test("0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359")
test("0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB")
test("0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb")

If you want to add it to your branch @MicahZoltu , I opened a PR against it with this ^ code.

carver and others added 2 commits February 18, 2020 11:55
Replace the pyethereum code, because it's deprecated, and because it
uses the name "sha3" for the hashing function, rather than the clearer
"keccak".
@MicahZoltu
Copy link
Contributor Author

Updated with changes proposed by @carver

@axic
Copy link
Member

axic commented Feb 19, 2020

Looking at the entire EIP (and not just the diff), I think it would make sense to change it as follows:

  1. Specification to start with an explanation in english
  2. Followed by some short pseudo-code
  3. Moving the python code under the Implementations heading

It may be an unreasonable burden to @MicahZoltu trying to improve this EIP, so I am happy to merge it as is, but the above is what would be my preference.

@MicahZoltu
Copy link
Contributor Author

MicahZoltu commented Feb 19, 2020

I think the changes you suggest @axic are good improvements to this EIP, though I would prefer they appear as a separate PR that gets merged after this one. That being said, if you want to submit a PR to my branch with the proposed changes I'm willing to merge them prior to merging this if that gets this in sooner. 😊 This PR is rapidly growing larger than the original one-word change though...

I believe this EIP was written before we had good standards/practices for EIP writing, so it isn't as of high a quality as some of the newer stuff that is well structured.

@axic
Copy link
Member

axic commented Feb 19, 2020

@alexvansande can you please check again?

@MicahZoltu
Copy link
Contributor Author

@axic or @holiman Can one of you merge this? I see you both approved it, but it has been sitting for months with no feedback.

@axic
Copy link
Member

axic commented Jun 4, 2020

I'd really prefer the original authors to give some indication, ping @vbuterin @alexvansande ?

@gcolvin gcolvin merged commit 3bc86ff into ethereum:master Jun 9, 2020
@MicahZoltu MicahZoltu deleted the patch-5 branch June 9, 2020 06:00
pizzarob pushed a commit to pizzarob/EIPs that referenced this pull request Jun 12, 2020
* Changes reference to `sha3` to `keccak256`.

Ethereum doesn't use `sha3` anywhere, and later in the document it explicitly states that this is actually `keccak256`.  To avoid people implementing SHA3 only to find out it doesn't work (like I did), I'm fixing this to be `keccak256`.

* Use eth-utils for eip-55 example code

Replace the pyethereum code, because it's deprecated, and because it
uses the name "sha3" for the hashing function, rather than the clearer
"keccak".

Co-authored-by: Jason Carver <ut96caarrs@snkmail.com>
tkstanczak pushed a commit to tkstanczak/EIPs that referenced this pull request Nov 7, 2020
* Changes reference to `sha3` to `keccak256`.

Ethereum doesn't use `sha3` anywhere, and later in the document it explicitly states that this is actually `keccak256`.  To avoid people implementing SHA3 only to find out it doesn't work (like I did), I'm fixing this to be `keccak256`.

* Use eth-utils for eip-55 example code

Replace the pyethereum code, because it's deprecated, and because it
uses the name "sha3" for the hashing function, rather than the clearer
"keccak".

Co-authored-by: Jason Carver <ut96caarrs@snkmail.com>
Arachnid pushed a commit to Arachnid/EIPs that referenced this pull request Mar 6, 2021
* Changes reference to `sha3` to `keccak256`.

Ethereum doesn't use `sha3` anywhere, and later in the document it explicitly states that this is actually `keccak256`.  To avoid people implementing SHA3 only to find out it doesn't work (like I did), I'm fixing this to be `keccak256`.

* Use eth-utils for eip-55 example code

Replace the pyethereum code, because it's deprecated, and because it
uses the name "sha3" for the hashing function, rather than the clearer
"keccak".

Co-authored-by: Jason Carver <ut96caarrs@snkmail.com>
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.

6 participants