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
2 changes: 1 addition & 1 deletion .github/workflows/arbitrator-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all --manifest-path arbitrator/Cargo.toml
args: --all --manifest-path arbitrator/Cargo.toml -- -D warnings

- name: Run rust tests
uses: actions-rs/cargo@v1
Expand Down
2 changes: 1 addition & 1 deletion arbitrator/prover/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE

#![allow(clippy::missing_safety_doc)] // We have a lot of unsafe ABI
#![allow(clippy::missing_safety_doc, clippy::too_many_arguments)]

pub mod binary;
/// cbindgen:ignore
Expand Down
43 changes: 6 additions & 37 deletions arbitrator/prover/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl Module {
)
},
func_ty.clone(),
&types,
types,
)?);
host_call_hooks.push(None);
}
Expand Down Expand Up @@ -1061,7 +1061,7 @@ impl Machine {
expected_type.inputs.push(ArbValueType::I32); // argc
expected_type.inputs.push(ArbValueType::I32); // argv
ensure!(
&main_module.func_types[f as usize] == &expected_type,
main_module.func_types[f as usize] == expected_type,
"Run function doesn't match expected signature of [argc, argv]",
);
// Go's flags library panics if the argument list is empty.
Expand Down Expand Up @@ -1345,7 +1345,9 @@ impl Machine {

let module = self.modules.last().expect("no module");
let export = module.exports.iter().find(|x| x.0 == func);
let export = export.expect(&format!("func {} not found", func)).1;
let export = export
.unwrap_or_else(|| panic!("func {} not found", func))
.1;

self.frame_stack.clear();
self.block_stack.clear();
Expand All @@ -1361,7 +1363,7 @@ impl Machine {
}

pub fn get_final_result(&self) -> Result<Vec<Value>> {
if self.frame_stack.len() != 0 {
if !self.frame_stack.is_empty() {
bail!(
"machine has not successfully computed a final result {:?}",
self.status
Expand Down Expand Up @@ -1452,20 +1454,6 @@ impl Machine {
match inst.opcode {
Opcode::Unreachable => error!(),
Opcode::Nop => {}
Opcode::Block => {
let idx = inst.argument_data as usize;
self.block_stack.push(idx);
debug_assert!(func.code.len() > idx);
}
Opcode::EndBlock => {
self.block_stack.pop();
}
Opcode::EndBlockIf => {
let x = self.value_stack.last().unwrap();
if !x.is_i32_zero() {
self.block_stack.pop().unwrap();
}
}
Opcode::InitFrame => {
let caller_module_internals = self.value_stack.pop().unwrap().assume_u32();
let caller_module = self.value_stack.pop().unwrap().assume_u32();
Expand Down Expand Up @@ -1493,17 +1481,6 @@ impl Machine {
Machine::test_next_instruction(func, &self.pc);
}
}
Opcode::Branch => {
self.pc.inst = self.block_stack.pop().unwrap();
Machine::test_next_instruction(func, &self.pc);
}
Opcode::BranchIf => {
let x = self.value_stack.pop().unwrap();
if !x.is_i32_zero() {
self.pc.inst = self.block_stack.pop().unwrap();
Machine::test_next_instruction(func, &self.pc);
}
}
Opcode::Return => {
let frame = self.frame_stack.pop().unwrap();
match frame.return_ref {
Expand Down Expand Up @@ -1868,20 +1845,12 @@ impl Machine {
}
self.value_stack.push(Value::I64(x));
}
Opcode::PushStackBoundary => {
self.value_stack.push(Value::StackBoundary);
}
Opcode::MoveFromStackToInternal => {
self.internal_stack.push(self.value_stack.pop().unwrap());
}
Opcode::MoveFromInternalToStack => {
self.value_stack.push(self.internal_stack.pop().unwrap());
}
Opcode::IsStackBoundary => {
let val = self.value_stack.pop().unwrap();
self.value_stack
.push(Value::I32((val == Value::StackBoundary) as u32));
}
Opcode::Dup => {
let val = self.value_stack.last().cloned().unwrap();
self.value_stack.push(val);
Expand Down
10 changes: 1 addition & 9 deletions arbitrator/prover/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub enum ArbValueType {
RefNull,
FuncRef,
InternalRef,
StackBoundary,
}

impl ArbValueType {
Expand Down Expand Up @@ -96,7 +95,6 @@ pub enum Value {
RefNull,
FuncRef(u32),
InternalRef(ProgramCounter),
StackBoundary,
}

impl Value {
Expand All @@ -109,7 +107,6 @@ impl Value {
Value::RefNull => ArbValueType::RefNull,
Value::FuncRef(_) => ArbValueType::FuncRef,
Value::InternalRef(_) => ArbValueType::InternalRef,
Value::StackBoundary => ArbValueType::StackBoundary,
}
}

Expand All @@ -122,7 +119,6 @@ impl Value {
Value::RefNull => Bytes32::default(),
Value::FuncRef(x) => x.into(),
Value::InternalRef(pc) => pc.serialize(),
Value::StackBoundary => Bytes32::default(),
}
}

Expand Down Expand Up @@ -186,9 +182,6 @@ impl Value {
ArbValueType::RefNull | ArbValueType::FuncRef | ArbValueType::InternalRef => {
Value::RefNull
}
ArbValueType::StackBoundary => {
panic!("Attempted to make default of StackBoundary type")
}
}
}

Expand Down Expand Up @@ -232,10 +225,9 @@ impl Value {
}
Value::F32(value) => single!("f32", *value),
Value::F64(value) => single!("f64", *value),
Value::RefNull => format!("null"),
Value::RefNull => "null".into(),
Value::FuncRef(func) => format!("func {}", func),
Value::InternalRef(pc) => format!("inst {} in {}-{}", pc.inst, pc.module, pc.func),
Value::StackBoundary => format!("stack boundary"),
}
}
}
Expand Down
29 changes: 4 additions & 25 deletions arbitrator/prover/src/wavm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ impl IBinOpType {
pub enum Opcode {
Unreachable,
Nop,
Block,
// Loop and If are wrapped into Block
Branch,
BranchIf,

Return,
Call,
Expand Down Expand Up @@ -137,24 +133,16 @@ pub enum Opcode {
IBinOp(IntegerValType, IBinOpType),

// Custom opcodes not in WASM. Documented more in "Custom opcodes.md".
/// Branch is partially split up into these.
EndBlock,
/// Custom opcode not in wasm.
/// Like "EndBlock" but conditional.
/// Keeps its condition on the stack.
EndBlockIf,
/// Custom opcode not in wasm.
InitFrame,
/// Unconditional jump to an arbitrary point in code.
ArbitraryJump,
/// Conditional jump to an arbitrary point in code.
ArbitraryJumpIf,
/// Push a Value::StackBoundary to the stack
PushStackBoundary,
/// Pop a value from the value stack and push it to the internal stack
MoveFromStackToInternal,
/// Pop a value from the internal stack and push it to the value stack
MoveFromInternalToStack,
/// Pop a value from the value stack, then push an I32 1 if it's a stack boundary, I32 0 otherwise.
IsStackBoundary,
/// Duplicate the top value on the stack
Dup,
/// Call a function in a different module
Expand All @@ -175,18 +163,13 @@ pub enum Opcode {
ReadInboxMessage,
/// Stop exexcuting the machine and move to the finished status
HaltAndSetFinished,
/// Unconditional jump to an arbitrary point in code.
ArbitraryJump,
}

impl Opcode {
pub fn repr(self) -> u16 {
match self {
Opcode::Unreachable => 0x00,
Opcode::Nop => 0x01,
Opcode::Block => 0x02,
Opcode::Branch => 0x0C,
Opcode::BranchIf => 0x0D,
Opcode::Return => 0x0F,
Opcode::Call => 0x10,
Opcode::CallIndirect => 0x11,
Expand Down Expand Up @@ -275,14 +258,11 @@ impl Opcode {
_ => panic!("Unsupported {:?}", self),
},
// Internal instructions:
Opcode::EndBlock => 0x8000,
Opcode::EndBlockIf => 0x8001,
Opcode::InitFrame => 0x8002,
Opcode::ArbitraryJumpIf => 0x8003,
Opcode::PushStackBoundary => 0x8004,
Opcode::ArbitraryJump => 0x8003,
Opcode::ArbitraryJumpIf => 0x8004,
Opcode::MoveFromStackToInternal => 0x8005,
Opcode::MoveFromInternalToStack => 0x8006,
Opcode::IsStackBoundary => 0x8007,
Opcode::Dup => 0x8008,
Opcode::CrossModuleCall => 0x8009,
Opcode::CallerModuleInternalCall => 0x800A,
Expand All @@ -293,7 +273,6 @@ impl Opcode {
Opcode::ReadPreImage => 0x8020,
Opcode::ReadInboxMessage => 0x8021,
Opcode::HaltAndSetFinished => 0x8022,
Opcode::ArbitraryJump => 0x8023,
}
}

Expand Down
87 changes: 1 addition & 86 deletions contracts/src/osp/OneStepProver0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ contract OneStepProver0 is IOneStepProver {
ty = ValueType.F32;
} else if (opcode == Instructions.F64_CONST) {
ty = ValueType.F64;
} else if (opcode == Instructions.PUSH_STACK_BOUNDARY) {
ty = ValueType.STACK_BOUNDARY;
} else {
revert("CONST_PUSH_INVALID_OPCODE");
}
Expand Down Expand Up @@ -86,39 +84,6 @@ contract OneStepProver0 is IOneStepProver {
}
}

function executeBlock(
Machine memory mach,
Module memory,
Instruction calldata inst,
bytes calldata
) internal pure {
uint32 targetPc = uint32(inst.argumentData);
require(targetPc == inst.argumentData, "BAD_BLOCK_PC");
mach.blockStack.push(targetPc);
}

function executeBranch(
Machine memory mach,
Module memory,
Instruction calldata,
bytes calldata
) internal pure {
mach.functionPc = mach.blockStack.pop();
}

function executeBranchIf(
Machine memory mach,
Module memory,
Instruction calldata,
bytes calldata
) internal pure {
uint32 cond = mach.valueStack.pop().assumeI32();
if (cond != 0) {
// Jump to target
mach.functionPc = mach.blockStack.pop();
}
}

function executeReturn(
Machine memory mach,
Module memory,
Expand Down Expand Up @@ -419,27 +384,6 @@ contract OneStepProver0 is IOneStepProver {
);
}

function executeEndBlock(
Machine memory mach,
Module memory,
Instruction calldata,
bytes calldata
) internal pure {
mach.blockStack.pop();
}

function executeEndBlockIf(
Machine memory mach,
Module memory,
Instruction calldata,
bytes calldata
) internal pure {
uint32 cond = mach.valueStack.peek().assumeI32();
if (cond != 0) {
mach.blockStack.pop();
}
}

function executeInitFrame(
Machine memory mach,
Module memory,
Expand Down Expand Up @@ -476,20 +420,6 @@ contract OneStepProver0 is IOneStepProver {
}
}

function executeIsStackBoundary(
Machine memory mach,
Module memory,
Instruction calldata,
bytes calldata
) internal pure {
Value memory val = mach.valueStack.pop();
uint32 newContents = 0;
if (val.valueType == ValueType.STACK_BOUNDARY) {
newContents = 1;
}
mach.valueStack.push(ValueLib.newI32(newContents));
}

function executeDup(
Machine memory mach,
Module memory,
Expand Down Expand Up @@ -519,12 +449,6 @@ contract OneStepProver0 is IOneStepProver {
impl = executeUnreachable;
} else if (opcode == Instructions.NOP) {
impl = executeNop;
} else if (opcode == Instructions.BLOCK) {
impl = executeBlock;
} else if (opcode == Instructions.BRANCH) {
impl = executeBranch;
} else if (opcode == Instructions.BRANCH_IF) {
impl = executeBranchIf;
} else if (opcode == Instructions.RETURN) {
impl = executeReturn;
} else if (opcode == Instructions.CALL) {
Expand All @@ -535,10 +459,6 @@ contract OneStepProver0 is IOneStepProver {
impl = executeCallerModuleInternalCall;
} else if (opcode == Instructions.CALL_INDIRECT) {
impl = executeCallIndirect;
} else if (opcode == Instructions.END_BLOCK) {
impl = executeEndBlock;
} else if (opcode == Instructions.END_BLOCK_IF) {
impl = executeEndBlockIf;
} else if (opcode == Instructions.ARBITRARY_JUMP) {
impl = executeArbitraryJump;
} else if (opcode == Instructions.ARBITRARY_JUMP_IF) {
Expand All @@ -557,18 +477,13 @@ contract OneStepProver0 is IOneStepProver {
impl = executeDrop;
} else if (opcode == Instructions.SELECT) {
impl = executeSelect;
} else if (
(opcode >= Instructions.I32_CONST && opcode <= Instructions.F64_CONST) ||
opcode == Instructions.PUSH_STACK_BOUNDARY
) {
} else if (opcode >= Instructions.I32_CONST && opcode <= Instructions.F64_CONST) {
impl = executeConstPush;
} else if (
opcode == Instructions.MOVE_FROM_STACK_TO_INTERNAL ||
opcode == Instructions.MOVE_FROM_INTERNAL_TO_STACK
) {
impl = executeMoveInternal;
} else if (opcode == Instructions.IS_STACK_BOUNDARY) {
impl = executeIsStackBoundary;
} else if (opcode == Instructions.DUP) {
impl = executeDup;
} else {
Expand Down
Loading