Closed zmalatrax closed 1 month ago
I am applying to this issue via OnlyDust platform.
Hey, I'm Renzo, a Software Engineer with over 5 years of experience, I recently started contributing to Web3 as a member of Dojo Coding, I have contributed in languages like Cairo and Rust already.
Sure, assigned
Hi, I have a question about the implementation of the hint, as there's no example for this one,
export const testLessThanOrEqualAddress = (
vm: VirtualMachine,
lhs: ResOperand,
rhs: ResOperand,
dst: CellRef
) => {
const lhsValue = vm.getResOperandValue(lhs);
const rhsValue = vm.getResOperandValue(rhs);
const result = new Felt(BigInt(lhsValue <= rhsValue));
vm.memory.assertEq(vm.cellRefToRelocatable(dst), result);
};
This implementation is quite similar to how the TestLessThanOrEqual hint would be, what I'm not sure about is, the result should be a Relocatable? If so, how can I do that conversion? If not, should the inputs be a Relocatable? I didn't quite get that part. Thank you!
Hi, I have a question about the implementation of the hint, as there's no example for this one,
Hi, indeed missed providing the right one, here is a proper reference.
This hint was actually introduced with Cairo 2.7.0 and the multi_pop_back()
/multi_pop_front()
methods in this PR.
I'm currently bumping the Cairo compiler submodule to the right version so you can write and compile a Cairo program using this hint.
This implementation is quite similar to how the TestLessThanOrEqual hint would be, what I'm not sure about is, the result should be a Relocatable? If so, how can I do that conversion? If not, should the inputs be a Relocatable? I didn't quite get that part. Thank you!
Yes the inputs should be Relocatable
, while the result is a Felt
. It means that lhsValue
and rhsValue
extracted from lhs
and rhs
are expected to be Relocatable
rather than Felt
as in TestLessThanOrEqual.
The current method handling ResOperand
is getResOperandValue()
and only extracts Felt
and not Relocatable
.
I'll update the API so that you can properly implement the TestLessThanOrEqualAddress
:)
@renzobanegass All good now, you can use vm.getResOperandRelocatable()
to extract a Relocatable from a ResOperand :)
Great, I'll get to it then!
Does this implementation look better?
export const testLessThanOrEqualAddress = (
vm: VirtualMachine,
lhs: ResOperand,
rhs: ResOperand,
dst: CellRef
) => {
const lhsValue = vm.getResOperandRelocatable(lhs);
const rhsValue = vm.getResOperandRelocatable(rhs);
const isLessThanOrEqual = lhsValue.segmentId < rhsValue.segmentId ||
(lhsValue.segmentId === rhsValue.segmentId && lhsValue.offset <= rhsValue.offset);
const result = new Felt(isLessThanOrEqual ? 1n : 0n);
vm.memory.assertEq(vm.cellRefToRelocatable(dst), result);
};
Does this implementation look better?
Open a PR, I'll make a review, it'll be much easier
Estimated time: 0.5d Lifespan: 1d
How-to implement a hint on the Cairo VM TS available here
Similar to the TestLessThanOrEqual hint, but expecting Relocatable instead of Felt. Rust implementation reference of TestLessThanOrEqual