Skip to content

Commit

Permalink
feat: Add CI (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
mertwole authored Jul 17, 2024
1 parent 9ee28a7 commit 7d5b4de
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 41 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: kuberunner
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install golang
uses: actions/setup-go@v5
with:
go-version: '1.20.1'
- name: Install foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Build
run: cargo build --all-targets
lints:
runs-on: kuberunner
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Install golang
uses: actions/setup-go@v5
with:
go-version: '1.20.1'
- name: Install foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly
- name: Run clippy
run: cargo clippy --all-targets -- -D warnings $(cat .lints | cut -f1 -d"#" | tr '\n' ' ')
- name: Run rustfmt
run: cargo fmt -- --check
7 changes: 3 additions & 4 deletions circuits/plonky2_blake2b256/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,11 @@ mod tests {
let mut pw = PartialWitness::new();
let data_bits = data
.iter()
.map(|byte| (0..8).rev().map(move |bit_idx| (byte >> bit_idx) % 2 == 1))
.flatten()
.flat_map(|byte| (0..8).rev().map(move |bit_idx| (byte >> bit_idx) % 2 == 1))
.collect::<Vec<_>>();

for i in 0..data_bits.len() {
pw.set_bool_target(targets.message[i], data_bits[i]);
for (i, bit) in data_bits.into_iter().enumerate() {
pw.set_bool_target(targets.message[i], bit);
}

let circuit = builder.build::<C>();
Expand Down
8 changes: 4 additions & 4 deletions circuits/plonky2_blake2b256/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ mod tests {
}

let a_rotate_targets = rright_word(a_targets, shift);
for i in 0..WORD_BITS {
builder.register_public_input(a_rotate_targets[i].target);
for target in a_rotate_targets {
builder.register_public_input(target.target);
}

let data = builder.build::<C>();
Expand Down Expand Up @@ -256,8 +256,8 @@ mod tests {
}

let c_targets = builder.add_words_wrapping(a_targets, b_targets);
for i in 0..WORD_BITS {
builder.register_public_input(c_targets[i].target);
for target in c_targets {
builder.register_public_input(target.target);
}

let data = builder.build::<C>();
Expand Down
2 changes: 1 addition & 1 deletion circuits/plonky2_ed25519/src/gadgets/eddsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ mod tests {

let mut rng = rand::thread_rng();
let rnd_idx = rng.gen_range(0..64);
let mut sig = SAMPLE_SIG1.clone();
let mut sig = SAMPLE_SIG1;
let rnd_value = rng.gen_range(1..=255);
sig[rnd_idx] += rnd_value;
fill_circuits::<F, D>(
Expand Down
5 changes: 2 additions & 3 deletions ethereum/client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub struct BlockMerkleRootProof {
pub merkle_root: B256,
}

#[allow(dead_code)]
#[derive(Debug, Clone)]
struct DeploymentEnv {
pub wvara_erc20: Address,
Expand Down Expand Up @@ -177,9 +178,7 @@ async fn verify_block() {
#[test]
fn verify_message_hash() {
let msg = ContentMessage {
sender: U256::from_be_bytes(H256::repeat_byte(3).to_fixed_bytes())
.try_into()
.unwrap(),
sender: U256::from_be_bytes(H256::repeat_byte(3).to_fixed_bytes()).into(),
receiver: Address::repeat_byte(3),
nonce: B256::from(U256::from(3)),
data: Bytes::from(vec![3, 3]),
Expand Down
4 changes: 2 additions & 2 deletions gear-programs/checkpoint-light-client/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ async fn init_and_updating() -> Result<()> {

let program_id = upload_program(&client, &mut listener, init).await?;

println!("program_id = {:?}", hex::encode(&program_id));
println!("program_id = {:?}", hex::encode(program_id));

println!();
println!();
Expand Down Expand Up @@ -432,7 +432,7 @@ async fn replaying_back() -> Result<()> {

let program_id = upload_program(&client, &mut listener, init).await?;

println!("program_id = {:?}", hex::encode(&program_id));
println!("program_id = {:?}", hex::encode(program_id));

println!();
println!();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ mod tests {

let data_block_target =
NodeDataBlockTarget::constant(&pad_byte_vec(bitmap.to_vec()), &mut builder);
let read_offset = builder.zero().into();
let read_offset = builder.zero();
let claimed_child_node_nibble = HalfByteTarget::constant(claimed_nibble, &mut builder);

let input = BitmapParserInputTarget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ mod tests {

let child_hash = vec![120, 200, 3, 10]
.into_iter()
.chain([0; 27].into_iter())
.chain([0; 27])
.chain(std::iter::once(99))
.collect::<Vec<_>>()
.try_into()
Expand Down Expand Up @@ -261,12 +261,11 @@ pub mod tests_common {
types: &[MockChildType],
) -> [[u8; NODE_DATA_BLOCK_BYTES]; MAX_BRANCH_NODE_DATA_LENGTH_IN_BLOCKS] {
let data = types
.into_iter()
.map(|ty| match ty {
.iter()
.flat_map(|ty| match ty {
MockChildType::Claimed(hash) => encode_claimed_node(hash).collect(),
MockChildType::NotClaimed(len) => encode_not_claimed_node(*len).collect::<Vec<_>>(),
})
.flatten()
.collect();

compose_padded_node_data(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ mod tests {
let at_target = builder.add_virtual_target();
pw.set_target(at_target, F::from_canonical_usize(at));

let data = node_data.random_read(at_target.into(), &mut builder);
let data = node_data.random_read(at_target, &mut builder);
let expected = ByteTarget::constant(expected_data, &mut builder);

data.connect(&expected, &mut builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ mod tests {

let input = NibbleParserInputTarget {
first_node_data_block: data_block_target,
read_offset: builder.zero().into(),
nibble_count: nibble_count_target.into(),
read_offset: builder.zero(),
nibble_count: nibble_count_target,
partial_address: PartialStorageAddressTarget::empty(&mut builder),
};

Expand Down
31 changes: 12 additions & 19 deletions prover/src/storage_inclusion/storage_trie_proof/storage_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ mod tests {
address_append_test_case(&[0x1, 0x2, 0x3, 0x4], &[], Some(&[0x1, 0x2, 0x3, 0x4]));

address_append_test_case(
&vec![0xA; MAX_STORAGE_ADDRESS_LENGTH_IN_NIBBLES / 2],
&[0xA; MAX_STORAGE_ADDRESS_LENGTH_IN_NIBBLES / 2],
Some(&vec![0xA; MAX_STORAGE_ADDRESS_LENGTH_IN_NIBBLES]),
&[0xA; MAX_STORAGE_ADDRESS_LENGTH_IN_NIBBLES / 2],
Some(&[0xA; MAX_STORAGE_ADDRESS_LENGTH_IN_NIBBLES]),
);
}

Expand All @@ -218,20 +218,16 @@ mod tests {
expected = "assertion `left == right` failed: Partition containing Wire(Wire { row: 130, column: 33 }) was set twice with different values: 0 != 1"
)]
fn test_address_append_overflow_fails() {
address_append_test_case(
&vec![0xA; MAX_STORAGE_ADDRESS_LENGTH_IN_NIBBLES],
&[0x1],
None,
);
address_append_test_case(&[0xA; MAX_STORAGE_ADDRESS_LENGTH_IN_NIBBLES], &[0x1], None);
}

#[test]
fn test_address_append_have_constant_verifier_data() {
let (first_cd, _) = build_test_case_circuit(&[0xA], &[0x3], Some(&[0xA, 0x3]));
let (second_cd, _) = build_test_case_circuit(
&vec![0xA; MAX_STORAGE_ADDRESS_LENGTH_IN_NIBBLES / 2],
&[0xA; MAX_STORAGE_ADDRESS_LENGTH_IN_NIBBLES / 2],
Some(&vec![0xA; MAX_STORAGE_ADDRESS_LENGTH_IN_NIBBLES]),
&[0xA; MAX_STORAGE_ADDRESS_LENGTH_IN_NIBBLES / 2],
Some(&[0xA; MAX_STORAGE_ADDRESS_LENGTH_IN_NIBBLES]),
);

assert_eq!(first_cd.verifier_only, second_cd.verifier_only);
Expand Down Expand Up @@ -274,18 +270,18 @@ mod tests {

#[test]
fn test_address_from_half_byte_targets_safe() {
address_from_half_byte_targets_safe_test_case(&pad_byte_vec(vec![]), 0, &vec![]);
address_from_half_byte_targets_safe_test_case(&pad_byte_vec(vec![]), 0, &[]);

address_from_half_byte_targets_safe_test_case(
&pad_byte_vec(vec![1, 2, 3, 4]),
4,
&vec![1, 2, 3, 4],
&[1, 2, 3, 4],
);

address_from_half_byte_targets_safe_test_case(
&pad_byte_vec(vec![1, 2, 3, 4, 5]),
3,
&vec![1, 2, 3],
&[1, 2, 3],
);
}

Expand All @@ -299,19 +295,16 @@ mod tests {
let mut pw = PartialWitness::new();

let targets = data
.into_iter()
.iter()
.map(|byte| HalfByteTarget::constant(*byte, &mut builder))
.collect::<Vec<_>>()
.try_into()
.expect("Correct length of data");

let length = builder.constant(F::from_canonical_usize(length));

let address = PartialStorageAddressTarget::from_half_byte_targets_safe(
targets,
length.into(),
&mut builder,
);
let address =
PartialStorageAddressTarget::from_half_byte_targets_safe(targets, length, &mut builder);

let expected_address = create_address_target(expected_data, &mut builder, &mut pw);

Expand Down Expand Up @@ -350,7 +343,7 @@ pub mod tests_common {
});

PartialStorageAddressTarget {
length: length.into(),
length,
padded_address: ArrayTarget::parse_exact(&mut nibble_targets),
}
}
Expand Down

0 comments on commit 7d5b4de

Please sign in to comment.