Skip to content

Commit

Permalink
Merge pull request #220 from kyonRay/master
Browse files Browse the repository at this point in the history
Release v3.7.0
  • Loading branch information
kyonRay authored Mar 23, 2024
2 parents fcd7cb7 + 4eb6e09 commit 4a59c2f
Show file tree
Hide file tree
Showing 13 changed files with 442 additions and 193 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ println("Notice: current gradle version is " + gradle.gradleVersion)
// Additional attribute definition
ext {
// jackson version
javaSDKVersion="3.6.0"
javaSDKVersion="3.7.0-SNAPSHOT"
//solcJVersion = "0.4.25.1"
//solcJVersion = "0.5.2.1"
//solcJVersion = "0.6.10.1"
solcJVersion = "0.8.11.1"
guavaVersion = "32.0.1-jre"
commonsCollections4Version = "4.4"
springVersion = '5.3.30'
springVersion = '5.3.32'
}

tasks.withType(JavaCompile) {
Expand Down Expand Up @@ -81,7 +81,7 @@ List spring = [
"org.springframework:spring-tx:$springVersion",
]

def log4j_version= '2.19.0'
def log4j_version= '2.22.1'
List logger = [
"org.apache.logging.log4j:log4j-api:$log4j_version",
"org.apache.logging.log4j:log4j-core:$log4j_version",
Expand All @@ -104,7 +104,7 @@ dependencies {
force true
}
api ("org.fisco-bcos.java-sdk:fisco-bcos-java-sdk:${javaSDKVersion}")
api('org.fisco-bcos.code-generator:bcos-code-generator:1.2.0') {
api('org.fisco-bcos.code-generator:bcos-code-generator:1.4.0') {
exclude group : "org.fisco-bcos.java-sdk"
exclude group : "org.slf4j"
exclude group : " com.fasterxml.jackson.core"
Expand Down
151 changes: 91 additions & 60 deletions src/main/java/org/fisco/bcos/sdk/demo/contract/DmcTransfer.java

Large diffs are not rendered by default.

156 changes: 82 additions & 74 deletions src/main/java/org/fisco/bcos/sdk/demo/contract/MultiTableTest.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ contract DmcTransfer {
} catch {
if (allowRevert){
revert();
} else{
} else {
_balance = _balance + shareMoney;
// if callMyself, update balance
if (toAddr == address(this)){
m_balance = _balance;
}
}
}
}
Expand Down
180 changes: 180 additions & 0 deletions src/main/java/org/fisco/bcos/sdk/demo/contract/sol/ECRecoverSMTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.6.0 <0.8.12;

contract ECRecoverSMTest {
event Address(address addr);

function genValidParams() private pure returns(bytes memory){
bytes memory data = abi.encode(
bytes32(0xaa0f7414b7f8648410f9818df3a1f43419d5c30313f430712033937ae57854c8),
uint8(28),
bytes32(0xacd0d6c91242e514655815073f5f0e9aed671f68a4ed3e3e9d693095779f704b),
bytes32(0x01932751f4431c3b4c9d6fb1c826d138ee155ea72ac9013d66929f6a265386b4));

return data;
}

function genInvalidParams() private pure returns(bytes memory){
bytes memory data = abi.encodeWithSignature("ecrecover(bytes32,uint8,bytes32,bytes32)",
bytes32(0xaa0f7414b7f8648410f9818df3a1f43419d5c30313f430712033937ae57854c8),
uint8(28),
bytes32(0xacd0d6c91242e514655815073f5f0e9aed671f68a4ed3e3e9d693095779f704b),
bytes32(0x01932751f4431c3b4c9d6fb1c826d138ee155ea72ac9013d66929f6a265386b5));

return data;
}

function genLargerInvalidParams(uint addNum) private pure returns(bytes memory){
// append genValidParams() addNum byte
bytes memory addBytes = new bytes(addNum);
bytes memory data = abi.encodePacked(genValidParams(), addBytes);
require(genValidParams().length + addNum == data.length, "genLargerInvalidParams failed");

return data;
}

function genShorterInvalidParams(uint cutNum) private pure returns(bytes memory){
// remove genValidParams() cutNum byte
bytes memory validParams = genValidParams();
require(validParams.length >= cutNum, "genShorterInvalidParams failed");
bytes memory data = new bytes(validParams.length - cutNum);
for(uint i = 0; i < validParams.length - cutNum; i++){
data[i] = validParams[i];
}

require(genValidParams().length - cutNum == data.length, "genShorterInvalidParams failed");
return data;
}

function callECRecover(bytes memory params) public returns (address){
// 调用预编译合约的ECRecover函数
address precompiledContract = address(0x1);
(bool success, bytes memory result) = precompiledContract.call(params);
require(success, "Call to precompiled contract failed");

if (result.length == 0) {
return address(0);
}

address addr;
assembly {
addr := mload(add(result, 32))
}

return addr;
}

function callECRecoverValid() public returns (address){
bytes memory params = genValidParams();
return callECRecover(params);
}

function callECRecoverInvalid() public returns (address){
bytes memory params = genInvalidParams();
return callECRecover(params); // must return 0x0000000000000000000000000000000000000084
}

function callECRecoverDirect() public pure returns (address){
bytes32 hash = bytes32(0xaa0f7414b7f8648410f9818df3a1f43419d5c30313f430712033937ae57854c8);
uint8 v = uint8(28);
bytes32 r = bytes32(0xacd0d6c91242e514655815073f5f0e9aed671f68a4ed3e3e9d693095779f704b);
bytes32 s = bytes32(0x01932751f4431c3b4c9d6fb1c826d138ee155ea72ac9013d66929f6a265386b4);

address addr = ecrecover(hash, v, r, s);
require(addr == address(0x6DA0599583855f1618b380f6782c0c5c25cB96Ec), "ecrecover failed");
return addr;
}

function testRecoverEmptyParams() public {
bytes memory data = abi.encode();
address addr = callECRecover(data);
require(addr == address(0x0), "should recover failed");
}

function testRecoverVRange() public {
uint8[9] memory vs = [uint8(0), uint8(1), uint8(2), uint8(10), uint8(27), uint8(28), uint8(100), uint8(200), uint8(255)];

for(uint i = 0; i < vs.length; i++){
uint8 v = vs[i];
bytes memory data = abi.encode(
bytes32(0xaa0f7414b7f8648410f9818df3a1f43419d5c30313f430712033937ae57854c8),
v,
bytes32(0xacd0d6c91242e514655815073f5f0e9aed671f68a4ed3e3e9d693095779f704b),
bytes32(0x01932751f4431c3b4c9d6fb1c826d138ee155ea72ac9013d66929f6a265386b4));

address addr = callECRecover(data);
// only v = 27 or 28 is valid
if (v == 27){
require(addr == address(0xA5B4792Dcad4FE78D13f6aBD7bA1f302945De4F7), "ecrecover failed");
} else if (v == 28){
require(addr == address(0x6DA0599583855f1618b380f6782c0c5c25cB96Ec), "ecrecover failed");
} else {
require(addr == address(0x0), "should recover failed");
}
}
}

function testRecoverLargerParams() public {
uint[10] memory addNums = [uint(1), uint(5), uint(32), uint(33), uint(64), uint(65), uint(256), uint(257), uint(512), uint(513)];

for(uint i = 0; i < addNums.length; i++){
uint addNum = addNums[i];
bytes memory data = genLargerInvalidParams(addNum);
address addr = callECRecover(data);
require(addr == address(0x6DA0599583855f1618b380f6782c0c5c25cB96Ec), "added bytes should be ignored");
}
}

function testRecoverShorterParams() public {
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)];

for(uint i = 0; i < cutNums.length; i++){
uint cutNum = cutNums[i];
bytes memory data = genShorterInvalidParams(cutNum);
address addr = callECRecover(data);
// should failed when cutNum >= 32

if (cutNum == 1) {
require(addr == address(0x509EAd8b20064F21e35f920cb0c6d6cbC0c0AA0D), "should success when cutNum == 1");
} else if (cutNum == 5) {
require(addr == address(0x571A110cE923c9354B11B247f087b6DAB1AD9089), "should success when cutNum == 5");
} else if (cutNum == 10) {
require(addr == address(0xFaCF3c4d9C0197bF621c39D461970E7a5D2F6947), "should success when cutNum == 10");
} else if (cutNum == 18) {
require(addr == address(0xCc63021A8a9E4c5C58F275C1DbA8536D398C46f5), "should success when cutNum == 18");
} else if (cutNum == 27) {
require(addr == address(0xc6a74652861114A92a30b8399e6eBe2e2e90313e), "should success when cutNum == 27");
} else if (cutNum == 31) {
require(addr == address(0xC275cac475391eEEAdc7a4d0A09781177776D8b5), "should success when cutNum == 31");
} else {
require(addr == address(0x0), "should failed when cutNum >= 32");
}

}
}

function testRecoverBasic() public {
require(callECRecoverValid() == address(0x6DA0599583855f1618b380f6782c0c5c25cB96Ec), "callECRecoverValid failed");
require(callECRecoverDirect() == address(0x6DA0599583855f1618b380f6782c0c5c25cB96Ec), "callECRecoverDirect failed");
}

function testEmitEvent() public {
emit Address(address(0x6DA0599583855f1618b380f6782c0c5c25cB96Ec));
callECRecoverDirect();
}

function compareAddressAndString(address _address, string memory _string) public pure returns (bool) {
bytes32 addressHash = keccak256(abi.encodePacked(_address));
bytes32 stringHash = keccak256(bytes(_string));

return (addressHash == stringHash);
}

function check() public {
testRecoverBasic();
testRecoverEmptyParams();
testRecoverVRange();
testRecoverLargerParams();
testRecoverShorterParams();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ pragma experimental ABIEncoderV2;

import "./Table.sol";

contract TableTest {

contract MultiTableTest {

TableManager constant tm = TableManager(address(0x1002));
Table table;
string constant TABLE_NAME = "t_test";
constructor () public{
string TABLE_NAME = "t_test";
constructor (string memory name) public {
// create table
string[] memory columnNames = new string[](10);
columnNames[0] = "v0";
Expand All @@ -24,7 +23,7 @@ contract TableTest {
columnNames[8] = "v8";
columnNames[9] = "v9";
TableInfo memory tf = TableInfo("key", columnNames);

TABLE_NAME = name;
tm.createTable(TABLE_NAME, tf);
address t_address = tm.openTable(TABLE_NAME);
require(t_address!=address(0x0),"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ contract RecursiveNode {
}

function recursiveCheck(address[] memory contracts, uint i, Info memory info) public payable {
return;

if (i >= contracts.length) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ public void run() {
+ total.toString()
+ ", expectBalance is "
+ expectBalance.toString());
System.exit(1);
}
System.out.println("check finished, total balance equal expectBalance!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ public void run() {
+ total.intValue()
+ ", expectBalance is "
+ expectBalance.intValue());
System.exit(1);
}
System.out.println("check finished! check finished, total balance equal expectBalance! ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ public void run() {
+ total.toString()
+ ", expectBalance is "
+ expectBalance);
System.exit(1);
}
System.out.println(
"check finished, total balance equal expectBalance! " + total.intValue());
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/org/fisco/bcos/sdk/demo/perf/DMCTransferStar.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,21 @@ public void run() {
new Runnable() {

public void run() {
List<String> myContractAddress = new ArrayList<>();
myContractAddress.add(contractsAddr[index]);

contracts[index].addNextCall(userAddress, starCenterAddr);
contracts[index].addNextCall(userAddress, myContractAddress);
contracts[index].addNextCall(
contractsAddr[index], starCenterAddr);

// contracts[index].addNextCall(userAddress, starCenterAddr);
callRelationshipLatch.countDown();
}
});
}
callRelationshipLatch.await();
System.out.println("Create contract and generate call relationship finished!");
System.out.println("starCenterAddr: " + starCenterAddr);

System.out.println("Sending transactions...");
ProgressBar sendedBar =
Expand Down Expand Up @@ -221,7 +228,7 @@ public void run() {
DmcTransfer contract = contracts[fromIndex];
long now = System.currentTimeMillis();
contract.takeShare(
BigInteger.valueOf(2),
BigInteger.valueOf(3),
allowRevert,
new TransactionCallback() {
@Override
Expand All @@ -238,7 +245,7 @@ public void onResponse(
transactionLatch.countDown();
totalCost.addAndGet(
System.currentTimeMillis() - now);
expectBalance.addAndGet(2);
expectBalance.addAndGet(3);
}
});

Expand Down Expand Up @@ -283,6 +290,7 @@ public void run() {
+ total.intValue()
+ ", expectBalance is "
+ expectBalance.intValue());
System.exit(1);
}
System.out.println("check finished, total balance equal expectBalance !");
}
Expand Down
Loading

0 comments on commit 4a59c2f

Please sign in to comment.