From 8567277e6c767a1d8aac7f1067c80928e3590058 Mon Sep 17 00:00:00 2001 From: wenlinli <1574249665@qq.com> Date: Fri, 12 Jul 2024 16:34:37 +0800 Subject: [PATCH 01/11] add Reentrancy Locks test contract add update StorageContract.sol --- .../solidity/0.8.26/DoubleBufferContract.sol | 50 +++++++++++++++++++ .../solidity/0.8.26/StorageContract.sol | 10 ++++ .../0.8.26/TestDoubleBufferContract.sol | 27 ++++++++++ 3 files changed, 87 insertions(+) create mode 100644 src/main/resources/contract/solidity/0.8.26/DoubleBufferContract.sol create mode 100644 src/main/resources/contract/solidity/0.8.26/TestDoubleBufferContract.sol diff --git a/src/main/resources/contract/solidity/0.8.26/DoubleBufferContract.sol b/src/main/resources/contract/solidity/0.8.26/DoubleBufferContract.sol new file mode 100644 index 00000000..e8e01198 --- /dev/null +++ b/src/main/resources/contract/solidity/0.8.26/DoubleBufferContract.sol @@ -0,0 +1,50 @@ +contract DoubleBufferContract { + uint[] bufferA; + uint[] bufferB; + + modifier nonreentrant(bytes32 key) { + assembly { + if tload(key) {revert(0, 0)} + tstore(key, 1) + } + _; + assembly { + tstore(key, 0) + } + } + + bytes32 constant A_LOCK = keccak256("a"); + bytes32 constant B_LOCK = keccak256("b"); + + function pushA() nonreentrant(A_LOCK) public payable { + bufferA.push(msg.value); + } + + function popA() nonreentrant(A_LOCK) public { + require(bufferA.length > 0); + + (bool success,) = msg.sender.call{value: bufferA[bufferA.length - 1]}(""); + require(success); + bufferA.pop(); + } + + function pushB() nonreentrant(B_LOCK) public payable { + bufferB.push(msg.value); + } + + function popB() nonreentrant(B_LOCK) public { + require(bufferB.length > 0); + + (bool success,) = msg.sender.call{value: bufferB[bufferB.length - 1]}(""); + require(success); + bufferB.pop(); + } + + function getBufferA() public view returns (uint256[] memory) { + return bufferA; + } + + function getBufferB() public view returns (uint256[] memory) { + return bufferB; + } +} \ No newline at end of file diff --git a/src/main/resources/contract/solidity/0.8.26/StorageContract.sol b/src/main/resources/contract/solidity/0.8.26/StorageContract.sol index 44138493..4719b10d 100644 --- a/src/main/resources/contract/solidity/0.8.26/StorageContract.sol +++ b/src/main/resources/contract/solidity/0.8.26/StorageContract.sol @@ -12,6 +12,7 @@ contract StorageContract { StorageSlot.Int256SlotType private int256Slot = StorageSlot.asInt256(keccak256("int256_slot")); function setAddress(address _value) public { + require(_value != address(0), "Invalid address"); addressSlot.tstore(_value); } @@ -20,6 +21,7 @@ contract StorageContract { } function setBoolean(bool _value) public { + require(_value == true || _value == false, "Input must be a boolean value"); booleanSlot.tstore(_value); } @@ -28,6 +30,7 @@ contract StorageContract { } function setBytes32(bytes32 _value) public { + require(_value != bytes32(0), "Invalid bytes32 value"); bytes32Slot.tstore(_value); } @@ -36,6 +39,7 @@ contract StorageContract { } function setUint256(uint256 _value) public { + require(_value <= type(uint256).max, "Invalid uint256 value"); uint256Slot.tstore(_value); } @@ -44,6 +48,7 @@ contract StorageContract { } function setInt256(int256 _value) public { + require(_value >= type(int256).min && _value < type(int256).max, "Invalid int256 value"); int256Slot.tstore(_value); } @@ -52,26 +57,31 @@ contract StorageContract { } function storeIntTest(int256 _value) public returns (int256) { + require(_value >= type(int256).min && _value < type(int256).max, "Invalid int256 value"); int256Slot.tstore(_value); return int256Slot.tload(); } function storeUintTest(uint256 _value) public returns (uint256) { + require(_value <= type(uint256).max, "Invalid uint256 value"); uint256Slot.tstore(_value); return uint256Slot.tload(); } function storeBytes32Test(bytes32 _value) public returns (bytes32) { + require(_value != bytes32(0), "Invalid bytes32 value"); bytes32Slot.tstore(_value); return bytes32Slot.tload(); } function storeBooleanTest(bool _value) public returns (bool) { + require(_value == true || _value == false, "Input must be a boolean value"); booleanSlot.tstore(_value); return booleanSlot.tload(); } function storeAddressTest(address _value) public returns (address) { + require(_value != address(0), "Invalid address"); addressSlot.tstore(_value); return addressSlot.tload(); } diff --git a/src/main/resources/contract/solidity/0.8.26/TestDoubleBufferContract.sol b/src/main/resources/contract/solidity/0.8.26/TestDoubleBufferContract.sol new file mode 100644 index 00000000..013e229a --- /dev/null +++ b/src/main/resources/contract/solidity/0.8.26/TestDoubleBufferContract.sol @@ -0,0 +1,27 @@ +pragma solidity ^0.8.0; + +import "./DoubleBufferContract.sol"; + +contract TestDoubleBufferContract { + DoubleBufferContract public doubleBufferContract; + + constructor() { + doubleBufferContract = new DoubleBufferContract(); + } + + function testReentrancyA() public { + doubleBufferContract.pushA{value: 1 ether}(); + // 尝试再次调用pushA函数,应该被阻止 + doubleBufferContract.pushA{value: 1 ether}(); + } + + function testReentrancyB() public { + doubleBufferContract.pushB{value: 1 ether}(); + // 尝试再次调用pushB函数,应该被阻止 + doubleBufferContract.pushB{value: 1 ether}(); + } + + receive() external payable { + doubleBufferContract.pushA{value: 1 ether}(); + } +} \ No newline at end of file From 406d85fbc1bd5eec64bb0cde6f468fd1322893ca Mon Sep 17 00:00:00 2001 From: wenlinli <1574249665@qq.com> Date: Wed, 17 Jul 2024 16:20:12 +0800 Subject: [PATCH 02/11] update StorageContract.sol and workflow.yml --- .github/workflows/workflow.yml | 4 ++-- .../contract/solidity/0.8.26/StorageContract.sol | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 2e4455e2..24d71087 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -44,8 +44,8 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-20.04] - container: docker.io/centos:7 + os: [ ubuntu-22.04 ] + container: docker.io/centos:8 steps: - uses: actions/checkout@v2 with: diff --git a/src/main/resources/contract/solidity/0.8.26/StorageContract.sol b/src/main/resources/contract/solidity/0.8.26/StorageContract.sol index 4719b10d..2dcebe67 100644 --- a/src/main/resources/contract/solidity/0.8.26/StorageContract.sol +++ b/src/main/resources/contract/solidity/0.8.26/StorageContract.sol @@ -21,7 +21,8 @@ contract StorageContract { } function setBoolean(bool _value) public { - require(_value == true || _value == false, "Input must be a boolean value"); + require(_value == true, "Input must be a boolean value"); + require(_value == false, "Input must be a boolean value"); booleanSlot.tstore(_value); } @@ -48,7 +49,8 @@ contract StorageContract { } function setInt256(int256 _value) public { - require(_value >= type(int256).min && _value < type(int256).max, "Invalid int256 value"); + require(_value >= type(int256).min, "Invalid int256 value"); + require(_value < type(int256).max, "Invalid int256 value"); int256Slot.tstore(_value); } @@ -57,8 +59,10 @@ contract StorageContract { } function storeIntTest(int256 _value) public returns (int256) { - require(_value >= type(int256).min && _value < type(int256).max, "Invalid int256 value"); + require(_value >= type(int256).min, "Invalid int256 value"); + require(_value < type(int256).max, "Invalid int256 value"); int256Slot.tstore(_value); + return int256Slot.tload(); } @@ -75,7 +79,8 @@ contract StorageContract { } function storeBooleanTest(bool _value) public returns (bool) { - require(_value == true || _value == false, "Input must be a boolean value"); + require(_value == true, "Input must be a boolean value"); + require(_value == false, "Input must be a boolean value"); booleanSlot.tstore(_value); return booleanSlot.tload(); } From ae2ef5e67d20361a75f8c148b10af322829077d0 Mon Sep 17 00:00:00 2001 From: wenlinli <1574249665@qq.com> Date: Wed, 17 Jul 2024 16:26:34 +0800 Subject: [PATCH 03/11] fix ci error --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 24d71087..58b2eaf6 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -45,7 +45,7 @@ jobs: fail-fast: false matrix: os: [ ubuntu-22.04 ] - container: docker.io/centos:8 + container: docker.io/centos:lastest steps: - uses: actions/checkout@v2 with: From 6205c1df5bbe570156f26c672edddd32c4b340d8 Mon Sep 17 00:00:00 2001 From: wenlinli <1574249665@qq.com> Date: Wed, 17 Jul 2024 16:50:27 +0800 Subject: [PATCH 04/11] fix ci error 1 --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 58b2eaf6..f9264aa8 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -44,7 +44,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ ubuntu-22.04 ] + os: [ ubuntu-20.04 ] container: docker.io/centos:lastest steps: - uses: actions/checkout@v2 From 9ae9f4ba261527232048963f32966d67416776f0 Mon Sep 17 00:00:00 2001 From: wenlinli <1574249665@qq.com> Date: Wed, 17 Jul 2024 16:55:32 +0800 Subject: [PATCH 05/11] fix ci error 1 --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index f9264aa8..e48dbaee 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -45,7 +45,7 @@ jobs: fail-fast: false matrix: os: [ ubuntu-20.04 ] - container: docker.io/centos:lastest + container: docker.io/centos:7.9 steps: - uses: actions/checkout@v2 with: From 505e7d4395f2e0049e97c759daa67be4ee7d079e Mon Sep 17 00:00:00 2001 From: wenlinli <1574249665@qq.com> Date: Fri, 19 Jul 2024 11:30:46 +0800 Subject: [PATCH 06/11] revert --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index e48dbaee..302e14d6 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -45,7 +45,7 @@ jobs: fail-fast: false matrix: os: [ ubuntu-20.04 ] - container: docker.io/centos:7.9 + container: docker.io/centos:7 steps: - uses: actions/checkout@v2 with: From ac381909d85944a630f8ce33daee5bba3a6ab6f7 Mon Sep 17 00:00:00 2001 From: Kyon <32325790+kyonRay@users.noreply.github.com> Date: Fri, 19 Jul 2024 11:44:25 +0800 Subject: [PATCH 07/11] Update workflow.yml --- .github/workflows/workflow.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 302e14d6..7d31ae6d 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -45,7 +45,7 @@ jobs: fail-fast: false matrix: os: [ ubuntu-20.04 ] - container: docker.io/centos:7 + container: docker.io/centos:latest steps: - uses: actions/checkout@v2 with: @@ -60,4 +60,4 @@ jobs: - name: run integration testing run: /bin/bash -x .ci/ci_check.sh - name: upload coverage - run: curl -LO https://codecov.io/bash && /bin/bash ./bash \ No newline at end of file + run: curl -LO https://codecov.io/bash && /bin/bash ./bash From 93c28c611c6a83abcdc1c816f07318d4e3396ceb Mon Sep 17 00:00:00 2001 From: wenlinli <1574249665@qq.com> Date: Fri, 19 Jul 2024 12:37:17 +0800 Subject: [PATCH 08/11] update --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 302e14d6..e16aded3 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -45,7 +45,7 @@ jobs: fail-fast: false matrix: os: [ ubuntu-20.04 ] - container: docker.io/centos:7 + container: docker.io/centos:latest steps: - uses: actions/checkout@v2 with: From bac9eb27f9609c0bd19a04a797390d50206ef90e Mon Sep 17 00:00:00 2001 From: wenlinli <1574249665@qq.com> Date: Fri, 19 Jul 2024 14:38:20 +0800 Subject: [PATCH 09/11] fix --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index e16aded3..cdc7f980 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -51,7 +51,7 @@ jobs: with: fetch-depth: 5 - name: install CentOS dependencies - run: yum install -y epel-release centos-release-scl which git openssl-devel openssl wget + run: yum install -y which git openssl-devel openssl wget - name: Set up JDK 1.8 uses: actions/setup-java@v3 with: From 498b3d5f92ca331ba0e5306ce1ac66017a36e4c0 Mon Sep 17 00:00:00 2001 From: wenlinli <1574249665@qq.com> Date: Thu, 25 Jul 2024 17:21:15 +0800 Subject: [PATCH 10/11] fix ci --- .github/workflows/workflow.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 1f3122f3..1fd718b9 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -51,7 +51,9 @@ jobs: with: fetch-depth: 5 - name: install CentOS dependencies - run: yum install -y which git openssl-devel openssl wget + run: | + yum clean all + yum install -y which git openssl-devel openssl wget - name: Set up JDK 1.8 uses: actions/setup-java@v3 with: From 6af959142663713d65bc4d77b1e5c76a374fb976 Mon Sep 17 00:00:00 2001 From: wenlinli <1574249665@qq.com> Date: Mon, 29 Jul 2024 19:14:30 +0800 Subject: [PATCH 11/11] update centos yum repo --- .github/workflows/workflow.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 1fd718b9..8ac222c3 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -52,7 +52,10 @@ jobs: fetch-depth: 5 - name: install CentOS dependencies run: | - yum clean all + cd /etc/yum.repos.d/ + sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* + sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* + yum update -y yum install -y which git openssl-devel openssl wget - name: Set up JDK 1.8 uses: actions/setup-java@v3