-
Notifications
You must be signed in to change notification settings - Fork 317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: trap with revert data #5732
Changes from 7 commits
e02f0e4
3a0efcb
d931931
bbc7b70
f562989
3a95d2e
6bda0d2
3ba8a43
1eaa311
60089a4
d7554ab
819de12
b038ef5
bceba91
5029825
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,11 @@ pub fn brillig_to_avm(brillig: &Brillig) -> Vec<u8> { | |
lhs, | ||
rhs, | ||
} => { | ||
assert!(is_integral_bit_size(*bit_size), "BinaryIntOp bit size should be integral: {:?}", brillig_instr); | ||
assert!( | ||
is_integral_bit_size(*bit_size), | ||
"BinaryIntOp bit size should be integral: {:?}", | ||
brillig_instr | ||
); | ||
let avm_opcode = match op { | ||
BinaryIntOp::Add => AvmOpcode::ADD, | ||
BinaryIntOp::Sub => AvmOpcode::SUB, | ||
|
@@ -102,20 +106,27 @@ pub fn brillig_to_avm(brillig: &Brillig) -> Vec<u8> { | |
], | ||
}); | ||
} | ||
BrilligOpcode::CalldataCopy { destination_address, size, offset } => { | ||
BrilligOpcode::CalldataCopy { | ||
destination_address, | ||
size, | ||
offset, | ||
} => { | ||
avm_instrs.push(AvmInstruction { | ||
opcode: AvmOpcode::CALLDATACOPY, | ||
indirect: Some(ALL_DIRECT), | ||
operands: vec![ | ||
AvmOperand::U32 { | ||
value: *offset as u32, // cdOffset (calldata offset) | ||
}, AvmOperand::U32 { | ||
}, | ||
AvmOperand::U32 { | ||
value: *size as u32, | ||
}, AvmOperand::U32 { | ||
}, | ||
AvmOperand::U32 { | ||
value: destination_address.to_usize() as u32, // dstOffset | ||
}], | ||
..Default::default() | ||
}); | ||
}, | ||
], | ||
..Default::default() | ||
}); | ||
} | ||
BrilligOpcode::Jump { location } => { | ||
let avm_loc = brillig_pcs_to_avm_pcs[*location]; | ||
|
@@ -146,14 +157,22 @@ pub fn brillig_to_avm(brillig: &Brillig) -> Vec<u8> { | |
..Default::default() | ||
}); | ||
} | ||
BrilligOpcode::Const { destination, value, bit_size } => { | ||
BrilligOpcode::Const { | ||
destination, | ||
value, | ||
bit_size, | ||
} => { | ||
handle_const(&mut avm_instrs, destination, value, bit_size); | ||
} | ||
BrilligOpcode::Mov { | ||
destination, | ||
source, | ||
} => { | ||
avm_instrs.push(generate_mov_instruction(Some(ALL_DIRECT), source.to_usize() as u32, destination.to_usize() as u32)); | ||
avm_instrs.push(generate_mov_instruction( | ||
Some(ALL_DIRECT), | ||
source.to_usize() as u32, | ||
destination.to_usize() as u32, | ||
)); | ||
} | ||
BrilligOpcode::ConditionalMov { | ||
source_a, | ||
|
@@ -165,10 +184,18 @@ pub fn brillig_to_avm(brillig: &Brillig) -> Vec<u8> { | |
opcode: AvmOpcode::CMOV, | ||
indirect: Some(ALL_DIRECT), | ||
operands: vec![ | ||
AvmOperand::U32 { value: source_a.to_usize() as u32 }, | ||
AvmOperand::U32 { value: source_b.to_usize() as u32 }, | ||
AvmOperand::U32 { value: condition.to_usize() as u32 }, | ||
AvmOperand::U32 { value: destination.to_usize() as u32 }, | ||
AvmOperand::U32 { | ||
value: source_a.to_usize() as u32, | ||
}, | ||
AvmOperand::U32 { | ||
value: source_b.to_usize() as u32, | ||
}, | ||
AvmOperand::U32 { | ||
value: condition.to_usize() as u32, | ||
}, | ||
AvmOperand::U32 { | ||
value: destination.to_usize() as u32, | ||
}, | ||
], | ||
..Default::default() | ||
}); | ||
|
@@ -177,13 +204,21 @@ pub fn brillig_to_avm(brillig: &Brillig) -> Vec<u8> { | |
destination, | ||
source_pointer, | ||
} => { | ||
avm_instrs.push(generate_mov_instruction(Some(ZEROTH_OPERAND_INDIRECT), source_pointer.to_usize() as u32, destination.to_usize() as u32)); | ||
avm_instrs.push(generate_mov_instruction( | ||
Some(ZEROTH_OPERAND_INDIRECT), | ||
source_pointer.to_usize() as u32, | ||
destination.to_usize() as u32, | ||
)); | ||
} | ||
BrilligOpcode::Store { | ||
destination_pointer, | ||
source, | ||
} => { | ||
avm_instrs.push(generate_mov_instruction(Some(FIRST_OPERAND_INDIRECT), source.to_usize() as u32, destination_pointer.to_usize() as u32)); | ||
avm_instrs.push(generate_mov_instruction( | ||
Some(FIRST_OPERAND_INDIRECT), | ||
source.to_usize() as u32, | ||
destination_pointer.to_usize() as u32, | ||
)); | ||
} | ||
BrilligOpcode::Call { location } => { | ||
let avm_loc = brillig_pcs_to_avm_pcs[*location]; | ||
|
@@ -199,38 +234,66 @@ pub fn brillig_to_avm(brillig: &Brillig) -> Vec<u8> { | |
opcode: AvmOpcode::INTERNALRETURN, | ||
..Default::default() | ||
}), | ||
BrilligOpcode::Stop { return_data_offset, return_data_size } => { | ||
BrilligOpcode::Stop { | ||
return_data_offset, | ||
return_data_size, | ||
} => { | ||
avm_instrs.push(AvmInstruction { | ||
opcode: AvmOpcode::RETURN, | ||
indirect: Some(ALL_DIRECT), | ||
operands: vec![ | ||
AvmOperand::U32 { value: *return_data_offset as u32 }, | ||
AvmOperand::U32 { value: *return_data_size as u32 }, | ||
AvmOperand::U32 { | ||
value: *return_data_offset as u32, | ||
}, | ||
AvmOperand::U32 { | ||
value: *return_data_size as u32, | ||
}, | ||
], | ||
..Default::default() | ||
}); | ||
} | ||
BrilligOpcode::Trap { /*return_data_offset, return_data_size*/ } => { | ||
BrilligOpcode::Trap { | ||
revert_data_offset, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this be direct or indirect? I.e., do I have to read from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Direct! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think rust-analyzer ships with vscode formatting :D |
||
revert_data_size, | ||
} => { | ||
// TODO(https://github.com/noir-lang/noir/issues/3113): Trap should support return data | ||
avm_instrs.push(AvmInstruction { | ||
opcode: AvmOpcode::REVERT, | ||
indirect: Some(ALL_DIRECT), | ||
operands: vec![ | ||
//AvmOperand::U32 { value: *return_data_offset as u32}, | ||
//AvmOperand::U32 { value: *return_data_size as u32}, | ||
AvmOperand::U32 { value: 0 }, | ||
AvmOperand::U32 { value: 0 }, | ||
AvmOperand::U32 { | ||
value: *revert_data_offset as u32, | ||
}, | ||
AvmOperand::U32 { | ||
value: *revert_data_size as u32, | ||
}, | ||
], | ||
..Default::default() | ||
}); | ||
}, | ||
BrilligOpcode::Cast { destination, source, bit_size } => { | ||
avm_instrs.push(generate_cast_instruction(source.to_usize() as u32, destination.to_usize() as u32, tag_from_bit_size(*bit_size))); | ||
} | ||
BrilligOpcode::ForeignCall { function, destinations, inputs, destination_value_types:_, input_value_types:_ } => { | ||
BrilligOpcode::Cast { | ||
destination, | ||
source, | ||
bit_size, | ||
} => { | ||
avm_instrs.push(generate_cast_instruction( | ||
source.to_usize() as u32, | ||
destination.to_usize() as u32, | ||
tag_from_bit_size(*bit_size), | ||
)); | ||
} | ||
BrilligOpcode::ForeignCall { | ||
function, | ||
destinations, | ||
inputs, | ||
destination_value_types: _, | ||
input_value_types: _, | ||
} => { | ||
handle_foreign_call(&mut avm_instrs, function, destinations, inputs); | ||
}, | ||
BrilligOpcode::BlackBox(operation) => handle_black_box_function(&mut avm_instrs, operation), | ||
} | ||
BrilligOpcode::BlackBox(operation) => { | ||
handle_black_box_function(&mut avm_instrs, operation) | ||
} | ||
_ => panic!( | ||
"Transpiler doesn't know how to process {:?} brillig instruction", | ||
brillig_instr | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we weren't running cargo fmt on this file :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ouch, I was just working on it but I guess if I run cargo ftm as well I'll be ok :D