Skip to content

Commit eb841d0

Browse files
committed
merge: resolve conflict with upstream develop (allowTvmOsaka)
- Delete ConfigKey.java (our intent), absorb new allowTvmOsaka field - Add allowTvmOsaka to CommitteeConfig bean and reference.conf - Bridge to CommonParameter in applyCommitteeConfig
2 parents ad7c8bb + bb8b4be commit eb841d0

5,845 files changed

Lines changed: 540497 additions & 59 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# FreezeTest CREATE2 地址预测失败修复记录
2+
3+
## 背景
4+
5+
`config-test.conf` 的地址前缀从 testnet `0xa0` 改为 mainnet `0x41` 后,`FreezeTest` 中 18 个测试用例失败。
6+
7+
失败断言:
8+
```java
9+
Assert.assertArrayEquals(predictedAddr, deployCreate2Contract(factoryAddr, salt));
10+
// predictedAddr(Solidity 预测)≠ deployCreate2Contract(TVM CREATE2 实际部署)
11+
```
12+
13+
## 根因分析
14+
15+
### EIP-1014 CREATE2 地址计算公式
16+
17+
标准 EVM:
18+
```
19+
address = keccak256(0xff ++ sender[20] ++ salt[32] ++ keccak256(code)[32])[12:]
20+
```
21+
22+
TRON TVM 做了两处定制:
23+
1. **magic byte**:标准 `0xff` 被替换为**地址前缀字节**(testnet=`0xa0`,mainnet=`0x41`
24+
2. **sender 长度**:使用 21 字节 TRON 地址(含前缀),而非 20 字节 EVM 地址
25+
26+
### 两条计算路径
27+
28+
#### 路径 1:Solidity 合约预测(`getCreate2Addr`
29+
30+
工厂合约的 `getCreate2Addr` 函数编译后的关键字节码:
31+
32+
```
33+
60a0 PUSH1 0xa0 ← 硬编码的 magic byte(编译时确定)
34+
60f8 PUSH1 0xf8
35+
1b SHL ← bytes1(0xa0)
36+
30 ADDRESS ← address(this),20 字节 EVM 地址
37+
```
38+
39+
对应 Solidity 源码:
40+
```solidity
41+
keccak256(abi.encodePacked(bytes1(0xa0), address(this), salt, keccak256(bytecode)))
42+
```
43+
44+
输入:`[0xa0, A₁..A₂₀, salt₃₂, codeHash₃₂]` = 85 字节
45+
46+
#### 路径 2:TVM CREATE2 操作码(`deployCreate2Contract`
47+
48+
`Program.java:1618-1634`
49+
```java
50+
senderAddress = getContextAddress(); // 21 字节:[prefix, A₁..A₂₀]
51+
WalletUtil.generateContractAddress2(senderAddress, salt, programCode);
52+
// → sha3omit12(merge(senderAddress₂₁, salt₃₂, sha3(code)₃₂))
53+
```
54+
55+
输入:`[prefix, A₁..A₂₀, salt₃₂, sha3(code)₃₂]` = 85 字节
56+
57+
### 关键差异
58+
59+
| | Solidity 预测 | TVM CREATE2 |
60+
|---|---|---|
61+
| 第一字节 | `0xa0`(字节码硬编码) | `DecodeUtil.addressPreFixByte`(运行时) |
62+
| 后续 20 字节 | `address(this)` | `getContextAddress()[1:21]` |
63+
64+
- **prefix = `0xa0`**:两条路径输入完全一致 → hash 相同 → 地址匹配 ✅
65+
- **prefix = `0x41`**:第一字节不同(`0xa0` vs `0x41`)→ hash 不同 → 地址不匹配 ❌
66+
67+
### 结论
68+
69+
**不是"碰巧通过"**。FACTORY_CODE 字节码是用 TRON 定制 Solidity 编译器在 testnet 环境下编译的,编译器将 CREATE2 的 magic byte 从标准的 `0xff` 替换为当时的地址前缀 `0xa0`。改为 `0x41` 后,字节码中的硬编码 `0xa0` 与运行时的 `0x41` 不再匹配。
70+
71+
## 修复
72+
73+
`FreezeTest.java` 第 85 行,将 FACTORY_CODE 中的 `60a0` 改为 `6041`
74+
75+
```diff
76+
- "0f59150813b61017357600080fd5b8192505050919050565b60008060a060f81b30846040518060200161019"
77+
+ "0f59150813b61017357600080fd5b8192505050919050565b600080604160f81b30846040518060200161019"
78+
```
79+
80+
`PUSH1 0xa0``PUSH1 0x41`,使 Solidity 预测函数的 magic byte 与新的运行时前缀一致。
81+
82+
## 涉及的关键代码位置
83+
84+
| 文件 | 行号 | 说明 |
85+
|---|---|---|
86+
| `DataWord.java` | 190-195 | `toTronAddress()`:前缀 + 20字节 = 21字节 TRON 地址 |
87+
| `OperationActions.java` | 303-312 | `addressAction`:Solidity `address(this)` 返回 20 字节 |
88+
| `Program.java` | 1337-1338 | `getContextAddress()`:返回 21 字节 TRON 地址 |
89+
| `Program.java` | 1618-1634 | `createContract2()`:CREATE2 操作码实现 |
90+
| `WalletUtil.java` | 56-59 | `generateContractAddress2()`:hash 计算 |
91+
| `Hash.java` | 194-199 | `sha3omit12()`:hash 后取 [11:31],首字节替换为前缀 |
92+
93+
## 验证
94+
95+
修复后全部 18 个 FreezeTest 测试通过(BUILD SUCCESSFUL)。
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "2"
2+
plugins:
3+
sonar-java:
4+
enabled: true
5+
config:
6+
sonar.java.source: 8
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
./*
2+
!docker-entrypoint.sh
3+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
name: Ask a question
3+
about: Something is unclear
4+
title: ''
5+
labels: 'type:docs'
6+
assignees: ''
7+
8+
---
9+
This should only be used in very rare cases e.g. if you are not 100% sure if something is a bug or asking a question that leads to improving the documentation. For general questions please use [Discord](https://discord.gg/cGKSsRVCGm) or [Telegram](https://t.me/TronOfficialDevelopersGroupEn).
10+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
name: Report a bug
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: 'type:bug'
6+
assignees: ''
7+
8+
---
9+
10+
<!-- Have you done the following? -->
11+
<!-- * Reproduced the issue in the latest version of the software -->
12+
<!-- * Duplicate Issue check: https://github.com/search?q=+is%3Aissue+repo%3Atronprotocol/java-tron -->
13+
14+
#### Software Versions
15+
<!-- `java -jar FullNode.jar -v` -->
16+
17+
<!--
18+
```
19+
OS : Linux
20+
JVM : Oracle Corporation 1.8.0_161 amd64
21+
Git : b1fc2f0f2bd79527099bc3027b9aba165c2e20c2
22+
Version : 4.7.4
23+
Code : 18260
24+
```
25+
-->
26+
27+
#### Expected behaviour
28+
<!--[What you expect to happen] -->
29+
30+
31+
#### Actual behaviour
32+
<!--[What you expect to happen] -->
33+
34+
35+
#### Frequency
36+
<!-- [What percentage of the time does it occur?] -->
37+
38+
#### Steps to reproduce the behaviour
39+
40+
1. [Step 1]
41+
2. [Step 2]
42+
3. [Step ...]
43+
44+
#### Backtrace
45+
46+
````
47+
[backtrace]
48+
````
49+
50+
When submitting logs: please submit them as text and not screenshots.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: Request a feature
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: 'type:feature'
6+
assignees: ''
7+
8+
---
9+
# Background
10+
11+
# Rationale
12+
13+
Why should this feature exist?
14+
15+
What are the use-cases?
16+
17+
# Specification
18+
19+
# Test Specification
20+
21+
# Scope Of Impact
22+
23+
24+
# Implementation
25+
26+
Do you have ideas regarding the implementation of this feature?
27+
28+
Are you willing to implement this feature?
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
**What does this PR do?**
2+
3+
**Why are these changes required?**
4+
5+
**This PR has been tested by:**
6+
- Unit Tests
7+
- Manual Testing
8+
9+
**Follow up**
10+
11+
**Extra details**
12+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ 'develop', 'master', 'release_**' ]
6+
pull_request:
7+
# The branches below must be a subset of the branches above
8+
branches: [ 'develop' ]
9+
schedule:
10+
- cron: '6 10 * * 0'
11+
12+
jobs:
13+
analyze:
14+
name: Analyze
15+
runs-on: ubuntu-latest
16+
permissions:
17+
actions: read
18+
contents: read
19+
security-events: write
20+
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
language: [ 'java' ]
25+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
26+
# Use only 'java' to analyze code written in Java, Kotlin or both
27+
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
28+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
29+
30+
steps:
31+
- name: Checkout repository
32+
uses: actions/checkout@v3
33+
34+
# Initializes the CodeQL tools for scanning.
35+
- name: Initialize CodeQL
36+
uses: github/codeql-action/init@v3
37+
with:
38+
languages: ${{ matrix.language }}
39+
# If you wish to specify custom queries, you can do so here or in a config file.
40+
# By default, queries listed here will override any specified in a config file.
41+
# Prefix the list here with "+" to use these queries and those in the config file.
42+
43+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
44+
# queries: security-extended,security-and-quality
45+
46+
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
47+
# If this step fails, then you should remove it and run the build manually (see below)
48+
- name: Autobuild
49+
uses: github/codeql-action/autobuild@v3
50+
51+
# ℹ️ Command-line programs to run using the OS shell.
52+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
53+
54+
# If the Autobuild fails above, remove it and uncomment the following three lines.
55+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
56+
57+
# - run: |
58+
# echo "Run, Build Application using script"
59+
# ./location_of_script_within_repo/buildscript.sh
60+
61+
- name: Perform CodeQL Analysis
62+
uses: github/codeql-action/analyze@v3
63+
with:
64+
category: "/language:${{matrix.language}}"
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Check Math Usage
2+
3+
on:
4+
push:
5+
branches: [ 'master', 'release_**' ]
6+
pull_request:
7+
branches: [ 'develop', 'release_**' ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
check-math:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Check for java.lang.Math usage
18+
id: check-math
19+
shell: bash
20+
run: |
21+
echo "Checking for java.lang.Math usage..."
22+
23+
touch math_usage.txt
24+
25+
while IFS= read -r file; do
26+
filename=$(basename "$file")
27+
if [[ "$filename" == "StrictMathWrapper.java" || "$filename" == "MathWrapper.java" ]]; then
28+
continue
29+
fi
30+
31+
perl -0777 -ne '
32+
s/"([^"\\]|\\.)*"//g;
33+
s/'\''([^'\''\\]|\\.)*'\''//g;
34+
s!/\*([^*]|\*[^/])*\*/!!g;
35+
s!//[^\n]*!!g;
36+
$hasMath = 0;
37+
$hasMath = 1 if /^[\s]*import[\s]+java\.lang\.Math\b/m;
38+
$hasMath = 1 if /\bjava\s*\.\s*lang\s*\.\s*Math\s*\./;
39+
$hasMath = 1 if /(?<![\w\.])(?<!Strict)Math\s*\./;
40+
print "$ARGV\n" if $hasMath;
41+
' "$file" >> math_usage.txt
42+
done < <(find . -type f -name "*.java")
43+
44+
sort -u math_usage.txt -o math_usage.txt
45+
46+
if [ -s math_usage.txt ]; then
47+
echo "❌ Error: Forbidden Math usage found in the following files:"
48+
cat math_usage.txt
49+
echo "math_found=true" >> $GITHUB_OUTPUT
50+
echo "Please use org.tron.common.math.StrictMathWrapper instead of direct Math usage."
51+
else
52+
echo "✅ No forbidden Math usage found"
53+
echo "math_found=false" >> $GITHUB_OUTPUT
54+
fi
55+
56+
- name: Upload findings
57+
if: steps.check-math.outputs.math_found == 'true'
58+
uses: actions/upload-artifact@v4
59+
with:
60+
name: math-usage-report
61+
path: math_usage.txt
62+
63+
- name: Create comment
64+
if: github.event_name == 'pull_request' && steps.check-math.outputs.math_found == 'true'
65+
uses: actions/github-script@v6
66+
with:
67+
script: |
68+
const fs = require('fs');
69+
const findings = fs.readFileSync('math_usage.txt', 'utf8');
70+
const body = `### ❌ Math Usage Detection Results
71+
72+
Found forbidden usage of \`java.lang.Math\` in the following files:
73+
74+
\`\`\`
75+
${findings}
76+
\`\`\`
77+
78+
**Please review if this usage is intended.**
79+
> [!CAUTION]
80+
> Note: You should use \`org.tron.common.math.StrictMathWrapper\`.
81+
> If you need to use \`java.lang.Math\`, please provide a justification.
82+
`;
83+
84+
await github.rest.issues.createComment({
85+
owner: context.repo.owner,
86+
repo: context.repo.repo,
87+
issue_number: context.issue.number,
88+
body: body
89+
});
90+
91+
- name: Fail if Math usage found
92+
if: steps.check-math.outputs.math_found == 'true'
93+
run: exit 1

0 commit comments

Comments
 (0)