Skip to content

Commit

Permalink
Merge branch 'main' into newhint28-verify-zero
Browse files Browse the repository at this point in the history
  • Loading branch information
Oppen committed Apr 15, 2023
2 parents 86ed377 + 1a89550 commit cbbf46d
Show file tree
Hide file tree
Showing 15 changed files with 2,101 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Description of the pull request changes and motivation.
- [ ] This change requires new documentation.
- [ ] Documentation has been added/updated.
- [ ] CHANGELOG has been updated.

1 change: 1 addition & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: "Pull Request Workflow"
on:
merge_group:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: rust

on:
merge_group:
push:
branches: [ main ]
pull_request:
Expand Down
257 changes: 250 additions & 7 deletions CHANGELOG.md

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Release Process
- [ ] Pull latest from `main` branch.
`git checkout main && git pull origin main`
- [ ] Determine release version string dependending on whether changes included
in changelog are API breaking, it's a release candidate, etc.
The release string should have the format "vX.Y.Z", with a possible
trailing "-rcN" and follow [semantic versioning](https://semver.org/).
- [ ] Checkout branch named `release-N` where N is the version string.
`git checkout -b release-N`
- [ ] Update the version field in the package entry of `Cargo.toml` files.
- The versions must be the same.
- There are 4 relevant `Cargo.toml` files in the repo:
- `Cargo.toml`: update the version string.
- `cairo-vm-cli/Cargo.toml`: update the version string and also the `cairo-vm` dependency version to match the above.
- `felt/Cargo.toml`: update the version string.
- `deps/parse-hyperlinks/Cargo.toml`: this vendored dependency needs its version bumped, but does not need to match the other crate versions.
- [Here](https://github.com/lambdaclass/cairo-rs/pull/948/files) is an example pull request with these changes.
- [ ] Run `cargo update` and `git add Cargo.lock`
- [ ] Update `CHANGELOG.md`:
- Verify that the changelog is up to date.
- Add a title with the release version string just below the `Upcoming Changes` section.
- [ ] Commit your changes, push your branch, and create a pull request.
- [ ] Merge after CI and review passes.
- [ ] Pull latest from `main` again.
- [ ] Tag commit with version string and push tag.
`git tag -a <version string> -m "Release..."`
- [ ] Watch the `publish` workflow run in Github Actions.
- [ ] Verify all the crates are available on crates.io with the correct versions.
- [cairo-vm](https://crates.io/crates/cairo-vm)
- [cairo-felt](https://crates.io/crates/cairo-felt)
- [cairo-take-until-unbalanced](https://crates.io/crates/cairo-take_until_unbalanced)
- [ ] Create a release in Github.
- Select the recently created tag.
- Set the title to the version string.
- If it is a release candidate, mark it as a draft release.
- [ ] Announce release through corresponding channels.

88 changes: 88 additions & 0 deletions cairo_programs/_keccak_alternative_hint.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
%builtins output range_check bitwise

from starkware.cairo.common.cairo_keccak.keccak import (
_prepare_block,
KECCAK_FULL_RATE_IN_BYTES,
KECCAK_FULL_RATE_IN_WORDS,
KECCAK_STATE_SIZE_FELTS,
)
from starkware.cairo.common.math import assert_nn_le
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin
from starkware.cairo.common.alloc import alloc
from starkware.cairo.common.serialize import serialize_word

func _keccak{range_check_ptr, bitwise_ptr: BitwiseBuiltin*, keccak_ptr: felt*}(
inputs: felt*, n_bytes: felt, state: felt*
) -> (output: felt*) {
alloc_locals;
if (nondet %{ ids.n_bytes >= ids.KECCAK_FULL_RATE_IN_BYTES %} != 0) {
_prepare_block(inputs=inputs, n_bytes=KECCAK_FULL_RATE_IN_BYTES, state=state);
_block_permutation();

return _keccak(
inputs=inputs + KECCAK_FULL_RATE_IN_WORDS,
n_bytes=n_bytes - KECCAK_FULL_RATE_IN_BYTES,
state=keccak_ptr - KECCAK_STATE_SIZE_FELTS,
);
}

assert_nn_le(n_bytes, KECCAK_FULL_RATE_IN_BYTES - 1);

_prepare_block(inputs=inputs, n_bytes=n_bytes, state=state);
_block_permutation();

return (output=keccak_ptr - KECCAK_STATE_SIZE_FELTS);
}

func _block_permutation{keccak_ptr: felt*}() {
%{
from starkware.cairo.common.cairo_keccak.keccak_utils import keccak_func
_keccak_state_size_felts = int(ids.KECCAK_STATE_SIZE_FELTS)
assert 0 <= _keccak_state_size_felts < 100

output_values = keccak_func(memory.get_range(
ids.keccak_ptr - _keccak_state_size_felts, _keccak_state_size_felts))
segments.write_arg(ids.keccak_ptr, output_values)
%}
let keccak_ptr = keccak_ptr + KECCAK_STATE_SIZE_FELTS;

return ();
}

func fill_array(array: felt*, base: felt, array_length: felt, iterator: felt) {
if (iterator == array_length) {
return ();
}

assert array[iterator] = base;

return fill_array(array, base, array_length, iterator + 1);
}

func main{output_ptr: felt*, range_check_ptr, bitwise_ptr: BitwiseBuiltin*}() {
alloc_locals;

let (output: felt*) = alloc();
let keccak_output = output;

let (inputs: felt*) = alloc();
let inputs_start = inputs;
fill_array(inputs, 9, 3, 0);

let (state: felt*) = alloc();
let state_start = state;
fill_array(state, 5, 25, 0);

let n_bytes = 24;

let (res: felt*) = _keccak{keccak_ptr=keccak_output}(
inputs=inputs_start, n_bytes=n_bytes, state=state_start
);

serialize_word(res[0]);
serialize_word(res[1]);
serialize_word(res[2]);
serialize_word(res[4]);

return ();
}
2 changes: 1 addition & 1 deletion cairo_programs/is_quad_residue_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ func main{output_ptr: felt*}() {

check_quad_res(inputs, expected, 0);

return();
return ();
}
19 changes: 19 additions & 0 deletions cairo_programs/uint256.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ from starkware.cairo.common.uint256 import (
uint256_signed_nn,
uint256_unsigned_div_rem,
uint256_mul,
uint256_mul_div_mod
)
from starkware.cairo.common.alloc import alloc

Expand Down Expand Up @@ -57,6 +58,24 @@ func main{range_check_ptr: felt}() {
assert b_quotient = Uint256(1, 0);
assert b_remainder = Uint256(340282366920938463463374607431768211377, 0);

let (a_quotient_low, a_quotient_high, a_remainder) = uint256_mul_div_mod(
Uint256(89, 72),
Uint256(3, 7),
Uint256(107, 114),
);
assert a_quotient_low = Uint256(143276786071974089879315624181797141668, 4);
assert a_quotient_high = Uint256(0, 0);
assert a_remainder = Uint256(322372768661941702228460154409043568767, 101);

let (b_quotient_low, b_quotient_high, b_remainder) = uint256_mul_div_mod(
Uint256(-3618502788666131213697322783095070105282824848410658236509717448704103809099, 2),
Uint256(1, 1),
Uint256(5, 2),
);
assert b_quotient_low = Uint256(170141183460469231731687303715884105688, 1);
assert b_quotient_high = Uint256(0, 0);
assert b_remainder = Uint256(170141183460469231731687303715884105854, 1);

let (mult_low_a, mult_high_a) = uint256_mul(Uint256(59, 2), Uint256(10, 0));
assert mult_low_a = Uint256(590, 20);
assert mult_high_a = Uint256(0, 0);
Expand Down
Loading

0 comments on commit cbbf46d

Please sign in to comment.