1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-02 01:04:57 +03:00

Fix nock compilation and builtin evaluation of sha256 stdilb (#3175)

This PR:

1. Fixes the compilation of the sha256 builtin anoma lib call

A sha256 hash is 32 bytes long, not 64 bytes. This number is used when
constructing the ByteArray representation (i.e `[length payload]` cell)
of the output of Anoma stdlib sha256 call. The Anoma stdlib sha256 call
just returns the atom payload.

2. Fixes the evaluation of the sha256 stdlib call

Previously we were converting the sha256 hash bytestring to Base16
format. This is convenient when displaying the ByteString hash. However
the Anoma nock interpreter outputs the raw bytes so we must change the
builtin evaluator to match this behaviour.

After these fixes we can re-enable the test084 anoma compilation test.
This commit is contained in:
Paul Cadman 2024-11-14 17:54:39 +00:00 committed by GitHub
parent 29041dcb32
commit 49c14be71e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 8 additions and 12 deletions

View File

@ -5,7 +5,6 @@ import Data.Bit (Bit)
import Data.Bit qualified as Bit
import Data.Bits
import Data.ByteString qualified as BS
import Data.ByteString.Base16 qualified as Base16
import Data.ByteString.Builder qualified as BS
import Juvix.Compiler.Nockma.Encoding.Base
import Juvix.Compiler.Nockma.Encoding.Effect.BitReader
@ -120,7 +119,4 @@ decodeByteStringWithDefault :: ByteString -> Integer -> ByteString
decodeByteStringWithDefault d = fromRight d . run . runErrorNoCallStack @BitReadError . decodeByteString
sha256Natural :: Natural -> ByteString
sha256Natural =
Base16.encode
. SHA256.hash
. naturalToByteStringLE
sha256Natural = SHA256.hash . naturalToByteStringLE

View File

@ -712,7 +712,7 @@ compile = \case
return $ mkByteArray (nockNatLiteral (integerToNatural sha256HashLength)) stdcall
where
sha256HashLength :: Integer
sha256HashLength = 64
sha256HashLength = 32
goAnomaRandomNextBytes :: [Term Natural] -> Sem r (Term Natural)
goAnomaRandomNextBytes args = case args of

View File

@ -240,7 +240,7 @@ classify AnomaTest {..} = case _anomaTestNum of
81 -> ClassWorking
82 -> ClassWorking
83 -> ClassWorking
84 -> ClassWrong
84 -> ClassWorking
85 -> ClassWorking
86 -> ClassExpectedFail
_ -> error "non-exhaustive test classification"
@ -1024,11 +1024,11 @@ allTests =
$(mkRelFile "test084.juvix")
[]
$ checkOutput
[ [nock| 64 |],
[ [nock| 32 |],
[nock|
[
64
5092006196359674779938793937035252249221936503860319648757996882954518215195609232852607160812968472040491493412050369557521935588220586883008001462395444
32
69779012276202546540741613998220636891790827476075440677599814057037833368907
] |]
],
mkAnomaTest

View File

@ -17,7 +17,7 @@ propEncodingRoundtrip = property $ do
propSha256Length :: Property
propSha256Length = property $ do
n <- forAll (Gen.integral (Range.linear 0 1000000))
BS.length (Encoding.sha256Natural n) === 64
BS.length (Encoding.sha256Natural n) === 32
propSha256HandlesLargeIntegers :: Property
propSha256HandlesLargeIntegers = property $ do

View File

@ -4,4 +4,4 @@ true
true
true
false
bytearray-from-list-byte (builtinListCons UInt8 52 (builtinListCons UInt8 98 (builtinListCons UInt8 102 (builtinListCons UInt8 53 (builtinListCons UInt8 49 (builtinListCons UInt8 50 (builtinListCons UInt8 50 (builtinListCons UInt8 102 (builtinListCons UInt8 51 (builtinListCons UInt8 52 (builtinListCons UInt8 52 (builtinListCons UInt8 53 (builtinListCons UInt8 53 (builtinListCons UInt8 52 (builtinListCons UInt8 99 (builtinListCons UInt8 53 (builtinListCons UInt8 51 (builtinListCons UInt8 98 (builtinListCons UInt8 100 (builtinListCons UInt8 101 (builtinListCons UInt8 50 (builtinListCons UInt8 101 (builtinListCons UInt8 98 (builtinListCons UInt8 98 (builtinListCons UInt8 56 (builtinListCons UInt8 99 (builtinListCons UInt8 100 (builtinListCons UInt8 50 (builtinListCons UInt8 98 (builtinListCons UInt8 55 (builtinListCons UInt8 101 (builtinListCons UInt8 51 (builtinListCons UInt8 100 (builtinListCons UInt8 49 (builtinListCons UInt8 54 (builtinListCons UInt8 48 (builtinListCons UInt8 48 (builtinListCons UInt8 97 (builtinListCons UInt8 100 (builtinListCons UInt8 54 (builtinListCons UInt8 51 (builtinListCons UInt8 49 (builtinListCons UInt8 99 (builtinListCons UInt8 51 (builtinListCons UInt8 56 (builtinListCons UInt8 53 (builtinListCons UInt8 97 (builtinListCons UInt8 53 (builtinListCons UInt8 100 (builtinListCons UInt8 55 (builtinListCons UInt8 99 (builtinListCons UInt8 99 (builtinListCons UInt8 101 (builtinListCons UInt8 50 (builtinListCons UInt8 51 (builtinListCons UInt8 99 (builtinListCons UInt8 55 (builtinListCons UInt8 55 (builtinListCons UInt8 56 (builtinListCons UInt8 53 (builtinListCons UInt8 52 (builtinListCons UInt8 53 (builtinListCons UInt8 57 (builtinListCons UInt8 97 (builtinListNil UInt8)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
bytearray-from-list-byte (builtinListCons UInt8 75 (builtinListCons UInt8 245 (builtinListCons UInt8 18 (builtinListCons UInt8 47 (builtinListCons UInt8 52 (builtinListCons UInt8 69 (builtinListCons UInt8 84 (builtinListCons UInt8 197 (builtinListCons UInt8 59 (builtinListCons UInt8 222 (builtinListCons UInt8 46 (builtinListCons UInt8 187 (builtinListCons UInt8 140 (builtinListCons UInt8 210 (builtinListCons UInt8 183 (builtinListCons UInt8 227 (builtinListCons UInt8 209 (builtinListCons UInt8 96 (builtinListCons UInt8 10 (builtinListCons UInt8 214 (builtinListCons UInt8 49 (builtinListCons UInt8 195 (builtinListCons UInt8 133 (builtinListCons UInt8 165 (builtinListCons UInt8 215 (builtinListCons UInt8 204 (builtinListCons UInt8 226 (builtinListCons UInt8 60 (builtinListCons UInt8 119 (builtinListCons UInt8 133 (builtinListCons UInt8 69 (builtinListCons UInt8 154 (builtinListNil UInt8)))))))))))))))))))))))))))))))))