question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a method to generate tightly packed encodings

See original GitHub issue

Is there a way to replicate the non-standard pack mode used by Solidity in Ethers.js?

My use case is I want to sign an EtherDelta order. This is later validated in the trade function with the following code

bytes32 hash = sha256(tokenGet, amountGet, tokenGive, amountGive, expires, nonce);
if (!(ecrecover(hash,v,r,s) == user ...

So in JavaScript I want to be able to get the non-standard pack mode of the parameters tokenGet, amountGet, tokenGive, amountGive, expires and nonce which can then be passed into a sha256 function. Is that possible?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
ricmoocommented, Nov 23, 2017

Added in https://github.com/ethers-io/ethers.js/commit/8129f0cb8b932662561d8aa799e4963f44d90c75.

ethers.utils.soliditySha256(types, values)
ethers.utils.solidityKeccak256(types, values)

Both types and values should be arrays of the values you wish to work with.

Give it a try and let me know if you have any issues. There are ~2000 test cases for it procedurally generated in the make-contract-events.js file if curious about coverage.

3reactions
ricmoocommented, Jan 23, 2019

@PhABC I think what you are looking for is ethers.utils.solidityPack? It does not support structs though. Do you need struct support?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to mimic abi.encodePacked in ethers?
When using the Solidity abi.packEncoded(...) function, a non-standard tightly packed version of encoding is used. These functions implement the ...
Read more >
Encoding | Protocol Buffers - Google Developers
Use the packed data type when you are storing consecutive values of the type described in the protocol definition. The tag is dropped...
Read more >
Tightly Packed Tries: How to Fit Large Models into Memory ...
We present Tightly Packed Tries (TPTs), a compact implementation of read-only, com- pressed trie structures with fast on-demand paging and short load times....
Read more >
Chapter 4. Choose Appropriate Visual Encodings - O'Reilly
One way to make decoding easy is to make your encodings of things and relationships as well aligned with the reality (or your...
Read more >
Object Encodings in System F Or: Stacking μ and 9
we have such an instance p, we could for example write p.getx () to get the x-position of the point. The equals-method is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found