verifyIPFS icon indicating copy to clipboard operation
verifyIPFS copied to clipboard

invalid opcode when running example

Open lsaether opened this issue 7 years ago • 5 comments

It appears that something in this library isn't working with recent versions of solidity, truffle and ganache-cli.

Trying to run the example in the README goes okay until I try to generateHash, in which case I run into the invalid opcode error. Any idea where the invalid opcode is happening? I'm digging through it to try to find it

lsaether avatar Mar 20 '18 10:03 lsaether

Does not surprise me, the code is over a year old and Solidity has undergone a lot of changes. Does this seem like something you would be able to fix yourself easily?

MrChico avatar Mar 20 '18 14:03 MrChico

I believe the invalid opcode comes from using sha256. if you comment out line 18 which converts to base58 you should be able to run the function successfully and generate the base58 encoded version client-side.

bonedaddy avatar Mar 20 '18 22:03 bonedaddy

The problem I think is the while loop on line 41

           while (carry > 0) {
                digits[digitlength] = uint8(carry % 58);
                digitlength++;
                carry = carry / 58;
            }

specifically the line carry = carry / 58; appears to not be breaking the loop and causing the invalid opcode error. When commenting that out and forcing the loop to break by setting carry = 0 the code compiles and runs but of course doesn't covert to base58 correctly.

As @postables suggests, I am just doing the base58 encoding client side. Since all I really need to verify here is the hash which can be done using solidity built-in sha256.

lsaether avatar Mar 21 '18 09:03 lsaether

I'm trying do generateHash without base58, but when I do base58 on bytes I get, its not giving me same output as ipfs. If anyone made it work it would be great if they leave code sample here.

nklipa13 avatar Apr 02 '18 09:04 nklipa13

I replaced on line 30 40 with 140 and it started to work.

Lizusha avatar Dec 18 '20 09:12 Lizusha