mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Rename precompile.sol and add more tests
This commit is contained in:
parent
5f6e606e4d
commit
1bde61c0be
@ -1,7 +1,7 @@
|
|||||||
# This will re-generate the headers if any file within src was modified.
|
# This will re-generate the headers if any file within src was modified.
|
||||||
set_directory_properties(PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/solstdlib/src/)
|
set_directory_properties(PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/solstdlib/src/)
|
||||||
|
|
||||||
set(STDLIB precompiles)
|
set(STDLIB cryptography)
|
||||||
set(GENERATED_STDLIB_HEADERS)
|
set(GENERATED_STDLIB_HEADERS)
|
||||||
foreach(src IN LISTS STDLIB)
|
foreach(src IN LISTS STDLIB)
|
||||||
set(STDLIB_FILE ${CMAKE_SOURCE_DIR}/solstdlib/src/${src}.sol)
|
set(STDLIB_FILE ${CMAKE_SOURCE_DIR}/solstdlib/src/${src}.sol)
|
||||||
|
@ -3,13 +3,13 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "solstdlib/precompiles.h"
|
#include "solstdlib/cryptography.h"
|
||||||
|
|
||||||
namespace solidity::solstdlib
|
namespace solidity::solstdlib
|
||||||
{
|
{
|
||||||
|
|
||||||
static std::map<std::string, std::string> sources = {
|
static std::map<std::string, std::string> sources = {
|
||||||
{ "std/precompiles.sol", precompiles },
|
{ "std/cryptography.sol", cryptography },
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace solidity::solstdlib
|
} // namespace solidity::solstdlib
|
||||||
|
@ -14,8 +14,7 @@ function ripemd160(bytes memory input) returns (bytes20 ret) {
|
|||||||
assembly {
|
assembly {
|
||||||
let success := staticcall(gas(), 3, add(input, 32), mload(input), 0, 32)
|
let success := staticcall(gas(), 3, add(input, 32), mload(input), 0, 32)
|
||||||
if iszero(success) { revert(0, 0) }
|
if iszero(success) { revert(0, 0) }
|
||||||
// TODO: check byteorder
|
ret := shl(96, mload(0))
|
||||||
ret := mload(0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
30
test/libsolidity/semanticTests/stdlib/cryptography.sol
Normal file
30
test/libsolidity/semanticTests/stdlib/cryptography.sol
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
pragma stdlib;
|
||||||
|
|
||||||
|
import "std/cryptography.sol";
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
|
||||||
|
function f(uint256 a) external returns (bytes32) {
|
||||||
|
return sha256(abi.encodePacked(a));
|
||||||
|
}
|
||||||
|
|
||||||
|
function g(uint256 a) external returns (bytes20) {
|
||||||
|
return ripemd160(abi.encodePacked(a));
|
||||||
|
}
|
||||||
|
|
||||||
|
function h(bytes32 h, uint8 v, bytes32 r, bytes32 s) public returns (address addr) {
|
||||||
|
return ecrecover(h, v, r, s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ====
|
||||||
|
// EVMVersion: >=constantinople
|
||||||
|
// ----
|
||||||
|
// f(uint256): 1 -> 0xec4916dd28fc4c10d78e287ca5d9cc51ee1ae73cbfde08c6b37324cbfaac8bc5
|
||||||
|
// g(uint256): 4 -> 0x1b0f3c404d12075c68c938f9f60ebea4f74941a0000000000000000000000000
|
||||||
|
// h(bytes32,uint8,bytes32,bytes32):
|
||||||
|
// 0x18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c,
|
||||||
|
// 28,
|
||||||
|
// 0x73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75f,
|
||||||
|
// 0xeeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549
|
||||||
|
// -> 0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b
|
19
test/libsolidity/semanticTests/stdlib/ecrecover.sol
Normal file
19
test/libsolidity/semanticTests/stdlib/ecrecover.sol
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
pragma stdlib;
|
||||||
|
|
||||||
|
import { ecrecover } from "std/cryptography.sol";
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function f(bytes32 h, uint8 v, bytes32 r, bytes32 s) public returns (address addr) {
|
||||||
|
return ecrecover(h, v, r, s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ====
|
||||||
|
// EVMVersion: >=constantinople
|
||||||
|
// ----
|
||||||
|
// f(bytes32,uint8,bytes32,bytes32):
|
||||||
|
// 0x18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c,
|
||||||
|
// 28,
|
||||||
|
// 0x73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75f,
|
||||||
|
// 0xeeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549
|
||||||
|
// -> 0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b
|
14
test/libsolidity/semanticTests/stdlib/ripemd160.sol
Normal file
14
test/libsolidity/semanticTests/stdlib/ripemd160.sol
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
pragma stdlib;
|
||||||
|
|
||||||
|
import { ripemd160 } from "std/cryptography.sol";
|
||||||
|
|
||||||
|
contract C {
|
||||||
|
function f(uint256 a) external returns (bytes20) {
|
||||||
|
return ripemd160(abi.encodePacked(a));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ====
|
||||||
|
// EVMVersion: >=constantinople
|
||||||
|
// ----
|
||||||
|
// f(uint256): 4 -> 0x1b0f3c404d12075c68c938f9f60ebea4f74941a0000000000000000000000000
|
@ -1,11 +1,11 @@
|
|||||||
pragma stdlib;
|
pragma stdlib;
|
||||||
|
|
||||||
import "std/precompiles.sol";
|
import { sha256 } from "std/cryptography.sol";
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
function f(uint256 a) external returns (bytes32) {
|
function f(uint256 a) external returns (bytes32) {
|
||||||
return sha256(abi.encodePacked(a));
|
return sha256(abi.encodePacked(a));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====
|
// ====
|
||||||
|
Loading…
Reference in New Issue
Block a user