Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

feat(acir)!: Add Keccak256 Opcode #91

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions acir/src/circuit/black_box_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub enum BlackBoxFunc {
HashToField128Security,
EcdsaSecp256k1,
FixedBaseScalarMul,
Keccak256,
}

impl std::fmt::Display for BlackBoxFunc {
Expand All @@ -44,6 +45,7 @@ impl BlackBoxFunc {
BlackBoxFunc::AND => 9,
BlackBoxFunc::XOR => 10,
BlackBoxFunc::RANGE => 11,
BlackBoxFunc::Keccak256 => 12,
}
}
pub fn from_u16(index: u16) -> Option<Self> {
Expand All @@ -60,6 +62,7 @@ impl BlackBoxFunc {
9 => BlackBoxFunc::AND,
10 => BlackBoxFunc::XOR,
11 => BlackBoxFunc::RANGE,
12 => BlackBoxFunc::Keccak256,
_ => return None,
};
Some(function)
Expand All @@ -78,6 +81,7 @@ impl BlackBoxFunc {
BlackBoxFunc::AND => "and",
BlackBoxFunc::XOR => "xor",
BlackBoxFunc::RANGE => "range",
BlackBoxFunc::Keccak256 => "keccak256",
}
}
pub fn lookup(op_name: &str) -> Option<BlackBoxFunc> {
Expand All @@ -94,6 +98,7 @@ impl BlackBoxFunc {
"and" => Some(BlackBoxFunc::AND),
"xor" => Some(BlackBoxFunc::XOR),
"range" => Some(BlackBoxFunc::RANGE),
"keccak256" => Some(BlackBoxFunc::Keccak256),
_ => None,
}
}
Expand Down Expand Up @@ -162,6 +167,11 @@ impl BlackBoxFunc {
input_size: InputSize::Fixed(1),
output_size: OutputSize(0),
},
BlackBoxFunc::Keccak256 => FuncDefinition {
name,
input_size: InputSize::Variable,
output_size: OutputSize(32),
},
}
}
}
Expand Down