ethers-io / ethers.objc

Fast, simple and complete library for Ethereum in Objective-C.
MIT License
157 stars 57 forks source link

High memory #21

Closed SkyByte93 closed 6 years ago

SkyByte93 commented 6 years ago

I found that using the encryptSecretStorageJSON method consumes very high memory. Basically around 250M. Basically around 250M, why do you have such a high memory, thanks! let account = Account.randomMnemonic() _ = account?.encryptSecretStorageJSON(password, callback: { (json) in })

ricmoo commented 6 years ago

After encrypting is the memory not being released?

The scrypt algorithm is intentionally memory intensive. By using memory-hard algorithms the cost of brute-forcing a password become computationally infeasable. Targeting memory makes the algorithm expensive to parallelze, since memory bandwidth is usually already maxed out in any given device (since it is always the bottleneck) and random memory access does not scale well with respect to ASICs.

I will do some memory analysis to make sure there aren’t other issues, but as long as after key derivation the memory is either released or can be re-allocated, I don’t believe this is an issue.