fix: use EIP 55 checksum address

This commit is contained in:
Wanseob Lim
2020-09-07 04:44:38 +09:00
parent 020468bf20
commit 9508d32f6c
19 changed files with 1123 additions and 2260 deletions

View File

@@ -35,6 +35,7 @@
"bip39": "^3.0.2",
"circomlib": "^0.1.1",
"hdkey": "^1.1.1",
"keccak": "^3.0.1",
"web3": "^1.2.6",
"web3-core": "^1.2.6",
"web3-eth-accounts": "^1.2.6"

View File

@@ -43,7 +43,7 @@ export class ZkAccount {
this.ethAccount = pk
}
this.pG = Point.fromPrivKey(this.p.toHex(32))
this.ethAddress = this.ethAccount.address.toLowerCase()
this.ethAddress = this.ethAccount.address
// https://github.com/zkopru-network/zkopru/issues/34#issuecomment-666988505
// Note: viewing key can be derived using another method. This is just for the convenience
// to make it easy to restore spending key & viewing key together from a mnemonic source in

View File

@@ -39,7 +39,7 @@ describe('unit test', () => {
'0xACa94ef8bD5ffEE41947b4585a84BdA5a3d3DA6E',
'0x1dF62f291b2E969fB0849d99D9Ce41e2F137006e',
]
expect(ganacheAddress.map(a => a.toLowerCase())).toStrictEqual(
expect(ganacheAddress).toStrictEqual(
accounts.map(account => account.ethAddress),
)
}, 30000)

View File

@@ -32,7 +32,7 @@
"bn.js": "^5.1.1",
"circomlib": "^0.1.1",
"ffjavascript": "^0.1.2",
"soltypes": "^1.2.2",
"soltypes": "^1.3.3",
"web3-utils": "^1.2.6"
},
"publishConfig": {

View File

@@ -52,7 +52,7 @@
"node-ansiparser": "^2.2.0",
"node-ansiterminal": "^0.2.1-beta",
"node-fetch": "^2.6.0",
"soltypes": "^1.2.2",
"soltypes": "^1.3.3",
"tar": "^6.0.2",
"web3": "^1.2.6",
"web3-core": "^1.2.6",

View File

@@ -17,7 +17,7 @@
"@openzeppelin/contracts": "3.0.1",
"bn.js": "^5.1.1",
"ethereumjs-tx": "1.3.7",
"soltypes": "^1.2.2",
"soltypes": "^1.3.3",
"web3": "^1.2.6",
"web3-core": "^1.2.6",
"web3-eth-contract": "^1.2.6"

View File

@@ -53,7 +53,7 @@
"node-schedule": "^1.3.2",
"prompts": "^2.3.2",
"snarkjs": "^0.1.25",
"soltypes": "^1.2.2",
"soltypes": "^1.3.3",
"web3": "^1.2.6",
"web3-core": "^1.2.6",
"web3-core-subscriptions": "^1.2.6",

View File

@@ -45,7 +45,7 @@
"node-fetch": "^2.6.0",
"node-schedule": "^1.3.2",
"snarkjs": "^0.1.27",
"soltypes": "^1.2.2",
"soltypes": "^1.3.3",
"web3": "^1.2.6",
"web3-core": "^1.2.6",
"web3-eth-contract": "^1.2.6",

View File

@@ -354,29 +354,15 @@ export class L2Chain {
)
logger.debug(
`withdrawal address =>
${outflows.map(outflow =>
outflow.data?.to
.toAddress()
.toString()
.toLowerCase(),
)}`,
)
logger.debug(
`my address =>${accounts.map(account =>
account.ethAddress.toLowerCase(),
)}`,
${outflows.map(outflow => outflow.data?.to.toAddress().toString())}`,
)
logger.debug(`my address =>${accounts.map(account => account.ethAddress)}`)
const myWithdrawalOutputs: ZkOutflow[] = outflows.filter(
outflow =>
outflow.data &&
accounts
.map(account => account.ethAddress.toLowerCase())
.includes(
outflow.data?.to
.toAddress()
.toString()
.toLowerCase(),
),
.map(account => account.ethAddress)
.includes(outflow.data?.to.toAddress().toString()),
)
// TODO needs batch transaction
for (const output of myWithdrawalOutputs) {

View File

@@ -41,7 +41,8 @@
"big-integer": "^1.6.48",
"fs-extra": "^9.0.0",
"node-docker-api": "^1.1.22",
"soltypes": "^1.2.2",
"soltypes": "^1.3.3",
"keccak": "^3.0.1",
"tar": "^6.0.2",
"web3": "^1.2.6",
"web3-core": "^1.2.7",

View File

@@ -39,7 +39,7 @@
"@zkopru/transaction": "file:../transaction",
"@zkopru/utils": "file:../utils",
"@zkopru/zk-wizard": "file:../zk-wizard",
"soltypes": "^1.2.2",
"soltypes": "^1.3.3",
"node-docker-api": "^1.1.22",
"puppeteer": "^5.0.0",
"web3": "^1.2.7",

View File

@@ -174,9 +174,7 @@ export const testNewSpendableUtxos = (ctx: CtxProvider) => async () => {
console.log(aliceBalance)
console.log(tokens.erc721.address)
expect(
aliceBalance.erc721[tokens.erc721.address.toLowerCase()].find(nft =>
nft.eqn(1),
),
aliceBalance.erc721[tokens.erc721.address].find(nft => nft.eqn(1)),
).toBeDefined()
expect(
carlBalance.erc20[tokens.erc20.address].eq(toBN(toWei('1', 'ether'))),

View File

@@ -35,7 +35,7 @@
"chacha20": "^0.1.4",
"circomlib": "^0.1.1",
"snarkjs": "^0.1.25",
"soltypes": "^1.2.2",
"soltypes": "^1.3.3",
"web3-utils": "^1.2.6"
},
"publishConfig": {

View File

@@ -20,14 +20,16 @@ export class Sum {
}
getERC20(address: Address | string): Field {
const addr = typeof address === 'string' ? Address.from(address) : address
const amount = this.erc20[addr.toString().toLowerCase()] || Field.zero
const addr: Address =
typeof address === 'string' ? Address.from(address) : address
const amount = this.erc20[addr.toString()] || Field.zero
return amount
}
getNFTs(address: Address | string): Field[] {
const addr = typeof address === 'string' ? Address.from(address) : address
const nfts = this.erc721[addr.toString().toLowerCase()] || []
const addr: Address =
typeof address === 'string' ? Address.from(address) : address
const nfts = this.erc721[addr.toString()] || []
return nfts
}
@@ -42,7 +44,7 @@ export class Sum {
static erc20From(notes: Note[]): { [addr: string]: Field } {
const erc20: { [addr: string]: Field } = {}
for (const note of notes) {
const addr = note.asset.tokenAddr.toHex().toLowerCase()
const addr = Address.from(note.asset.tokenAddr.toHex()).toString()
if (!note.asset.erc20Amount.isZero() && note.asset.nft.isZero()) {
const prev = erc20[addr] ? erc20[addr] : Field.from(0)
erc20[addr] = prev.add(note.asset.erc20Amount)
@@ -54,7 +56,7 @@ export class Sum {
static nftsFrom(notes: Note[]): { [addr: string]: Field[] } {
const erc721: { [addr: string]: Field[] } = {}
for (const note of notes) {
const addr = note.asset.tokenAddr.toHex().toLowerCase()
const addr = Address.from(note.asset.tokenAddr.toHex()).toString()
if (note.asset.erc20Amount.isZero() && !note.asset.nft.isZero()) {
if (!erc721[addr]) {
erc721[addr] = []

View File

@@ -2,6 +2,7 @@ import { Field, F } from '@zkopru/babyjubjub'
import { txSizeCalculator, logger } from '@zkopru/utils'
import { fromWei } from 'web3-utils'
import assert from 'assert'
import { Address } from 'soltypes'
import { ZkAddress } from './zk-address'
import { Utxo } from './utxo'
import { Sum } from './note-sum'
@@ -156,7 +157,12 @@ export class TxBuilder {
Object.keys(sendingAmount.erc20).forEach(addr => {
const targetAmount: Field = sendingAmount.getERC20(addr)
const sameERC20UTXOs: Utxo[] = this.spendables
.filter(utxo => utxo.tokenAddr().toHex() === addr)
.filter(utxo =>
utxo
.tokenAddr()
.toAddress()
.eq(Address.from(addr)),
)
.sort((a, b) => (a.erc20Amount().gt(b.erc20Amount()) ? 1 : -1))
for (const utxo of sameERC20UTXOs) {
if (targetAmount.gt(Sum.from(spendings).getERC20(addr))) {
@@ -177,7 +183,10 @@ export class TxBuilder {
.sort((a, b) => (a.gt(b) ? 1 : -1))
const spendingNFTNotes: Utxo[] = this.spendables.filter(utxo => {
return (
utxo.tokenAddr().toHex() === addr &&
utxo
.tokenAddr()
.toAddress()
.eq(Address.from(addr)) &&
sendingNFTs.find(nft => nft.eq(utxo.nft())) !== undefined
)
})

View File

@@ -37,7 +37,7 @@
"big-integer": "^1.6.48",
"bn.js": "^5.1.1",
"circomlib": "^0.1.1",
"soltypes": "^1.2.2",
"soltypes": "^1.3.3",
"uuid": "^8.1.0",
"web3-utils": "^1.2.6"
},

View File

@@ -37,7 +37,7 @@
"pino-pretty": "^4.0.0",
"prompts": "^2.3.2",
"snarkjs": "^0.1.25",
"soltypes": "^1.2.2",
"soltypes": "^1.3.3",
"tar": "^6.0.2",
"web3-utils": "^1.2.6"
},

View File

@@ -39,7 +39,7 @@
"ffjavascript": "^0.1.2",
"fs-extra": "^9.0.0",
"node-fetch": "^2.6.0",
"soltypes": "^1.2.2",
"soltypes": "^1.3.3",
"wasmsnark": "^0.0.10",
"web3": "^1.2.6",
"web3-core": "^1.2.6",

3302
yarn.lock

File diff suppressed because it is too large Load Diff