Skip to content

Commit de057ba

Browse files
committed
test that endpoint cannot be called directly by a third party
1 parent 8b99a54 commit de057ba

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/crosschain/ERC7802Bridge.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const { ethers } = require('hardhat');
22
const { expect } = require('chai');
33
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
44

5+
const { impersonate } = require('@openzeppelin/contracts/test/helpers/account');
6+
57
const AxelarHelper = require('./axelar/AxelarHelper');
68

79
const buildBridgeHash = (...chains) => {
@@ -153,4 +155,29 @@ describe('ERC7802Bridge', function () {
153155
await expect(this.tokenA.balanceOf(this.endpointA)).to.eventually.equal(0n);
154156
await expect(this.tokenA.balanceOf(this.endpointB)).to.eventually.equal(0n);
155157
});
158+
159+
it('cannot call endpoint directly to mint tokens', async function () {
160+
const [receiver, malicious] = this.accounts;
161+
const value = 1_000_000_000n;
162+
163+
// Deploy endpoint (that is whitelisted by tokenB)
164+
await this.bridgeB.getBridgeEndpoint(this.id);
165+
166+
const tx = {
167+
to: this.endpointB,
168+
data: ethers.concat([
169+
this.tokenB.target,
170+
this.tokenB.interface.encodeFunctionData('crosschainMint', [receiver.address, value]),
171+
]),
172+
};
173+
174+
// The bridge is able to make that call
175+
const bridgeAsWallet = await impersonate(this.bridgeB.target);
176+
await expect(bridgeAsWallet.sendTransaction(tx))
177+
.to.emit(this.tokenB, 'Transfer')
178+
.withArgs(ethers.ZeroAddress, receiver, value);
179+
180+
// An malicious user cannot
181+
await expect(malicious.sendTransaction(tx)).to.be.revertedWithoutReason();
182+
});
156183
});

0 commit comments

Comments
 (0)