Skip to content

Commit

Permalink
fix: clarify HashOp::Keccak variant to refer to Keccak-256 (#217)
Browse files Browse the repository at this point in the history
Co-authored-by: Carlos Rodriguez <[email protected]>
  • Loading branch information
Farhad-Shabani and crodriguezvega authored Dec 14, 2023
1 parent dad0145 commit c7c7288
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 93 deletions.
140 changes: 70 additions & 70 deletions go/proofs.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/src/generated/codecimpl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export namespace ics23 {
NO_HASH = 0,
SHA256 = 1,
SHA512 = 2,
KECCAK = 3,
KECCAK256 = 3,
RIPEMD160 = 4,
BITCOIN = 5,
SHA512_256 = 6,
Expand Down
14 changes: 7 additions & 7 deletions js/src/generated/codecimpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $root.ics23 = (function() {
* @property {number} NO_HASH=0 NO_HASH value
* @property {number} SHA256=1 SHA256 value
* @property {number} SHA512=2 SHA512 value
* @property {number} KECCAK=3 KECCAK value
* @property {number} KECCAK256=3 KECCAK256 value
* @property {number} RIPEMD160=4 RIPEMD160 value
* @property {number} BITCOIN=5 BITCOIN value
* @property {number} SHA512_256=6 SHA512_256 value
Expand All @@ -38,7 +38,7 @@ $root.ics23 = (function() {
values[valuesById[0] = "NO_HASH"] = 0;
values[valuesById[1] = "SHA256"] = 1;
values[valuesById[2] = "SHA512"] = 2;
values[valuesById[3] = "KECCAK"] = 3;
values[valuesById[3] = "KECCAK256"] = 3;
values[valuesById[4] = "RIPEMD160"] = 4;
values[valuesById[5] = "BITCOIN"] = 5;
values[valuesById[6] = "SHA512_256"] = 6;
Expand Down Expand Up @@ -1244,7 +1244,7 @@ $root.ics23 = (function() {
case 2:
message.hash = 2;
break;
case "KECCAK":
case "KECCAK256":
case 3:
message.hash = 3;
break;
Expand Down Expand Up @@ -1274,7 +1274,7 @@ $root.ics23 = (function() {
case 2:
message.prehashKey = 2;
break;
case "KECCAK":
case "KECCAK256":
case 3:
message.prehashKey = 3;
break;
Expand Down Expand Up @@ -1304,7 +1304,7 @@ $root.ics23 = (function() {
case 2:
message.prehashValue = 2;
break;
case "KECCAK":
case "KECCAK256":
case 3:
message.prehashValue = 3;
break;
Expand Down Expand Up @@ -1639,7 +1639,7 @@ $root.ics23 = (function() {
case 2:
message.hash = 2;
break;
case "KECCAK":
case "KECCAK256":
case 3:
message.hash = 3;
break;
Expand Down Expand Up @@ -2307,7 +2307,7 @@ $root.ics23 = (function() {
case 2:
message.hash = 2;
break;
case "KECCAK":
case "KECCAK256":
case 3:
message.hash = 3;
break;
Expand Down
2 changes: 1 addition & 1 deletion proto/cosmos/ics23/v1/proofs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enum HashOp {
NO_HASH = 0;
SHA256 = 1;
SHA512 = 2;
KECCAK = 3;
KECCAK256 = 3;
RIPEMD160 = 4;
BITCOIN = 5; // ripemd160(sha256(x))
SHA512_256 = 6;
Expand Down
6 changes: 3 additions & 3 deletions rust/src/cosmos.ics23.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ pub enum HashOp {
NoHash = 0,
Sha256 = 1,
Sha512 = 2,
Keccak = 3,
Keccak256 = 3,
Ripemd160 = 4,
/// ripemd160(sha256(x))
Bitcoin = 5,
Expand All @@ -289,7 +289,7 @@ impl HashOp {
HashOp::NoHash => "NO_HASH",
HashOp::Sha256 => "SHA256",
HashOp::Sha512 => "SHA512",
HashOp::Keccak => "KECCAK",
HashOp::Keccak256 => "KECCAK256",
HashOp::Ripemd160 => "RIPEMD160",
HashOp::Bitcoin => "BITCOIN",
HashOp::Sha512256 => "SHA512_256",
Expand All @@ -304,7 +304,7 @@ impl HashOp {
"NO_HASH" => Some(Self::NoHash),
"SHA256" => Some(Self::Sha256),
"SHA512" => Some(Self::Sha512),
"KECCAK" => Some(Self::Keccak),
"KECCAK256" => Some(Self::Keccak256),
"RIPEMD160" => Some(Self::Ripemd160),
"BITCOIN" => Some(Self::Bitcoin),
"SHA512_256" => Some(Self::Sha512256),
Expand Down
6 changes: 3 additions & 3 deletions rust/src/cosmos.ics23.v1.serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ impl serde::Serialize for HashOp {
Self::NoHash => "NO_HASH",
Self::Sha256 => "SHA256",
Self::Sha512 => "SHA512",
Self::Keccak => "KECCAK",
Self::Keccak256 => "KECCAK256",
Self::Ripemd160 => "RIPEMD160",
Self::Bitcoin => "BITCOIN",
Self::Sha512256 => "SHA512_256",
Expand All @@ -1004,7 +1004,7 @@ impl<'de> serde::Deserialize<'de> for HashOp {
"NO_HASH",
"SHA256",
"SHA512",
"KECCAK",
"KECCAK256",
"RIPEMD160",
"BITCOIN",
"SHA512_256",
Expand Down Expand Up @@ -1056,7 +1056,7 @@ impl<'de> serde::Deserialize<'de> for HashOp {
"NO_HASH" => Ok(HashOp::NoHash),
"SHA256" => Ok(HashOp::Sha256),
"SHA512" => Ok(HashOp::Sha512),
"KECCAK" => Ok(HashOp::Keccak),
"KECCAK256" => Ok(HashOp::Keccak256),
"RIPEMD160" => Ok(HashOp::Ripemd160),
"BITCOIN" => Ok(HashOp::Bitcoin),
"SHA512_256" => Ok(HashOp::Sha512256),
Expand Down
14 changes: 7 additions & 7 deletions rust/src/host_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ pub trait HostFunctionsProvider {
/// The SHA-512 hash algorithm with its output truncated to 256 bits.
fn sha2_512_truncated(message: &[u8]) -> [u8; 32];

/// SHA-3-512 hash function.
fn sha3_512(message: &[u8]) -> [u8; 64];
/// The Keccak-256 hash function.
fn keccak_256(message: &[u8]) -> [u8; 32];

/// Ripemd160 hash function.
/// The Ripemd160 hash function.
fn ripemd160(message: &[u8]) -> [u8; 20];

/// BLAKE2b-512 hash function.
Expand All @@ -33,7 +33,7 @@ pub mod host_functions_impl {
use blake2::{Blake2b512, Blake2s256};
use ripemd::Ripemd160;
use sha2::{Digest, Sha256, Sha512, Sha512_256};
use sha3::Sha3_512;
use sha3::Keccak256;

pub struct HostFunctionsManager;
impl HostFunctionsProvider for HostFunctionsManager {
Expand All @@ -58,9 +58,9 @@ pub mod host_functions_impl {
buf
}

fn sha3_512(message: &[u8]) -> [u8; 64] {
let digest = Sha3_512::digest(message);
let mut buf = [0u8; 64];
fn keccak_256(message: &[u8]) -> [u8; 32] {
let digest = Keccak256::digest(message);
let mut buf = [0u8; 32];
buf.copy_from_slice(&digest);
buf
}
Expand Down
Loading

0 comments on commit c7c7288

Please sign in to comment.