Skip to content

Commit fbbbc7d

Browse files
committed
update to latest solitity
1 parent 406b635 commit fbbbc7d

File tree

3 files changed

+36
-34
lines changed

3 files changed

+36
-34
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
# Testonator
44

5-
This library provides a JSON-RPC wrapper to a standalone Ethereum blockchain, used for testing purposes. It uses Solidity 0.4.25. It also provides an wrapper for web3j, where contracts do not have to be generated into Java classes. If your contract looks like this:
5+
This library provides a JSON-RPC wrapper to a standalone Ethereum blockchain, used for testing purposes. It uses Solidity 0.5.6. It also provides an wrapper for web3j, where contracts do not have to be generated into Java classes. If your contract looks like this:
66

77
```
8-
pragma solidity ^0.4.25;
8+
pragma solidity ^0.5.6;
99
1010
contract Example2 {
1111
uint256 public counter = 15;
@@ -38,14 +38,14 @@ Maven:
3838
<dependency>
3939
<groupId>io.iconator</groupId>
4040
<artifactId>testonator</artifactId>
41-
<version>1.0.32</version>
41+
<version>1.0.33</version>
4242
</dependency>
4343
```
4444

4545
Gradle:
4646

4747
```
48-
compile 'io.iconator:testonator:1.0.32'
48+
compile 'io.iconator:testonator:1.0.33'
4949
```
5050

5151
## Example of JSON-RPC request

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ publishing {
2222

2323
group 'io.iconator'
2424
archivesBaseName = 'testonator'
25-
version '1.0.32'
25+
version '1.0.33'
2626

2727
sourceCompatibility = 1.8
2828
targetCompatibility = 1.8
@@ -37,7 +37,7 @@ repositories {
3737

3838
dependencies {
3939
compile 'org.ethereum:ethereumj-core:1.10.0-RELEASE'
40-
compile 'org.ethereum:solcJ-all:0.5.2'
40+
compile 'org.ethereum:solcJ-all:0.5.6'
4141
compile 'com.github.briandilley.jsonrpc4j:jsonrpc4j:1.5.3'
4242
compile 'commons-io:commons-io:2.6'
4343
compile 'org.web3j:core:4.1.0'

src/test/resources/Utils.sol

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,46 +49,48 @@ library Utils {
4949
//From: https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/cryptography/ECDSA.sol
5050

5151
/**
52-
* @notice Recover signer address from a message by using his signature
53-
* @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address.
54-
* @param sig bytes signature, the signature is generated using web3.eth.sign()
55-
*/
56-
function recover(bytes32 hash, bytes memory sig) internal pure returns (address) {
57-
//r is computed as the X coordinate of a point R, modulo the curve order n.
52+
* @dev Recover signer address from a message by using their signature
53+
* @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address.
54+
* @param signature bytes signature, the signature is generated using web3.eth.sign()
55+
*/
56+
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
57+
// Check the signature length
58+
if (signature.length != 65) {
59+
return (address(0));
60+
}
61+
62+
// Divide the signature in r, s and v variables
5863
bytes32 r;
59-
//s is (hash+rdA) / random number
6064
bytes32 s;
61-
//v is used for public key recovery: https://bitcoin.stackexchange.com/questions/38351/ecdsa-v-r-s-what-is-v
6265
uint8 v;
6366

64-
//Check the signature length
65-
if (sig.length != 65) {
66-
return address(0);
67-
}
68-
69-
// Divide the signature in r, s and v variables
67+
// ecrecover takes the signature parameters, and the only way to get them
68+
// currently is to use assembly.
69+
// solhint-disable-next-line no-inline-assembly
7070
assembly {
71-
r := mload(add(sig, 32))
72-
s := mload(add(sig, 64))
73-
v := byte(0, mload(add(sig, 96)))
71+
r := mload(add(signature, 0x20))
72+
s := mload(add(signature, 0x40))
73+
v := byte(0, mload(add(signature, 0x60)))
7474
}
7575

76-
//EIP-2 still allows signature malleabality, remove this possibility
77-
if(uint256(s) > uint256(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0)) {
76+
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
77+
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
78+
// the valid range for s in (281): 0 < s < secp256k1n ÷ 2 + 1, and for v in (282): v ∈ {27, 28}. Most
79+
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
80+
//
81+
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
82+
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
83+
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
84+
// these malleable signatures as well.
85+
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
7886
return address(0);
7987
}
8088

81-
//removed the possibility of 0/1 in the signature, see:
82-
//https://github.com/OpenZeppelin/openzeppelin-solidity/pull/1622
83-
//https://github.com/ethereum/EIPs/issues/865
84-
85-
// If the version is correct return the signer address
86-
// see
87-
// https://github.com/ethereum/go-ethereum/blob/master/core/types/transaction_signing.go#L195
8889
if (v != 27 && v != 28) {
8990
return address(0);
90-
} else {
91-
return ecrecover(hash, v, r, s);
9291
}
92+
93+
// If the signature is valid (and not malleable), return the signer address
94+
return ecrecover(hash, v, r, s);
9395
}
9496
}

0 commit comments

Comments
 (0)