diff --git a/avm-transpiler/src/opcodes.rs b/avm-transpiler/src/opcodes.rs index 2b63c8e987ea..206325cfeff7 100644 --- a/avm-transpiler/src/opcodes.rs +++ b/avm-transpiler/src/opcodes.rs @@ -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 { @@ -155,6 +157,8 @@ impl AvmOpcode { AvmOpcode::POSEIDON2 => "POSEIDON2", AvmOpcode::SHA256 => "SHA256 ", AvmOpcode::PEDERSEN => "PEDERSEN", + // Conversions + AvmOpcode::TORADIXLE => "TORADIXLE", } } } diff --git a/avm-transpiler/src/transpile.rs b/avm-transpiler/src/transpile.rs index 314dc77414ba..11007c9497e7 100644 --- a/avm-transpiler/src/transpile.rs +++ b/avm-transpiler/src/transpile.rs @@ -968,6 +968,34 @@ fn handle_black_box_function(avm_instrs: &mut Vec, 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), + 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), } }