Skip to content

Commit 4a59c2f

Browse files
authored
Merge pull request #220 from kyonRay/master
Release v3.7.0
2 parents fcd7cb7 + 4eb6e09 commit 4a59c2f

13 files changed

+442
-193
lines changed

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ println("Notice: current gradle version is " + gradle.gradleVersion)
1111
// Additional attribute definition
1212
ext {
1313
// jackson version
14-
javaSDKVersion="3.6.0"
14+
javaSDKVersion="3.7.0-SNAPSHOT"
1515
//solcJVersion = "0.4.25.1"
1616
//solcJVersion = "0.5.2.1"
1717
//solcJVersion = "0.6.10.1"
1818
solcJVersion = "0.8.11.1"
1919
guavaVersion = "32.0.1-jre"
2020
commonsCollections4Version = "4.4"
21-
springVersion = '5.3.30'
21+
springVersion = '5.3.32'
2222
}
2323

2424
tasks.withType(JavaCompile) {
@@ -81,7 +81,7 @@ List spring = [
8181
"org.springframework:spring-tx:$springVersion",
8282
]
8383

84-
def log4j_version= '2.19.0'
84+
def log4j_version= '2.22.1'
8585
List logger = [
8686
"org.apache.logging.log4j:log4j-api:$log4j_version",
8787
"org.apache.logging.log4j:log4j-core:$log4j_version",
@@ -104,7 +104,7 @@ dependencies {
104104
force true
105105
}
106106
api ("org.fisco-bcos.java-sdk:fisco-bcos-java-sdk:${javaSDKVersion}")
107-
api('org.fisco-bcos.code-generator:bcos-code-generator:1.2.0') {
107+
api('org.fisco-bcos.code-generator:bcos-code-generator:1.4.0') {
108108
exclude group : "org.fisco-bcos.java-sdk"
109109
exclude group : "org.slf4j"
110110
exclude group : " com.fasterxml.jackson.core"

src/main/java/org/fisco/bcos/sdk/demo/contract/DmcTransfer.java

Lines changed: 91 additions & 60 deletions
Large diffs are not rendered by default.

src/main/java/org/fisco/bcos/sdk/demo/contract/MultiTableTest.java

Lines changed: 82 additions & 74 deletions
Large diffs are not rendered by default.

src/main/java/org/fisco/bcos/sdk/demo/contract/sol/DmcTransfer.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ contract DmcTransfer {
4141
} catch {
4242
if (allowRevert){
4343
revert();
44-
} else{
44+
} else {
4545
_balance = _balance + shareMoney;
46+
// if callMyself, update balance
47+
if (toAddr == address(this)){
48+
m_balance = _balance;
49+
}
4650
}
4751
}
4852
}
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity >=0.6.0 <0.8.12;
3+
4+
contract ECRecoverSMTest {
5+
event Address(address addr);
6+
7+
function genValidParams() private pure returns(bytes memory){
8+
bytes memory data = abi.encode(
9+
bytes32(0xaa0f7414b7f8648410f9818df3a1f43419d5c30313f430712033937ae57854c8),
10+
uint8(28),
11+
bytes32(0xacd0d6c91242e514655815073f5f0e9aed671f68a4ed3e3e9d693095779f704b),
12+
bytes32(0x01932751f4431c3b4c9d6fb1c826d138ee155ea72ac9013d66929f6a265386b4));
13+
14+
return data;
15+
}
16+
17+
function genInvalidParams() private pure returns(bytes memory){
18+
bytes memory data = abi.encodeWithSignature("ecrecover(bytes32,uint8,bytes32,bytes32)",
19+
bytes32(0xaa0f7414b7f8648410f9818df3a1f43419d5c30313f430712033937ae57854c8),
20+
uint8(28),
21+
bytes32(0xacd0d6c91242e514655815073f5f0e9aed671f68a4ed3e3e9d693095779f704b),
22+
bytes32(0x01932751f4431c3b4c9d6fb1c826d138ee155ea72ac9013d66929f6a265386b5));
23+
24+
return data;
25+
}
26+
27+
function genLargerInvalidParams(uint addNum) private pure returns(bytes memory){
28+
// append genValidParams() addNum byte
29+
bytes memory addBytes = new bytes(addNum);
30+
bytes memory data = abi.encodePacked(genValidParams(), addBytes);
31+
require(genValidParams().length + addNum == data.length, "genLargerInvalidParams failed");
32+
33+
return data;
34+
}
35+
36+
function genShorterInvalidParams(uint cutNum) private pure returns(bytes memory){
37+
// remove genValidParams() cutNum byte
38+
bytes memory validParams = genValidParams();
39+
require(validParams.length >= cutNum, "genShorterInvalidParams failed");
40+
bytes memory data = new bytes(validParams.length - cutNum);
41+
for(uint i = 0; i < validParams.length - cutNum; i++){
42+
data[i] = validParams[i];
43+
}
44+
45+
require(genValidParams().length - cutNum == data.length, "genShorterInvalidParams failed");
46+
return data;
47+
}
48+
49+
function callECRecover(bytes memory params) public returns (address){
50+
// 调用预编译合约的ECRecover函数
51+
address precompiledContract = address(0x1);
52+
(bool success, bytes memory result) = precompiledContract.call(params);
53+
require(success, "Call to precompiled contract failed");
54+
55+
if (result.length == 0) {
56+
return address(0);
57+
}
58+
59+
address addr;
60+
assembly {
61+
addr := mload(add(result, 32))
62+
}
63+
64+
return addr;
65+
}
66+
67+
function callECRecoverValid() public returns (address){
68+
bytes memory params = genValidParams();
69+
return callECRecover(params);
70+
}
71+
72+
function callECRecoverInvalid() public returns (address){
73+
bytes memory params = genInvalidParams();
74+
return callECRecover(params); // must return 0x0000000000000000000000000000000000000084
75+
}
76+
77+
function callECRecoverDirect() public pure returns (address){
78+
bytes32 hash = bytes32(0xaa0f7414b7f8648410f9818df3a1f43419d5c30313f430712033937ae57854c8);
79+
uint8 v = uint8(28);
80+
bytes32 r = bytes32(0xacd0d6c91242e514655815073f5f0e9aed671f68a4ed3e3e9d693095779f704b);
81+
bytes32 s = bytes32(0x01932751f4431c3b4c9d6fb1c826d138ee155ea72ac9013d66929f6a265386b4);
82+
83+
address addr = ecrecover(hash, v, r, s);
84+
require(addr == address(0x6DA0599583855f1618b380f6782c0c5c25cB96Ec), "ecrecover failed");
85+
return addr;
86+
}
87+
88+
function testRecoverEmptyParams() public {
89+
bytes memory data = abi.encode();
90+
address addr = callECRecover(data);
91+
require(addr == address(0x0), "should recover failed");
92+
}
93+
94+
function testRecoverVRange() public {
95+
uint8[9] memory vs = [uint8(0), uint8(1), uint8(2), uint8(10), uint8(27), uint8(28), uint8(100), uint8(200), uint8(255)];
96+
97+
for(uint i = 0; i < vs.length; i++){
98+
uint8 v = vs[i];
99+
bytes memory data = abi.encode(
100+
bytes32(0xaa0f7414b7f8648410f9818df3a1f43419d5c30313f430712033937ae57854c8),
101+
v,
102+
bytes32(0xacd0d6c91242e514655815073f5f0e9aed671f68a4ed3e3e9d693095779f704b),
103+
bytes32(0x01932751f4431c3b4c9d6fb1c826d138ee155ea72ac9013d66929f6a265386b4));
104+
105+
address addr = callECRecover(data);
106+
// only v = 27 or 28 is valid
107+
if (v == 27){
108+
require(addr == address(0xA5B4792Dcad4FE78D13f6aBD7bA1f302945De4F7), "ecrecover failed");
109+
} else if (v == 28){
110+
require(addr == address(0x6DA0599583855f1618b380f6782c0c5c25cB96Ec), "ecrecover failed");
111+
} else {
112+
require(addr == address(0x0), "should recover failed");
113+
}
114+
}
115+
}
116+
117+
function testRecoverLargerParams() public {
118+
uint[10] memory addNums = [uint(1), uint(5), uint(32), uint(33), uint(64), uint(65), uint(256), uint(257), uint(512), uint(513)];
119+
120+
for(uint i = 0; i < addNums.length; i++){
121+
uint addNum = addNums[i];
122+
bytes memory data = genLargerInvalidParams(addNum);
123+
address addr = callECRecover(data);
124+
require(addr == address(0x6DA0599583855f1618b380f6782c0c5c25cB96Ec), "added bytes should be ignored");
125+
}
126+
}
127+
128+
function testRecoverShorterParams() public {
129+
uint[11] memory cutNums = [uint(1), uint(5), uint(10), uint(18), uint(27), uint(31), uint(32), uint(33), uint(63), uint(64), uint(65)];
130+
131+
for(uint i = 0; i < cutNums.length; i++){
132+
uint cutNum = cutNums[i];
133+
bytes memory data = genShorterInvalidParams(cutNum);
134+
address addr = callECRecover(data);
135+
// should failed when cutNum >= 32
136+
137+
if (cutNum == 1) {
138+
require(addr == address(0x509EAd8b20064F21e35f920cb0c6d6cbC0c0AA0D), "should success when cutNum == 1");
139+
} else if (cutNum == 5) {
140+
require(addr == address(0x571A110cE923c9354B11B247f087b6DAB1AD9089), "should success when cutNum == 5");
141+
} else if (cutNum == 10) {
142+
require(addr == address(0xFaCF3c4d9C0197bF621c39D461970E7a5D2F6947), "should success when cutNum == 10");
143+
} else if (cutNum == 18) {
144+
require(addr == address(0xCc63021A8a9E4c5C58F275C1DbA8536D398C46f5), "should success when cutNum == 18");
145+
} else if (cutNum == 27) {
146+
require(addr == address(0xc6a74652861114A92a30b8399e6eBe2e2e90313e), "should success when cutNum == 27");
147+
} else if (cutNum == 31) {
148+
require(addr == address(0xC275cac475391eEEAdc7a4d0A09781177776D8b5), "should success when cutNum == 31");
149+
} else {
150+
require(addr == address(0x0), "should failed when cutNum >= 32");
151+
}
152+
153+
}
154+
}
155+
156+
function testRecoverBasic() public {
157+
require(callECRecoverValid() == address(0x6DA0599583855f1618b380f6782c0c5c25cB96Ec), "callECRecoverValid failed");
158+
require(callECRecoverDirect() == address(0x6DA0599583855f1618b380f6782c0c5c25cB96Ec), "callECRecoverDirect failed");
159+
}
160+
161+
function testEmitEvent() public {
162+
emit Address(address(0x6DA0599583855f1618b380f6782c0c5c25cB96Ec));
163+
callECRecoverDirect();
164+
}
165+
166+
function compareAddressAndString(address _address, string memory _string) public pure returns (bool) {
167+
bytes32 addressHash = keccak256(abi.encodePacked(_address));
168+
bytes32 stringHash = keccak256(bytes(_string));
169+
170+
return (addressHash == stringHash);
171+
}
172+
173+
function check() public {
174+
testRecoverBasic();
175+
testRecoverEmptyParams();
176+
testRecoverVRange();
177+
testRecoverLargerParams();
178+
testRecoverShorterParams();
179+
}
180+
}

src/main/java/org/fisco/bcos/sdk/demo/contract/sol/MultiTableTest.sol

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ pragma experimental ABIEncoderV2;
44

55
import "./Table.sol";
66

7-
contract TableTest {
8-
7+
contract MultiTableTest {
98

109
TableManager constant tm = TableManager(address(0x1002));
1110
Table table;
12-
string constant TABLE_NAME = "t_test";
13-
constructor () public{
11+
string TABLE_NAME = "t_test";
12+
constructor (string memory name) public {
1413
// create table
1514
string[] memory columnNames = new string[](10);
1615
columnNames[0] = "v0";
@@ -24,7 +23,7 @@ contract TableTest {
2423
columnNames[8] = "v8";
2524
columnNames[9] = "v9";
2625
TableInfo memory tf = TableInfo("key", columnNames);
27-
26+
TABLE_NAME = name;
2827
tm.createTable(TABLE_NAME, tf);
2928
address t_address = tm.openTable(TABLE_NAME);
3029
require(t_address!=address(0x0),"");

src/main/java/org/fisco/bcos/sdk/demo/contract/sol/RecursiveDelegateCallTest.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ contract RecursiveNode {
8585
}
8686

8787
function recursiveCheck(address[] memory contracts, uint i, Info memory info) public payable {
88-
return;
88+
8989
if (i >= contracts.length) {
9090
return;
9191
}

src/main/java/org/fisco/bcos/sdk/demo/perf/DMCTransferDag.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ public void run() {
280280
+ total.toString()
281281
+ ", expectBalance is "
282282
+ expectBalance.toString());
283+
System.exit(1);
283284
}
284285
System.out.println("check finished, total balance equal expectBalance!");
285286
}

src/main/java/org/fisco/bcos/sdk/demo/perf/DMCTransferMyself.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ public void run() {
276276
+ total.intValue()
277277
+ ", expectBalance is "
278278
+ expectBalance.intValue());
279+
System.exit(1);
279280
}
280281
System.out.println("check finished! check finished, total balance equal expectBalance! ");
281282
}

src/main/java/org/fisco/bcos/sdk/demo/perf/DMCTransferRing.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ public void run() {
372372
+ total.toString()
373373
+ ", expectBalance is "
374374
+ expectBalance);
375+
System.exit(1);
375376
}
376377
System.out.println(
377378
"check finished, total balance equal expectBalance! " + total.intValue());

0 commit comments

Comments
 (0)