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: fix reentrancy #871

Merged
merged 2 commits into from
Aug 5, 2024
Merged
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
5 changes: 5 additions & 0 deletions .github/workflows/java-contracts-test.yml
Original file line number Diff line number Diff line change
@@ -31,6 +31,11 @@ jobs:
uses: actions/checkout@v3
with:
submodules: true
- name: install docker-compose
run: |
sudo curl -L "https://github.com/docker/compose/releases/download/v2.29.0/docker-compose-linux-x86_64" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
- name: Start local Blockchain
run: docker logout public.ecr.aws && cd contracts/javascore/gochain-btp && make run

Original file line number Diff line number Diff line change
@@ -51,6 +51,7 @@ impl<'a> CwIbcCoreContext<'a> {
let next_sequence_recv = Sequence::from(msg.next_sequence_recv);

let mut channel_end = self.get_channel_end(deps.storage, &src_port, &src_channel)?;

let counterparty = Counterparty::new(dst_port.clone(), Some(dst_channel.clone()));
if !channel_end.counterparty_matches(&counterparty) {
return Err(ContractError::IbcPacketError {
@@ -186,6 +187,12 @@ impl<'a> CwIbcCoreContext<'a> {
let timeoutblock = to_ibc_timeout_block(&packet_timeout_height);
let timeout = CwTimeout::with_block(timeoutblock);
let ibc_packet = CwPacket::new(data, src, dest, packet.sequence, timeout);
self.delete_packet_commitment(
deps.storage,
&src_port,
&src_channel,
packet.sequence.into(),
)?;

let address = to_checked_address(deps.as_ref(), &msg.signer);
let cosm_msg = cw_common::xcall_connection_msg::ExecuteMsg::IbcPacketTimeout {
Original file line number Diff line number Diff line change
@@ -55,8 +55,9 @@ public void recvPacket(MsgPacketRecv msg) {
IIBCModule module = lookupModuleByChannel(packet.getDestinationPort(),
packet.getDestinationChannel());

byte[] acknowledgement = module.onRecvPacket(msg.getPacket(), Context.getCaller());

_recvPacket(packet, msg.getProof(), msg.getProofHeight());
byte[] acknowledgement = module.onRecvPacket(msg.getPacket(), Context.getCaller());

if (acknowledgement != null && acknowledgement.length > 0) {
_writeAcknowledgement(
@@ -93,10 +94,9 @@ public void writeAcknowledgement(
public void acknowledgePacket(MsgPacketAcknowledgement msg) {
Packet packet = Packet.decode(msg.getPacket());
IIBCModule module = lookupModuleByChannel(packet.getSourcePort(), packet.getSourceChannel());

module.onAcknowledgementPacket(msg.getPacket(), msg.getAcknowledgement(),
Context.getCaller());
_acknowledgePacket(packet, msg.getAcknowledgement(), msg.getProof(), msg.getProofHeight());
module.onAcknowledgementPacket(msg.getPacket(), msg.getAcknowledgement(),
Context.getCaller());

AcknowledgePacket(msg.getPacket(), msg.getAcknowledgement());
}
@@ -112,9 +112,8 @@ public void requestTimeout(MsgRequestTimeoutPacket msg) {
public void timeoutPacket(MsgPacketTimeout msg) {
Packet packet = Packet.decode(msg.getPacket());
IIBCModule module = lookupModuleByChannel(packet.getSourcePort(), packet.getSourceChannel());
module.onTimeoutPacket(msg.getPacket(), Context.getCaller());
_timeoutPacket(packet, msg.getProofHeight(), msg.getProof(), msg.getNextSequenceRecv());

module.onTimeoutPacket(msg.getPacket(), Context.getCaller());
PacketTimeout(msg.getPacket());
}
}