Prevent warp transfers to zero-ish addresses (#3426)
### Description - Prevent warp transfers to zero-ish addresses - Increase address utility test coverage ### Related issues Fixes https://github.com/hyperlane-xyz/hyperlane-monorepo/issues/3421 ### Backward compatibility Yes ### Testing Tested in warp UI and added unit testspull/3427/head
parent
a72c3cf1a5
commit
5daaae274d
@ -0,0 +1,6 @@ |
||||
--- |
||||
'@hyperlane-xyz/utils': patch |
||||
'@hyperlane-xyz/sdk': patch |
||||
--- |
||||
|
||||
Prevent warp transfers to zero-ish addresses |
@ -0,0 +1,63 @@ |
||||
import { expect } from 'chai'; |
||||
|
||||
import { |
||||
addressToBytes, |
||||
bytesToProtocolAddress, |
||||
isZeroishAddress, |
||||
} from './addresses'; |
||||
import { ProtocolType } from './types'; |
||||
|
||||
const ETH_ZERO_ADDR = '0x0000000000000000000000000000000000000000'; |
||||
const ETH_NON_ZERO_ADDR = '0x0000000000000000000000000000000000000001'; |
||||
const COS_ZERO_ADDR = 'cosmos1000'; |
||||
const COS_NON_ZERO_ADDR = |
||||
'neutron1jyyjd3x0jhgswgm6nnctxvzla8ypx50tew3ayxxwkrjfxhvje6kqzvzudq'; |
||||
const SOL_ZERO_ADDR = '111111'; |
||||
const SOL_NON_ZERO_ADDR = 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb'; |
||||
|
||||
// TODO increase address utility test coverage
|
||||
describe('Address utilities', () => { |
||||
describe('isZeroishAddress', () => { |
||||
it('Identifies 0-ish addresses', () => { |
||||
expect(isZeroishAddress('0x')).to.be.true; |
||||
expect(isZeroishAddress(ETH_ZERO_ADDR)).to.be.true; |
||||
expect(isZeroishAddress(COS_ZERO_ADDR)).to.be.true; |
||||
expect(isZeroishAddress(SOL_ZERO_ADDR)).to.be.true; |
||||
}); |
||||
it('Identifies non-0-ish addresses', () => { |
||||
expect(isZeroishAddress(ETH_NON_ZERO_ADDR)).to.be.false; |
||||
expect(isZeroishAddress(COS_NON_ZERO_ADDR)).to.be.false; |
||||
expect(isZeroishAddress(SOL_NON_ZERO_ADDR)).to.be.false; |
||||
}); |
||||
}); |
||||
|
||||
describe('addressToBytes', () => { |
||||
it('Converts addresses to bytes', () => { |
||||
expect(addressToBytes(ETH_NON_ZERO_ADDR).length).to.equal(32); |
||||
}); |
||||
it('Rejects zeroish addresses', () => { |
||||
expect(() => addressToBytes(ETH_ZERO_ADDR)).to.throw(Error); |
||||
expect(() => addressToBytes(COS_ZERO_ADDR)).to.throw(Error); |
||||
expect(() => addressToBytes(SOL_ZERO_ADDR)).to.throw(Error); |
||||
}); |
||||
}); |
||||
|
||||
describe('bytesToProtocolAddress', () => { |
||||
it('Converts bytes to address', () => { |
||||
expect( |
||||
bytesToProtocolAddress( |
||||
addressToBytes(ETH_NON_ZERO_ADDR), |
||||
ProtocolType.Ethereum, |
||||
), |
||||
).to.equal(ETH_NON_ZERO_ADDR); |
||||
}); |
||||
it('Rejects zeroish addresses', () => { |
||||
expect(() => |
||||
bytesToProtocolAddress( |
||||
new Uint8Array([0, 0, 0]), |
||||
ProtocolType.Ethereum, |
||||
), |
||||
).to.throw(Error); |
||||
}); |
||||
}); |
||||
}); |
Loading…
Reference in new issue