Skip to content

Conversation

imloama
Copy link

@imloama imloama commented Jun 4, 2025

在生成随机地址时,出现公钥补0,导致生成的地址和java端不一致。从而操作资产时,出现错误。
如私钥地址:0xcb2703a0030898e676e4bacaa1d0d1f12ad6a4db3a3eb1e65e4d4710e31bdb02
go sdk生成地址:0x46a9bc34c51ad531079f7ba0c6f0e4c6b6ed85df
java sdk生成地址:0xa8c9f1fe39d16a54fe1745bbd762d837e8330620
修改后,生成一致

@imloama imloama changed the title bugfix: sm2处理公钥时,补0在x和y中间补0,与java算法中,在最新边补0不一致,导致生成地址不一致 bugfix: sm2生成address时,go sdk与java sdk生成结果不一致。 Jun 4, 2025
@bxq2011hust bxq2011hust requested a review from Copilot June 13, 2025 01:30
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an inconsistency in address generation between the Go and Java SDKs by ensuring that the public key’s X and Y coordinates are zero-padded to a fixed length.

  • Added padding logic for X coordinate
  • Added padding logic for Y coordinate

copy(pubBytes[publicKeyLength/2:], pub.Y.Bytes())
// 确保X坐标长度固定,不足时在前端补0
xBytes := pub.X.Bytes()
copy(pubBytes[:publicKeyLength/2-(len(xBytes))], make([]byte, publicKeyLength/2-len(xBytes)))
Copy link

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The padding logic for both X and Y coordinates is similar. Consider extracting this repeated logic into a helper function to enhance maintainability.

Copilot uses AI. Check for mistakes.

@bxq2011hust
Copy link
Member

谢谢你的贡献,能否请您添加一个单元测试,验证这个问题?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants