Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
from starkware.cairo.common.alloc import alloc
from starkware.cairo.common.cairo_blake2s.blake2s import blake_with_opcode
from starkware.cairo.common.cairo_blake2s.blake2s import BLAKE2S_FINALIZE_INSTRUCTION

// Computes blake2s of `input` of size 16 felts, representing 32 bits each.
// The initial state is the standard BLAKE2s IV XORed with the parameter block P[0] = 0x01010020.
func blake_with_opcode_for_single_16_length_word(data: felt*, out: felt*, initial_state: felt*) {
const BLAKE2S_FINALIZE_OPCODE_EXT = 2;
const OP0_REG = 1; // State is fp-based.
const OP1_FP = 3; // Data is fp-based.
const AP_ADD1 = 11; // Increment ap by 1 after the instruction.
const BLAKE2S_FLAGS = 2 ** OP0_REG + 2 ** OP1_FP + 2 ** AP_ADD1;

const STATE_OFFSET = -3;
const MESSAGE_OFFSET = -5;
const COUNTER_OFFSET = -1;

const POS_STATE_OFFSET = 2 ** 15 + STATE_OFFSET;
const POS_MESSAGE_OFFSET = 2 ** 15 + MESSAGE_OFFSET;
const POS_COUNTER_OFFSET = 2 ** 15 + COUNTER_OFFSET;

const BLAKE2S_FINALIZE_INSTRUCTION = POS_COUNTER_OFFSET + POS_STATE_OFFSET * 2 ** 16 +
POS_MESSAGE_OFFSET * 2 ** 32 + BLAKE2S_FLAGS * 2 ** 48 + BLAKE2S_FINALIZE_OPCODE_EXT * 2 **
63;

tempvar counter = 64;
[ap] = initial_state, ap++;
[ap] = data, ap++;
[ap] = counter, ap++;
[ap] = out;
static_assert [ap + COUNTER_OFFSET] == counter;
static_assert [fp + STATE_OFFSET] == initial_state;
static_assert [fp + MESSAGE_OFFSET] == data;
dw BLAKE2S_FINALIZE_INSTRUCTION;
// Increment AP after blake opcode.
ap += 1;
return ();
}

Expand Down
6 changes: 3 additions & 3 deletions crates/apollo_starknet_os_program/src/program_hash.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"os": "0x338203798f8c939bae2c9bd06afd80bb63595007601729b33d6739920416c24",
"aggregator": "0x110273c1890c2e09a34e3995eeeaa7e0a10fe5a8bd98c84ccf6243512f7a7e6",
"aggregator_with_prefix": "0x3ca5d4c4724e45c896bf36d26e28a7e585e61d680b3b06962af652cafa166d7"
"os": "0x7f1ad76d2bc6845ae61c5ccb2f8aae2e2ff1418b5572bebcdf2dd832556a6b0",
"aggregator": "0x31a2d2cf5b673b718d9a9ed527fc343c2744ec3bd1daf1a7b9f1a4a1fa3d21d",
"aggregator_with_prefix": "0x4460a2cd0996f05489f8339d50f317d07b06f26dd2ecd5a5540368d2cef2a9d"
}
Loading