tact icon indicating copy to clipboard operation
tact copied to clipboard

sha256 should throw on comptime strings > 128, but it doesn't

Open novusnota opened this issue 1 year ago • 1 comments

Are you using the latest released (or pre-released, a.k.a. "next") version?

  • [X] I'm using the latest Tact version

Tact source code

contract Example {    
    receive("whatever") {
        let str = "A very big message. A very big message. A very big message. A very big message. A very big message. A very big message. 12345678 ---- ";
        dump(sha256(str));
    }
}

Relevant Tact/build system log output

#DEBUG#: File contracts/example.tact:3:9:
#DEBUG#: dump(sha256(str))
#DEBUG#: 23040416185367298424325046199007012241044178307087676684167050785956767923678

What happened?

All went fine

What did you expect?

I expected a compilation error

Steps to reproduce

No response

How do you run Tact?

Blueprint

Anything else?

Note, that the const-eval does throw an error, see:

tact --eval 'sha256("A very big message. A very big message. A very big message. A very big message. A very big message. A very big message. 12345678 ---- ")'

novusnota avatar Oct 02 '24 19:10 novusnota

It actually should not throw. We should make it compatible with what FunC does:

❯ cat sha256.fc
_ %foo() method_id(254) {
  return "This message demonstrates hash collision. These two messages are the same but also different. How different? That is up to you to decide. Do you think this says the same thing as the message below? "H;
}

_ %bar() method_id(255) {
  return "This message demonstrates hash collision. These two messages are the same but also different. How different? That is up to you to decide. Do you think this says the same thing as the message above?"H;
}

❯ ./func sha256.fc
// automatically generated from `sha256.fc`
254 DECLMETHOD %foo
255 DECLMETHOD %bar
%foo PROC:<{
  38691795256652595975174524357765136501621359555084910406216446862506586089407 PUSHINT
}>
%bar PROC:<{
  38321595322411654587457740692931899477424616340583131356943385673090315996846 PUSHINT
}>

anton-trunov avatar Oct 03 '24 08:10 anton-trunov