Skip to content

Commit

Permalink
fix(utils): fix applyL1ToL2Alias and undoL1ToL2Alias
Browse files Browse the repository at this point in the history
  • Loading branch information
petarTxFusion committed Mar 15, 2024
1 parent 3d57f38 commit 9c6b687
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/java/io/zksync/utils/WalletUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,15 @@ public static BigInteger estimateCustomBridgeDepositL2Gas(String l1BridgeAddress
}

public static String applyL1ToL2Alias(String address){
String a = Numeric.toHexStringWithPrefix(Numeric.toBigInt(address).add(Numeric.toBigInt("0x1111000000000000000000000000000000001111")).mod(BigInteger.valueOf(2).pow(160)));
return Numeric.toHexStringWithPrefix(Numeric.toBigInt(address).add(Numeric.toBigInt("0x1111000000000000000000000000000000001111")).mod(BigInteger.valueOf(2).pow(160)));
return Numeric.toHexStringWithPrefixZeroPadded(Numeric.toBigInt(address).add(Numeric.toBigInt("0x1111000000000000000000000000000000001111")).mod(BigInteger.valueOf(2).pow(160)), 40);
}

public static String undoL1ToL2Alias(String address){
BigInteger result = Numeric.toBigInt(address).subtract(Numeric.toBigInt("0x1111000000000000000000000000000000001111"));
if (result.compareTo(BigInteger.ZERO) < 0){
result.add(BigInteger.valueOf(2).pow(160));
}
return Numeric.toHexStringWithPrefixZeroPadded(result, 40);
}

public static String getERC20DefaultBridgeData(String l1TokenAddress, Web3j provider, Credentials credentials, ContractGasProvider gasProvider){
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/io/zksync/utils/ContractDeployerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ public void computeL2Create2AddressActual() {
Assertions.assertEquals(expected, result.getValue());
}

@Test
public void testApplyAlias(){
String nonZeroPadded = WalletUtils.applyL1ToL2Alias("0x702942B8205E5dEdCD3374E5f4419843adA76Eeb");
Assertions.assertEquals("0x813A42B8205E5DedCd3374e5f4419843ADa77FFC".toLowerCase(), nonZeroPadded.toLowerCase());
}

@Test
public void testUndoAlias(){
String nonZeroPadded = WalletUtils.applyL1ToL2Alias("0x702942B8205E5dEdCD3374E5f4419843adA76Eeb");
Assertions.assertEquals("0x813A42B8205E5DedCd3374e5f4419843ADa77FFC".toLowerCase(), nonZeroPadded.toLowerCase());
}

@Test
public void computeL2CreateAddressActual() {
String expected = "0x5107b7154dfc1d3b7f1c4e19b5087e1d3393bcf4";
Expand Down

0 comments on commit 9c6b687

Please sign in to comment.