Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(utils): fix applyL1ToL2Alias and undoL1ToL2Alias #31

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading