From f899c6023d428f745090410993fb27a58ee96863 Mon Sep 17 00:00:00 2001 From: Greg Hale Date: Thu, 22 Feb 2024 09:07:05 -0800 Subject: [PATCH] use base64-unpadded encoding/decoding for tokenmessage --- src/Pact/Native.hs | 4 ++-- tests/pact/hyperlane.repl | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Pact/Native.hs b/src/Pact/Native.hs index e6a6c7b6d..cd1192a92 100644 --- a/src/Pact/Native.hs +++ b/src/Pact/Native.hs @@ -1642,7 +1642,7 @@ hyperlaneDecodeTokenMessageDef = -- fails in exactly the cases we expect. -- (The only change we make to its output is to strip error messages). computeGas' i (GHyperlaneDecodeTokenMessage (T.length msg)) $ - case B64URL.decode (T.encodeUtf8 msg) of + case B64URL.decodeUnpadded (T.encodeUtf8 msg) of Left _ -> evalError' i "Failed to base64-decode token message" Right bytes -> do case runGetOrFail (getTokenMessageERC20 <* eof) (BS.fromStrict bytes) of @@ -1706,7 +1706,7 @@ hyperlaneDecodeTokenMessageDef = -- | Helper function for creating TokenMessages encoded in the ERC20 format -- and base64url encoded. Used for generating test data. encodeTokenMessage :: BS.ByteString -> Word256 -> Word256 -> Text -encodeTokenMessage recipient amount chain = T.decodeUtf8 $ B64URL.encode (BS.toStrict bytes) +encodeTokenMessage recipient amount chain = T.decodeUtf8 $ B64URL.encodeUnpadded (BS.toStrict bytes) where bytes = runPut $ do putWord256be (96 :: Word256) diff --git a/tests/pact/hyperlane.repl b/tests/pact/hyperlane.repl index 20dc971ef..bb5ffdb9e 100644 --- a/tests/pact/hyperlane.repl +++ b/tests/pact/hyperlane.repl @@ -12,6 +12,11 @@ "chainId": "4", "recipient": (read-keyset 'test-keys) } + (hyperlane-decode-token-message "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAewAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGF7InByZWQiOiAia2V5cy1hbGwiLCAia2V5cyI6WyJkYTFhMzM5YmQ4MmQyYzJlOTE4MDYyNmEwMGRjMDQzMjc1ZGViM2FiYWJiMjdiNTczOGFiZjZiOWRjZWU4ZGI2Il19AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") +) + +; Decoding a valid TokenMessage should succeed. +(expect-failure "decoding fails for base64-padded messages" (hyperlane-decode-token-message "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAewAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGF7InByZWQiOiAia2V5cy1hbGwiLCAia2V5cyI6WyJkYTFhMzM5YmQ4MmQyYzJlOTE4MDYyNmEwMGRjMDQzMjc1ZGViM2FiYWJiMjdiNTczOGFiZjZiOWRjZWU4ZGI2Il19AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==") )