Skip to content
Closed
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
4 changes: 4 additions & 0 deletions avm-transpiler/src/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ pub enum AvmOpcode {
POSEIDON2,
SHA256, // temp - may be removed, but alot of contracts rely on it
PEDERSEN, // temp - may be removed, but alot of contracts rely on it
// Conversions
TORADIXLE,
}

impl AvmOpcode {
Expand Down Expand Up @@ -155,6 +157,8 @@ impl AvmOpcode {
AvmOpcode::POSEIDON2 => "POSEIDON2",
AvmOpcode::SHA256 => "SHA256 ",
AvmOpcode::PEDERSEN => "PEDERSEN",
// Conversions
AvmOpcode::TORADIXLE => "TORADIXLE",
}
}
}
28 changes: 28 additions & 0 deletions avm-transpiler/src/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,34 @@ fn handle_black_box_function(avm_instrs: &mut Vec<AvmInstruction>, operation: &B
..Default::default()
});
}
BlackBoxOp::ToRadix {
input,
radix,
output,
} => {
let num_limbs = output.size;
let input_offset = input.0;
let output_offset = output.pointer.0;
assert!(radix <= &256u32, "Radix must be less than or equal to 256");

avm_instrs.push(AvmInstruction {
opcode: AvmOpcode::TORADIXLE,
indirect: Some(FIRST_OPERAND_INDIRECT),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's the second one the one that is indirect right? the first is the input field (direct) and the second one is output.pointer (indirect)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We count from 0 XD

tag: None,
operands: vec![
AvmOperand::U32 {
value: input_offset as u32,
},
AvmOperand::U32 {
value: output_offset as u32,
},
AvmOperand::U32 { value: *radix },
AvmOperand::U32 {
value: num_limbs as u32,
},
],
})
}
_ => panic!("Transpiler doesn't know how to process {:?}", operation),
}
}
Expand Down