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

[WIP] Update keccak-builtin #873

Merged
merged 21 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 35 additions & 24 deletions Cargo.lock

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

18 changes: 18 additions & 0 deletions cairo_programs/keccak_builtin.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
%builtins keccak
from starkware.cairo.common.cairo_builtins import KeccakBuiltin
from starkware.cairo.common.keccak_state import KeccakBuiltinState

func main{keccak_ptr: KeccakBuiltin*}() {
assert keccak_ptr[0].input = KeccakBuiltinState(1,2,3,4,5,6,7,8);
let result = keccak_ptr[0].output;
let keccak_ptr = keccak_ptr + KeccakBuiltin.SIZE;
assert result.s0 = 528644516554364142278482415480021626364691973678134577961206;
assert result.s1 = 768681319646568210457759892191562701823009052229295869963057;
assert result.s2 = 1439835513376369408063324968379272676079109225238241190228026;
assert result.s3 = 1150396629165612276474514703759718478742374517669870754478270;
assert result.s4 = 1515147102575186161827863034255579930572231617017100845406254;
assert result.s5 = 1412568161597072838250338588041800080889949791225997426843744;
assert result.s6 = 982235455376248641031519404605670648838699214888770304613539;
assert result.s7 = 1339947803093378278438908448344904300127577306141693325151040;
return ();
}
7 changes: 0 additions & 7 deletions src/hint_processor/builtin_hint_processor/keccak_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,3 @@ fn left_pad(bytes_vector: &mut [u8], n_zeros: usize) -> Vec<u8> {

res
}

pub(crate) fn left_pad_u64(bytes_vector: &mut [u64], n_zeros: usize) -> Vec<u64> {
let mut res: Vec<u64> = vec![0; n_zeros];
res.extend(bytes_vector.iter());

res
}
11 changes: 4 additions & 7 deletions src/vm/errors/runner_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use thiserror::Error;
use thiserror_no_std::Error;

use super::memory_errors::MemoryError;
use crate::types::{
errors::math_errors::MathError,
relocatable::{MaybeRelocatable, Relocatable},
};
use crate::types::{errors::math_errors::MathError, relocatable::Relocatable};
use felt::Felt;

#[derive(Debug, PartialEq, Error)]
Expand Down Expand Up @@ -37,7 +34,7 @@ pub enum RunnerError {
#[error("Given builtins are not in appropiate order")]
DisorderedBuiltins,
#[error("Expected integer at address {0:?} to be smaller than 2^{1}, Got {2}")]
IntegerBiggerThanPowerOfTwo(MaybeRelocatable, u32, Felt),
IntegerBiggerThanPowerOfTwo(Relocatable, u32, Felt),
#[error("{0}")]
EcOpSameXCoordinate(String),
#[error("EcOpBuiltin: point {0:?} is not on the curve")]
Expand Down Expand Up @@ -84,8 +81,8 @@ pub enum RunnerError {
Math(#[from] MathError),
#[error("keccak_builtin: Failed to get first input address")]
KeccakNoFirstInput,
#[error("keccak_builtin: Failed to convert input cells to u64 values")]
KeccakInputCellsNotU64,
#[error("{0}: Expected integer at address {1}")]
BuiltinExpectedInteger(&'static str, Relocatable),
#[error("keccak_builtin: Failed to convert input cells to u64 values")]
KeccakInputCellsNotU64,
}
4 changes: 2 additions & 2 deletions src/vm/runners/builtin_runner/bitwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ impl BitwiseBuiltinRunner {
) {
if num_x.bits() > self.bitwise_builtin.total_n_bits as u64 {
return Err(RunnerError::IntegerBiggerThanPowerOfTwo(
x_addr.into(),
x_addr,
self.bitwise_builtin.total_n_bits,
num_x.clone(),
));
};
if num_y.bits() > self.bitwise_builtin.total_n_bits as u64 {
return Err(RunnerError::IntegerBiggerThanPowerOfTwo(
y_addr.into(),
y_addr,
self.bitwise_builtin.total_n_bits,
num_y.clone(),
));
Expand Down