Skip to content

Commit

Permalink
fix: fix reentrancy (#871)
Browse files Browse the repository at this point in the history
* fix: fix reentrancy

* Update java-contracts-test.yml

Install docker-compose

---------

Co-authored-by: DeepakBomjan <[email protected]>
  • Loading branch information
ibrizsabin and DeepakBomjan authored Aug 5, 2024
1 parent c277c32 commit 987dcee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/java-contracts-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}
}

0 comments on commit 987dcee

Please sign in to comment.