From 82cc3179685415c7155bdc31553758550f5f8cc7 Mon Sep 17 00:00:00 2001 From: jmhickman Date: Sat, 30 Apr 2022 11:24:42 -0500 Subject: [PATCH] * Fixed (probably?) a flaw in the way Bytes Arrays computed cursor values to pass into the Bytes themselves. * Exposed via a public function the internal bytestring creation function. It can be useful to transform argument lists into the corresponding bytes for use in creating calldata. --- ABI.fs | 10 ++++++---- Helpers.fs | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ABI.fs b/ABI.fs index 3baeb15..82f2dc6 100644 --- a/ABI.fs +++ b/ABI.fs @@ -94,7 +94,7 @@ module ABIFunctions = | x when x.Length > 64 -> let _x = x[..63] let x = x[64..] - wrapBytesAcrossWords x [_x] + wrapBytesAcrossWords x (acc @ [_x]) | _ -> [""] @@ -255,7 +255,8 @@ module ABIFunctions = let tail = tail @ [ bs |> List.fold (fun acc s -> $"{acc}{s |> strip0x |> padTo32BytesRight}") (returnCountOfItems bs) |> Blob ] unpackInputAndProcess tail acc (cursor + bs.Length + 1 ) - | Bytes bs -> + | Bytes bs -> + printfn $"Bytes--->{acc}::{cursor}" let acc = acc + returnCurrentOffset cursor let bs = bs |> strip0x let contents = bs.Length |> byteDivide2 |> formatTypes padTo32BytesLeft |> fun s -> s + (wrapBytesAcrossWords bs [] |> String.concat "") @@ -269,8 +270,9 @@ module ABIFunctions = unpackInputAndProcess tail acc (cursor + (contents.Length / 64 )) | BytesArray bsArr -> + printfn $"BytesArray--->{acc}::{cursor}" let acc = acc + returnCurrentOffset cursor - let contents = returnCountOfItems bsArr |> fun s -> s + (unpackInputAndProcess bsArr "" (countOfArguments bsArr)) + let contents = returnCountOfItems bsArr |> fun s -> s + (unpackInputAndProcess bsArr "" bsArr.Length) let tail = tail @ [ contents |> Blob ] unpackInputAndProcess tail acc (cursor + (contents.Length / 64)) @@ -294,7 +296,7 @@ module ABIFunctions = | StringArray sArr -> let acc = acc + returnCurrentOffset cursor - let contents = returnCountOfItems sArr |> fun s -> s + (unpackInputAndProcess sArr "" (countOfArguments sArr)) + let contents = returnCountOfItems sArr |> fun s -> s + (unpackInputAndProcess sArr "" sArr.Length) let tail = tail @ [ contents |> Blob ] unpackInputAndProcess tail acc (cursor + (contents.Length / 64) ) diff --git a/Helpers.fs b/Helpers.fs index 27b6ea6..ee0b144 100644 --- a/Helpers.fs +++ b/Helpers.fs @@ -38,4 +38,11 @@ module Helpers = digest = newKeccakDigest log = startLogger() |> log } + + /// + /// Sometimes crafting or exposing bytestrings can be used programmatically, such as to create calldata + /// for use in low-level areas. Use with care, this is a deep internal function exposed with no guards. + /// + let public returnEVMBytestring evmDatatypes = createInputByteString evmDatatypes +