Skip to content

Commit

Permalink
fix(avm-transpiler): FDIV and U128 test case (#5200)
Browse files Browse the repository at this point in the history
FDIV does not take a tag. Current state was breaking serialization.
  • Loading branch information
fcarreiro committed Mar 14, 2024
1 parent f988cb8 commit 6977e81
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion avm-transpiler/src/opcodes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// All AVM opcodes
/// Keep updated with TS and yellow paper!
#[derive(Copy, Clone)]
#[derive(PartialEq, Copy, Clone)]
pub enum AvmOpcode {
// Compute
ADD,
Expand Down
6 changes: 5 additions & 1 deletion avm-transpiler/src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ pub fn brillig_to_avm(brillig: &Brillig) -> Vec<u8> {
avm_instrs.push(AvmInstruction {
opcode: avm_opcode,
indirect: Some(ALL_DIRECT),
tag: Some(AvmTypeTag::FIELD),
tag: if avm_opcode == AvmOpcode::FDIV {
None
} else {
Some(AvmTypeTag::FIELD)
},
operands: vec![
AvmOperand::U32 {
value: lhs.to_usize() as u32,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ contract AvmTest {
200 as Field
}

#[aztec(public-vm)]
fn addU128(a: U128, b: U128) -> pub U128 {
a + b
}

// /************************************************************************
// * Hashing functions
// ************************************************************************/
Expand Down
18 changes: 18 additions & 0 deletions yarn-project/simulator/src/avm/avm_simulator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ describe('AVM simulator', () => {
expect(results.output).toEqual([new Fr(3)]);
});

it('Should execute contract function that performs U128 addition', async () => {
const calldata: Fr[] = [
// First U128
new Fr(1),
new Fr(2),
// Second U128
new Fr(3),
new Fr(4),
];
const context = initContext({ env: initExecutionEnvironment({ calldata }) });

const bytecode = getAvmTestContractBytecode('avm_addU128');
const results = await new AvmSimulator(context).executeBytecode(bytecode);

expect(results.reverted).toBe(false);
expect(results.output).toEqual([new Fr(4), new Fr(6)]);
});

describe.each([
['avm_setOpcodeUint8', 8n],
// ['avm_setOpcodeUint16', 60000n],
Expand Down

0 comments on commit 6977e81

Please sign in to comment.