I have a function which accepts one bytes16
argument.
function start(
bytes16 reference
)
I have some events which I use to track behaviour, using reference
as the index. Everything works well enough except when a user submits a reference with 17-32 chars. Between web3 and the SC, reference
is being truncated, keeping only the 16 bytes to the left and the rest as zero.
I added validations for this on the client-side but I still wanted to setup the SC to handle this more gracefully. I was expecting it to revert transaction with a type error but that only happens if the argument has over 32 bytes.
I would imagine I should be adding a modifier to require the right length but I'm having a hard time finding similar cases to understand how it should be done. What's the best practice in a situation like this?
bytes16
is always exactly 16 bytes long... I'm not sure what it is that you want to check. (On the client, you can certainly validate the data before you put it into abytes16
, but by the time you're in the smart contract, you have abytes16
already.)