Skip to content

Commit

Permalink
eth-precompiles: Fix RipeMD into non zero-init buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim committed Jan 26, 2025
1 parent 4757592 commit b581c0f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions constantine/ethereum_evm_precompiles.nim
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func eth_evm_ripemd160*(r: var openArray[byte], inputs: openArray[byte]): CttEVM
if r.len != 32:
return cttEVM_InvalidOutputSize

r.toOpenArray(0, 11).setZero()
# Need to only write to last 20 bytes. Hence fist `toOpenArray` & then cast & deref
ripemd160.hash(cast[ptr array[20, byte]](toOpenArray(r, 12, 31)[0].addr)[], inputs)
return cttEVM_Success
Expand Down
3 changes: 2 additions & 1 deletion tests/t_ethereum_evm_precompiles.nim
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ proc testRipemd160() =
var expectedbytes = newSeq[byte](expected.len div 2)
expectedbytes.fromHex(expected)

var r = newSeq[byte](expected.len div 2)
var r = newSeq[byte](expected.len div 2) # Canary value
r.fromHex"AAAABBBBCCCCDDDDEEEEFFFF0000111122223333444455556666777788889999"

let status = eth_evm_ripemd160(r, inputbytes)
if status != cttEVM_Success:
Expand Down

0 comments on commit b581c0f

Please sign in to comment.