Skip to content

Commit

Permalink
* Fixed (probably?) a flaw in the way Bytes Arrays computed cursor va…
Browse files Browse the repository at this point in the history
…lues 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.
  • Loading branch information
jmhickman committed Apr 30, 2022
1 parent 1d09ca5 commit 82cc317
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ABI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
| _ -> [""]


Expand Down Expand Up @@ -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 "")
Expand All @@ -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))

Expand All @@ -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) )

Expand Down
7 changes: 7 additions & 0 deletions Helpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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


0 comments on commit 82cc317

Please sign in to comment.