NatLabs / icrc1

A full implementation of the ICRC-1 fungible token standard
https://natlabs.github.io/icrc1/
MIT License
32 stars 23 forks source link

get_transactions bug, fail with Natural subtraction underflow #21

Open ic-dstar opened 10 months ago

ic-dstar commented 10 months ago

If It has 3 transactions, call get_transactions fail with Natural subtraction underflow. you can test it if set a length less than start (by search inside transactions).

// dfx call
call get_transactions '(record{start=2 : nat; length=1 : nat})'

the bug cause by this line. https://github.com/NatLabs/icrc1/blob/2ede9a69a6d9d15802d44dafb5403e767269e27b/src/ICRC1/lib.mo#L352

function SB.sclice accept argument (buffer, start, end) https://github.com/NatLabs/icrc1/blob/2ede9a69a6d9d15802d44dafb5403e767269e27b/src/ICRC1/Utils.mo#L261

but the code call it , SB.slice(transactions, tx_start_index, req.length).

it should fix to


SB.slice(transactions, tx_start_index,  tx_start_index + req.length).

could you fix this? or may I pull a request.

tomijaga commented 10 months ago

Hey @ic-dstar, Thanks for reporting the issue.

Feel free to submit a pull request so it can be quickly resolved. I'll add more extensive tests for the get_transactions() fn later to prevent future errors.

tomijaga commented 10 months ago

Hey @ic-dstar, Your PR has been merged into the main branch. Let me know if any other issue comes up.