I want to create a circuit to measure the length of a string in Circom. There are only numeric data types, how can I do that?
Asked
Active
Viewed 376 times
-2
-
why is tag as tag:rust? – rv.kvetch Apr 19 '22 at 13:44
-
How do you have 15.4k rep and don't know better than to ask a question that isn't reproducible, and doesn't provide debugging information? – JΛYDΞV May 19 '22 at 03:29
2 Answers
0
You can supply string as a series of bytes. You can:
- Make your circuit take in an array of signals of length 256
- Iterate over the array
- Look for first 0 byte
- Save the index as string length
This will allow you to measure string lengths of up to 256 bytes.

Ilia Sidorenko
- 2,157
- 3
- 26
- 30
0
You can convert your string to an array of numbers (bytes) using an encoding appropriate to your use case, e.g. Unicode or ASCII.

Alex Kuzmin
- 725
- 5
- 17