Skip to content

hashes of strings are computed differently at compile time and runtime #3088

@ptrcarta

Description

@ptrcarta

Version Information

  • vyper Version (output of vyper --version): 0.3.6+commit.4a2124d0
  • OS: osx
  • Python Version (output of python --version): Python 3.9.13

Folded hashes are computed on utf8 encoded strings, runtime hashes are computed on latin1 encoded strings

# @version 0.3.6

@external
@view
def compile_hash() -> bytes32:
    return keccak256('è')

@external
@view
def runtime_hash() -> bytes32:
    str:String[1] = 'è'
    return keccak256(str)

Here runtime_hash() and compile_hash() should return the same bytes32 value, but they are different. one is the hash of 0xe8 (ord('è')), the other is the hash of 0xc3a8 ('è'.encode())

How can it be fixed?

Encode strings in Keccak256 folding the same way as they are represented at runtime

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions