I wanna compute sha256 in Solidity Assembly for hash of getting bytes slice.
Asked
Active
Viewed 488 times
1 Answers
1
Sha256 is one of a few precompiled smart contracts:
function subSha256(bytes memory data, uint256 offset, uint256 length) public view returns(bytes32) {
bytes32[1] memory result;
assembly {
pop(staticcall(gas, 0x02, add(add(data, 32), offset), length, result, 32))
}
return result[0];
}
k06a
- 3,016
- 2
- 21
- 35
staticcallat the Solidity level, and get(bool success, bytes memory result)returned to you. – goodvibration May 26 '20 at 16:54