Skip to content

Commit

Permalink
fix: replace short address with bech32m full address in test cases (#511
Browse files Browse the repository at this point in the history
)
  • Loading branch information
fjchen7 authored Dec 1, 2021
1 parent 8662c80 commit e9daff6
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 45 deletions.
20 changes: 13 additions & 7 deletions ckb-api/src/test/java/constant/AddressWithKeyHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,36 @@ public class AddressWithKeyHolder {
private static Map<String, String> addressWithPubKey = new HashMap<>(8);

//// 0xa3b8598e1d53e6c5e89e8acb6b4c34d3adb13f2b
private static String TEST_ADDRESS0 = "ckt1qyq28wze3cw48ek9az0g4jmtfs6d8td38u4s6hp2s0";
private static String TEST_ADDRESS0 =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqdrhpvcu82numz73852ed45cdxn4kcn72cr4338a";
private static String TEST_PUBKEY0 = "0xa3b8598e1d53e6c5e89e8acb6b4c34d3adb13f2b";

//// 0xaf0b41c627807fbddcee75afa174d5a7e5135ebd
private static String TEST_ADDRESS1 = "ckt1qyq27z6pccncqlaamnh8ttapwn260egnt67ss2cwvz";
private static String TEST_ADDRESS1 =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqd0pdquvfuq077aemn447shf4d8u5f4a0glzz2g4";
private static String TEST_PUBKEY1 = "0xaf0b41c627807fbddcee75afa174d5a7e5135ebd";

//// 0x05a1fabfa84db9e538e2e7fe3ca9adf849f55ce0
private static String TEST_ADDRESS2 = "ckt1qyqqtg06h75ymw098r3w0l3u4xklsj04tnsqctqrmc";
private static String TEST_ADDRESS2 =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg958atl2zdh8jn3ch8lc72nt0cf864ecqdxm9zf";
private static String TEST_PUBKEY2 = "0x05a1fabfa84db9e538e2e7fe3ca9adf849f55ce0";

//// 0x202647fecc5b9d8cbdb4ae7167e40f5ab1e4baaf
private static String TEST_ADDRESS3 = "ckt1qyqzqfj8lmx9h8vvhk62uut8us844v0yh2hsnqvvgc";
private static String TEST_ADDRESS3 =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqfqyerlanzmnkxtmd9ww9n7gr66k8jt4tclm9jnk";
private static String TEST_PUBKEY3 = "0x202647fecc5b9d8cbdb4ae7167e40f5ab1e4baaf";

//// 0x839f1806e85b40c13d3c73866045476cc9a8c214
private static String TEST_ADDRESS4 = "ckt1qyqg88ccqm59ksxp85788pnqg4rkejdgcg2qxcu2qf";
private static String TEST_ADDRESS4 =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqvrnuvqd6zmgrqn60rnsesy23mvex5vy9q0g8hfd";
private static String TEST_PUBKEY4 = "0x839f1806e85b40c13d3c73866045476cc9a8c214";

private static String CEX_ADDRESS = "ckt1qyqz50qxup4cw2dvg0exg8y9m5e90dykuh6q72rj0h";
private static String CEX_ADDRESS =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqf28srwq6u89xky8unyrjza6vjhkjtwtaqm5z887";
private static String CEX_PUBKEY = "0x2a3c06e06b8729ac43f2641c85dd3257b496e5f4";

private static String QUERY_TRANSACTION_ADDRESS =
"ckt1qyqp5nlkxkvwgwhee4pryj4mwetl4pyut0psq2h92t";
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg6flmrtx8y8tuu6s3jf2ahv4l6sjw9hsc3t4tqv";
private static String QUERY_TRANSACTION_PUBKEY = "0x1a4ff63598e43af9cd42324abb7657fa849c5bc3";

static {
Expand Down
4 changes: 3 additions & 1 deletion ckb-api/src/test/java/org/nervos/api/CkbApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ private void mercuryApi(MercuryApi api) {
try {

GetBalancePayloadBuilder builder = new GetBalancePayloadBuilder();
builder.item(ItemFactory.newAddressItem("ckt1qyq28wze3cw48ek9az0g4jmtfs6d8td38u4s6hp2s0"));
builder.item(
ItemFactory.newAddressItem(
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqdrhpvcu82numz73852ed45cdxn4kcn72cr4338a"));

System.out.println(g.toJson(builder.build()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ void testQueryTransactionsCellbase() {

try {

String minerAddress = "ckt1qyqd5eyygtdmwdr7ge736zw6z0ju6wsw7rssu8fcve";
String minerAddress =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqw6vjzy9kahx3lyvlgap8dp8ewd8g80pcgcexzrj";
QueryTransactionsPayloadBuilder builder = new QueryTransactionsPayloadBuilder();
builder.item(ItemFactory.newAddressItem(minerAddress));
builder.addAssetInfo(AssetInfo.newCkbAsset());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,36 @@ public class AddressWithKeyHolder {
private static Map<String, String> addressWithPubKey = new HashMap<>(8);

//// 0xa3b8598e1d53e6c5e89e8acb6b4c34d3adb13f2b
private static String TEST_ADDRESS0 = "ckt1qyq28wze3cw48ek9az0g4jmtfs6d8td38u4s6hp2s0";
private static String TEST_ADDRESS0 =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqdrhpvcu82numz73852ed45cdxn4kcn72cr4338a";
private static String TEST_PUBKEY0 = "0xa3b8598e1d53e6c5e89e8acb6b4c34d3adb13f2b";

//// 0xaf0b41c627807fbddcee75afa174d5a7e5135ebd
private static String TEST_ADDRESS1 = "ckt1qyq27z6pccncqlaamnh8ttapwn260egnt67ss2cwvz";
private static String TEST_ADDRESS1 =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqd0pdquvfuq077aemn447shf4d8u5f4a0glzz2g4";
private static String TEST_PUBKEY1 = "0xaf0b41c627807fbddcee75afa174d5a7e5135ebd";

//// 0x05a1fabfa84db9e538e2e7fe3ca9adf849f55ce0
private static String TEST_ADDRESS2 = "ckt1qyqqtg06h75ymw098r3w0l3u4xklsj04tnsqctqrmc";
private static String TEST_ADDRESS2 =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg958atl2zdh8jn3ch8lc72nt0cf864ecqdxm9zf";
private static String TEST_PUBKEY2 = "0x05a1fabfa84db9e538e2e7fe3ca9adf849f55ce0";

//// 0x202647fecc5b9d8cbdb4ae7167e40f5ab1e4baaf
private static String TEST_ADDRESS3 = "ckt1qyqzqfj8lmx9h8vvhk62uut8us844v0yh2hsnqvvgc";
private static String TEST_ADDRESS3 =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqfqyerlanzmnkxtmd9ww9n7gr66k8jt4tclm9jnk";
private static String TEST_PUBKEY3 = "0x202647fecc5b9d8cbdb4ae7167e40f5ab1e4baaf";

//// 0x839f1806e85b40c13d3c73866045476cc9a8c214
private static String TEST_ADDRESS4 = "ckt1qyqg88ccqm59ksxp85788pnqg4rkejdgcg2qxcu2qf";
private static String TEST_ADDRESS4 =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqvrnuvqd6zmgrqn60rnsesy23mvex5vy9q0g8hfd";
private static String TEST_PUBKEY4 = "0x839f1806e85b40c13d3c73866045476cc9a8c214";

private static String CEX_ADDRESS = "ckt1qyqz50qxup4cw2dvg0exg8y9m5e90dykuh6q72rj0h";
private static String CEX_ADDRESS =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqf28srwq6u89xky8unyrjza6vjhkjtwtaqm5z887";
private static String CEX_PUBKEY = "0x2a3c06e06b8729ac43f2641c85dd3257b496e5f4";

private static String QUERY_TRANSACTION_ADDRESS =
"ckt1qyqp5nlkxkvwgwhee4pryj4mwetl4pyut0psq2h92t";
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg6flmrtx8y8tuu6s3jf2ahv4l6sjw9hsc3t4tqv";
private static String QUERY_TRANSACTION_PUBKEY = "0x1a4ff63598e43af9cd42324abb7657fa849c5bc3";

static {
Expand Down
3 changes: 2 additions & 1 deletion ckb/src/test/java/transaction/LockUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public void testGenerateLockScriptWithPrivateKey() {
@Test
public void testGenerateLockScriptWithAddress() {
Script lock =
LockUtils.generateLockScriptWithAddress("ckt1qyqrdsefa43s6m882pcj53m4gdnj4k440axqswmu83");
LockUtils.generateLockScriptWithAddress(
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqdrhpvcu82numz73852ed45cdxn4kcn72cr4338a");
Assertions.assertEquals(
"0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", lock.codeHash);
Assertions.assertEquals("0x36c329ed630d6ce750712a477543672adab57f4c", lock.args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ public static String generate(Network network, Script script) {
}

/**
* Short address format is deprecated because it is limited (only supports secp256k1_blake160, secp256k1_multisig, anyone_can_pay)
* and a flaw has been found in its encoding method bech32, which could enable attackers to generate valid but unexpected addresses.
* For more please check https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md
* Short address format is deprecated because it is limited (only supports secp256k1_blake160,
* secp256k1_multisig, anyone_can_pay) and a flaw has been found in its encoding method bech32,
* which could enable attackers to generate valid but unexpected addresses. For more please check
* https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md
*/
@Deprecated
public static String generateShortAddress(Network network, Script script) {
Expand Down Expand Up @@ -65,9 +66,10 @@ public static String generateShortAddress(Network network, Script script) {
}

/**
* Old full address format is deprecated because a flaw has been found in its encoding method bech32, which could enable
* attackers to generate valid but unexpected addresses.
* For more please check https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md
* Old full address format is deprecated because a flaw has been found in its encoding method
* bech32, which could enable attackers to generate valid but unexpected addresses. For more
* please check
* https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md
*/
@Deprecated
public static String generateFullAddress(Network network, Script script) {
Expand All @@ -80,7 +82,6 @@ public static String generateFullAddress(Network network, Script script) {
prefix(network), convertBits(com.google.common.primitives.Bytes.asList(data), 8, 5, true));
}


public static String generateBech32mFullAddress(Network network, Script script) {
// Payload: type(00) | code hash | hash type | args

Expand Down
27 changes: 15 additions & 12 deletions core/src/main/java/org/nervos/ckb/utils/address/AddressTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ public static AddressGenerateResult generateAddress(Network network)
}

/**
* Short address format is deprecated because it is limited (only support secp256k1_blake160, secp256k1_multisig, anyone_can_pay)
* and a flaw has been found in its encoding method bech32, which could enable attackers to generate valid but unexpected addresses.
* For more please check https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md
* Short address format is deprecated because it is limited (only support secp256k1_blake160,
* secp256k1_multisig, anyone_can_pay) and a flaw has been found in its encoding method bech32,
* which could enable attackers to generate valid but unexpected addresses. For more please check
* https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md
*/
@Deprecated
public static AddressGenerateResult generateShortAddress(Network network)
Expand All @@ -55,9 +56,10 @@ public static AddressGenerateResult generateShortAddress(Network network)
}

/**
* Old full address format is deprecated because a flaw has been found in its encoding method bech32, which could enable
* attackers to generate valid but unexpected addresses.
* For more please check https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md
* Old full address format is deprecated because a flaw has been found in its encoding method
* bech32, which could enable attackers to generate valid but unexpected addresses. For more
* please check
* https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md
*/
@Deprecated
public static AddressGenerateResult generateFullAddress(Network network)
Expand Down Expand Up @@ -100,9 +102,10 @@ public static String convertPublicKeyToAddress(Network network, String publicKey
}

/**
* Short address format deprecated because it is limited (only support secp256k1_blake160, secp256k1_multisig, anyone_can_pay)
* and a flaw has been found in its encoding method bech32, which could enable attackers to generate valid but unexpected addresses.
* For more please check https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md
* Short address format deprecated because it is limited (only support secp256k1_blake160,
* secp256k1_multisig, anyone_can_pay) and a flaw has been found in its encoding method bech32,
* which could enable attackers to generate valid but unexpected addresses. For more please check
* https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md
*/
@Deprecated
public static String convertPublicKeyToShortAddress(Network network, String publicKey) {
Expand All @@ -115,9 +118,9 @@ public static String convertPublicKeyToShortAddress(Network network, String publ
}

/**
* Old full address format deprecated because a flaw has been found in its encoding method bech32, which could enable
* attackers to generate valid but unexpected addresses.
* For more please check https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md
* Old full address format deprecated because a flaw has been found in its encoding method bech32,
* which could enable attackers to generate valid but unexpected addresses. For more please check
* https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md
*/
@Deprecated
public static String convertPublicKeyToFullAddress(Network network, String publicKey) {
Expand Down
15 changes: 10 additions & 5 deletions core/src/test/java/utils/AddressToolsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ void testConvertPublicKeyToAddress() {
@Test
void testGenerateAcpAddress() {
String expected = "ckt1qypqtg06h75ymw098r3w0l3u4xklsj04tnsqkm65q6";
String address = "ckt1qyqqtg06h75ymw098r3w0l3u4xklsj04tnsqctqrmc";
String address =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg958atl2zdh8jn3ch8lc72nt0cf864ecqdxm9zf";

String actual = AddressTools.generateAcpAddress(address);

Expand All @@ -108,8 +109,10 @@ void testGenerateAcpAddress() {
void testGenerateChequeAddress() {
String expected =
"ckt1qpsdtuu7lnjqn3v8ew02xkwwlh4dv5x2z28shkwt8p2nfruccux4kq2je6sm0zczgrepc8y547zvuu6zpshfvvjh7h2ln2w035d2lnh32ylk5ydmjq5ypwq24ftzt";
String senderAddress = "ckt1qyq27z6pccncqlaamnh8ttapwn260egnt67ss2cwvz";
String receiverAddress = "ckt1qyqqtg06h75ymw098r3w0l3u4xklsj04tnsqctqrmc";
String senderAddress =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqd0pdquvfuq077aemn447shf4d8u5f4a0glzz2g4";
String receiverAddress =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg958atl2zdh8jn3ch8lc72nt0cf864ecqdxm9zf";

String actual = AddressTools.generateChequeAddress(senderAddress, receiverAddress);

Expand All @@ -118,14 +121,16 @@ void testGenerateChequeAddress() {

@Test
void testParseAddress() {
String address = "ckt1qyqqtg06h75ymw098r3w0l3u4xklsj04tnsqctqrmc";
String address =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg958atl2zdh8jn3ch8lc72nt0cf864ecqdxm9zf";
AddressParseResult script = AddressTools.parse(address);
System.out.println(new Gson().toJson(script));
}

@Test
void testParseNetwork() {
String address = "ckt1qyqqtg06h75ymw098r3w0l3u4xklsj04tnsqctqrmc";
String address =
"ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqg958atl2zdh8jn3ch8lc72nt0cf864ecqdxm9zf";
Assertions.assertEquals(Network.TESTNET, AddressTools.parseNetwork(address));
}
}
8 changes: 4 additions & 4 deletions utils/src/main/java/org/nervos/ckb/address/AddressUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
* and [Common Address Format](https://github.com/nervosnetwork/ckb/wiki/Common-Address-Format).
* Currently we implement the predefined format for type 0x01 and code hash index 0x00.
*
* Deprecated:
* Short address and old full address format are deprecated because a flaw has been found in its encoding method bech32, which could enable
* attackers to generate valid but unexpected addresses.
* For more please check https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md
* <p>Deprecated: Short address and old full address format are deprecated because a flaw has been
* found in its encoding method bech32, which could enable attackers to generate valid but
* unexpected addresses. For more information please check
* https://github.com/nervosnetwork/rfcs/blob/master/rfcs/0021-ckb-address-format/0021-ckb-address-format.md
*/
@Deprecated
public class AddressUtils {
Expand Down

0 comments on commit e9daff6

Please sign in to comment.