Open jibbers42 opened 2 years ago
the solution is to make the client check the type in the IDL and then return an error if the type is a uSomething
but the BN
is < 0
Interesting... I guess I was thinking of this like normal client/server stuff, but maybe the design of Anchor implies the client would always be the same, and the design of Solana means there is a cost to do an operation. Still, the cost is cheap and using Anchor on the client isn't required (I assume), so a bad actor might still cause problems... or less paranoid, just a bug.
Before reading your solution, I changed the type to a signed int and return an error if it's < 0
. Unless I'm missing something, I feel like it would be better for Anchor to catch this case for me... if that's possible.
The anchor client should catch this case for you yes. To be clear, I was suggesting a way for us to build this into Anchor. Not a solution that you should implement in your own code.
Any update on this?
If I have a
u64
on the rust side and pass a negative (new anchor.BN(-1)
) from the client then the program will receive that number as a positive. I would expect an error to be returned or at least for the number to be changed to 0 (which isn't good either really).anchor version:
program:
test:
output: