Skip to content

Commit

Permalink
rustfmt fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tsahee committed Jul 19, 2023
1 parent ed4ad20 commit 7803bab
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
39 changes: 24 additions & 15 deletions arbitrator/prover/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use sha3::Keccak256;
use smallvec::SmallVec;
use std::{
borrow::Cow,
cmp::min,
convert::{TryFrom, TryInto},
fmt::{self, Display},
fs::File,
Expand All @@ -39,7 +40,6 @@ use std::{
num::Wrapping,
path::{Path, PathBuf},
sync::Arc,
cmp::min,
};
use wasmer_types::FunctionIndex;
use wasmparser::{DataKind, ElementItem, ElementKind, Operator, TableType};
Expand Down Expand Up @@ -80,30 +80,33 @@ pub struct Function {
local_types: Vec<ArbValueType>,
}

fn code_to_opcode_hash(code: &Vec<Instruction>, opcode_idx:usize) -> Bytes32 {
let seg = opcode_idx/16;
let seg_start = seg*16;
fn code_to_opcode_hash(code: &Vec<Instruction>, opcode_idx: usize) -> Bytes32 {
let seg = opcode_idx / 16;
let seg_start = seg * 16;
let seg_end = min(seg_start + 16, code.len());
let mut b = [0u8; 32];
for i in 0..(seg_end-seg_start){
b[i*2..i*2+2].copy_from_slice(code[seg_start + i].opcode.repr().to_be_bytes().as_slice())
for i in 0..(seg_end - seg_start) {
b[i * 2..i * 2 + 2]
.copy_from_slice(code[seg_start + i].opcode.repr().to_be_bytes().as_slice())
}
Bytes32(b)
}

fn code_to_opcode_hashes(code: &Vec<Instruction>) -> Vec<Bytes32> {
fn code_to_opcode_hashes(code: &Vec<Instruction>) -> Vec<Bytes32> {
#[cfg(feature = "native")]
let iter = (0..(code.len()+15)/16).into_par_iter();
let iter = (0..(code.len() + 15) / 16).into_par_iter();

#[cfg(not(feature = "native"))]
let iter = (0..(code.len()+15)/16).into_iter();
let iter = (0..(code.len() + 15) / 16).into_iter();

iter.map(|i|code_to_opcode_hash(code, i*16)).collect()
iter.map(|i| code_to_opcode_hash(code, i * 16)).collect()
}

#[cfg(feature = "native")]
fn code_to_argdata_hashes(code: &Vec<Instruction>) -> Vec<Bytes32> {
code.par_iter().map(|i| i.get_proving_argument_data()).collect()
code.par_iter()
.map(|i| i.get_proving_argument_data())
.collect()
}

#[cfg(not(feature = "native"))]
Expand Down Expand Up @@ -173,7 +176,7 @@ impl Function {
Function {
code,
ty,
opcode_merkle:Merkle::new(MerkleType::Opcode, opcode_hashes),
opcode_merkle: Merkle::new(MerkleType::Opcode, opcode_hashes),
argument_data_merkle: Merkle::new(MerkleType::ArgumentData, argument_data_hashes),
local_types,
}
Expand Down Expand Up @@ -1463,8 +1466,14 @@ impl Machine {
let opcode_hashes = code_to_opcode_hashes(&func.code);
let argdata_hashes = code_to_argdata_hashes(&func.code);

func.opcode_merkle = Merkle::new_advanced(MerkleType::Opcode, opcode_hashes, Bytes32::default(), 2);
func.argument_data_merkle = Merkle::new_advanced(MerkleType::ArgumentData, argdata_hashes, Bytes32::default(), 2);
func.opcode_merkle =
Merkle::new_advanced(MerkleType::Opcode, opcode_hashes, Bytes32::default(), 2);
func.argument_data_merkle = Merkle::new_advanced(
MerkleType::ArgumentData,
argdata_hashes,
Bytes32::default(),
2,
);
}
module.funcs_merkle = Arc::new(Merkle::new(
MerkleType::Function,
Expand Down Expand Up @@ -2674,7 +2683,7 @@ impl Machine {
out!(code_to_opcode_hash(&func.code, self.pc.inst()));
out!(func
.opcode_merkle
.prove(self.pc.inst()/16)
.prove(self.pc.inst() / 16)
.expect("Failed to prove against code merkle"));
out!(func.code[self.pc.inst()].get_proving_argument_data());
out!(func
Expand Down
3 changes: 2 additions & 1 deletion arbitrator/prover/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ impl Merkle {
} else {
hash_node(ty, left, right)
}
}).collect();
})
.collect();
empty_layers.push(new_empty_layer);
layers.push(new_layer);
}
Expand Down
1 change: 0 additions & 1 deletion arbitrator/prover/src/wavm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ impl Instruction {
ret[2..].copy_from_slice(&*self.get_proving_argument_data());
ret
}

}

/// Note: An Unreachable stack state is equal to any other stack state.
Expand Down

0 comments on commit 7803bab

Please sign in to comment.