Skip to content

Commit e5538f8

Browse files
authored
Merge pull request cardano-foundation#253 from cardano-foundation/fix/ID-504-Other-Escrow-Token-Compromised
Fix/id 504 other escrow token compromised
2 parents 17c6730 + e43b9d5 commit e5538f8

File tree

18 files changed

+101
-56
lines changed

18 files changed

+101
-56
lines changed

cardano/gateway/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ OGMIOS_ENDPOINT=http://127.0.0.1:1337
1212
CARDANO_CHAIN_HOST=127.0.0.1
1313
CARDANO_CHAIN_PORT=3001
1414
CARDANO_NETWORK_MAGIC=42
15-
CARDANO_EPOCH_NONCE_GENESIS="5a9f8426ad4079263b88c45c84079a2ccbd3e7d4218166404dababe07f69fdad"
15+
CARDANO_EPOCH_NONCE_GENESIS="41c48395859c96d1a431ee848a4d2795f65a4ab19ca37ceeb4d13824792f1fa5"
1616

1717
HANDLER_JSON_PATH=/usr/src/app/cardano/offchain/deployments/handler.json
1818

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export const MinimumActiveEpoch = BigInt(2);
2+
3+
export const TRANSACTION_TIME_TO_LIVE = 20_000; // 20 seconds

cardano/gateway/src/tx/channel.service.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import {
6464
import { ORDER_MAPPING_CHANNEL } from '~@/constant/channel';
6565
import { Order } from '~@/shared/types/channel/order';
6666
import { sleep } from '../shared/helpers/time';
67+
import { TRANSACTION_TIME_TO_LIVE } from '~@/config/constant.config';
6768

6869
@Injectable()
6970
export class ChannelService {
@@ -82,7 +83,7 @@ export class ChannelService {
8283
channelOpenInitOperator,
8384
constructedAddress,
8485
);
85-
const validToTime = Date.now() + 3 * 1e5;
86+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
8687
const validToSlot = unixTimeToSlot(this.lucidService.lucid.config().network, Number(validToTime));
8788
const currentSlot = this.lucidService.lucid.currentSlot();
8889
if (currentSlot > validToSlot) {
@@ -126,7 +127,8 @@ export class ChannelService {
126127
channelOpenTryOperator,
127128
constructedAddress,
128129
);
129-
const unsignedChannelOpenTryTxValidTo: TxBuilder = unsignedChannelOpenTryTx.validTo(Date.now() + 300 * 1e3);
130+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
131+
const unsignedChannelOpenTryTxValidTo: TxBuilder = unsignedChannelOpenTryTx.validTo(validToTime);
130132
// TODO: signing should be done by the relayer in the future
131133
const signedChannelOpenTryTxCompleted = await (await unsignedChannelOpenTryTxValidTo.complete()).sign
132134
.withWallet()
@@ -159,7 +161,7 @@ export class ChannelService {
159161
channelOpenAckOperator,
160162
constructedAddress,
161163
);
162-
const validToTime = Date.now() + 3 * 1e5;
164+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
163165
const validToSlot = unixTimeToSlot(this.lucidService.lucid.config().network, Number(validToTime));
164166
const currentSlot = this.lucidService.lucid.currentSlot();
165167
if (currentSlot > validToSlot) {
@@ -200,9 +202,8 @@ export class ChannelService {
200202
channelOpenConfirmOperator,
201203
constructedAddress,
202204
);
203-
const unsignedChannelConfirmInitTxValidTo: TxBuilder = unsignedChannelConfirmInitTx.validTo(
204-
Date.now() + 600 * 1e3,
205-
);
205+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
206+
const unsignedChannelConfirmInitTxValidTo: TxBuilder = unsignedChannelConfirmInitTx.validTo(validToTime);
206207

207208
// TODO: signing should be done by the relayer in the future
208209
const signedChannelConfirmInitTxCompleted = await (await unsignedChannelConfirmInitTxValidTo.complete()).sign
@@ -243,7 +244,8 @@ export class ChannelService {
243244
channelCloseInitOperator,
244245
constructedAddress,
245246
);
246-
const unsignedChannelCloseInitTxValidTo: TxBuilder = unsignedChannelCloseInitTx.validTo(Date.now() + 300 * 1e3);
247+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
248+
const unsignedChannelCloseInitTxValidTo: TxBuilder = unsignedChannelCloseInitTx.validTo(validToTime);
247249

248250
// TODO: signing should be done by the relayer in the future
249251
const signedChannelCloseInitTxCompleted = await (await unsignedChannelCloseInitTxValidTo.complete()).sign

cardano/gateway/src/tx/client.service.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
import { checkForMisbehaviour } from '@shared/types/misbehaviour/misbehaviour';
3232
import { UpdateOnMisbehaviourOperatorDto, UpdateClientOperatorDto } from './dto/client/update-client-operator.dto';
3333
import { validateAndFormatCreateClientParams, validateAndFormatUpdateClientParams } from './helper/client.validate';
34+
import { TRANSACTION_TIME_TO_LIVE } from '~@/config/constant.config';
3435

3536
@Injectable()
3637
export class ClientService {
@@ -121,9 +122,10 @@ export class ClientService {
121122

122123
const unsignedUpdateClientTx: TxBuilder =
123124
await this.buildUnsignedUpdateOnMisbehaviour(updateOnMisbehaviourOperator);
125+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
124126
const unSignedTxValidTo: TxBuilder = unsignedUpdateClientTx
125127
.validFrom(new Date().valueOf())
126-
.validTo(new Date().valueOf());
128+
.validTo(validToTime);
127129
// Todo: signing should be done by the relayer in the future
128130
const signedUpdateClientTxCompleted = await (await unSignedTxValidTo.complete()).sign.withWallet().complete();
129131

@@ -145,7 +147,7 @@ export class ClientService {
145147
BigInt(currentClientDatum.state.clientState.maxClockDrift || 0)) /
146148
10n ** 6n +
147149
100n * 10n ** 3n;
148-
const validToTime = new Date().valueOf() + 100 * 1e3;
150+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
149151
const updateClientHeaderOperator: UpdateClientOperatorDto = {
150152
clientId,
151153
header,
@@ -166,7 +168,7 @@ export class ClientService {
166168
}
167169

168170
const validFrom = Number(validFromTime);
169-
const validTo = new Date().valueOf() + 100 * 1e3;
171+
const validTo = Date.now() + TRANSACTION_TIME_TO_LIVE;
170172

171173
const unSignedTxValidTo: TxBuilder = unsignedUpdateClientTx.validFrom(validFrom).validTo(validTo);
172174

cardano/gateway/src/tx/connection.service.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { ClientState as CardanoClientState } from '@plus/proto-types/build/ibc/l
4747
import { Any } from '@plus/proto-types/build/google/protobuf/any';
4848
import { getMithrilClientStateForVerifyProofRedeemer } from '../shared/helpers/mithril-client';
4949
import { ClientState as MithrilClientState } from '@plus/proto-types/build/ibc/lightclients/mithril/mithril';
50+
import { TRANSACTION_TIME_TO_LIVE } from '~@/config/constant.config';
5051
@Injectable()
5152
export class ConnectionService {
5253
constructor(
@@ -68,9 +69,8 @@ export class ConnectionService {
6869
connectionOpenInitOperator,
6970
constructedAddress,
7071
);
71-
const unsignedConnectionOpenInitTxValidTo: TxBuilder = unsignedConnectionOpenInitTx.validTo(
72-
Date.now() + 100 * 1e3,
73-
);
72+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
73+
const unsignedConnectionOpenInitTxValidTo: TxBuilder = unsignedConnectionOpenInitTx.validTo(validToTime);
7474

7575
// Todo: signing should be done by the relayer in the future
7676
const signedConnectionOpenInitTxCompleted = await (await unsignedConnectionOpenInitTxValidTo.complete()).sign
@@ -108,7 +108,8 @@ export class ConnectionService {
108108
connectionOpenTryOperator,
109109
constructedAddress,
110110
);
111-
const unsignedConnectionOpenTryTxValidTo: TxBuilder = unsignedConnectionOpenTryTx.validTo(Date.now() + 100 * 1e3);
111+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
112+
const unsignedConnectionOpenTryTxValidTo: TxBuilder = unsignedConnectionOpenTryTx.validTo(validToTime);
112113

113114
// Todo: signing should be done by the relayer in the future
114115
const signedConnectionOpenTryTxCompleted = await (await unsignedConnectionOpenTryTxValidTo.complete()).sign
@@ -146,7 +147,8 @@ export class ConnectionService {
146147
connectionOpenAckOperator,
147148
constructedAddress,
148149
);
149-
const unsignedConnectionOpenAckTxValidTo: TxBuilder = unsignedConnectionOpenAckTx.validTo(Date.now() + 100 * 1e3);
150+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
151+
const unsignedConnectionOpenAckTxValidTo: TxBuilder = unsignedConnectionOpenAckTx.validTo(validToTime);
150152
// Todo: signing should be done by the relayer in the future
151153
const signedConnectionOpenAckTxCompleted = await (await unsignedConnectionOpenAckTxValidTo.complete()).sign
152154
.withWallet()
@@ -187,9 +189,8 @@ export class ConnectionService {
187189
connectionOpenConfirmOperator,
188190
constructedAddress,
189191
);
190-
const unsignedConnectionOpenConfirmTxValidTo: TxBuilder = unsignedConnectionOpenConfirmTx.validTo(
191-
Date.now() + 150 * 1e3,
192-
);
192+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
193+
const unsignedConnectionOpenConfirmTxValidTo: TxBuilder = unsignedConnectionOpenConfirmTx.validTo(validToTime);
193194

194195
// Todo: signing should be done by the relayer in the future
195196
const signedConnectionOpenConfirmTxCompleted = await (

cardano/gateway/src/tx/packet.service.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import { packetAcknowledgementPath, packetCommitmentPath, packetReceiptPath } fr
7171
import { Order as ChannelOrder } from '@plus/proto-types/build/ibc/core/channel/v1/channel';
7272
import { Order } from '~@/shared/types/channel/order';
7373
import { GrpcInternalException, GrpcInvalidArgumentException } from '~@/exception/grpc_exceptions';
74+
import { TRANSACTION_TIME_TO_LIVE } from '~@/config/constant.config';
7475

7576
@Injectable()
7677
export class PacketService {
@@ -133,7 +134,7 @@ export class PacketService {
133134
constructedAddress,
134135
);
135136

136-
const validToTime = Date.now() + 3 * 1e5;
137+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
137138
const validToSlot = this.lucidService.lucid.unixTimeToSlot(Number(validToTime));
138139
const currentSlot = this.lucidService.lucid.currentSlot();
139140
if (currentSlot > validToSlot) {
@@ -181,7 +182,7 @@ export class PacketService {
181182
const sendPacketOperator = validateAndFormatSendPacketParams(data);
182183

183184
const unsignedSendPacketTx: TxBuilder = await this.buildUnsignedSendPacketTx(sendPacketOperator);
184-
const validToTime = Date.now() + 3 * 1e5;
185+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
185186
const validToSlot = this.lucidService.lucid.unixTimeToSlot(Number(validToTime));
186187
const currentSlot = this.lucidService.lucid.currentSlot();
187188
if (currentSlot > validToSlot) {
@@ -227,7 +228,8 @@ export class PacketService {
227228
timeoutPacketOperator,
228229
constructedAddress,
229230
);
230-
const unsignedSendPacketTxValidTo: TxBuilder = unsignedSendPacketTx.validTo(Date.now() + 3 * 1e5);
231+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
232+
const unsignedSendPacketTxValidTo: TxBuilder = unsignedSendPacketTx.validTo(validToTime);
231233

232234
// Todo: signing should be done in the relayer in the future
233235
const signedSendPacketTxCompleted = await (await unsignedSendPacketTxValidTo.complete()).sign
@@ -280,7 +282,7 @@ export class PacketService {
280282
timeoutRefreshOperator,
281283
constructedAddress,
282284
);
283-
const validToTime = Date.now() + 3 * 1e5;
285+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
284286
const validToSlot = this.lucidService.lucid.unixTimeToSlot(Number(validToTime));
285287

286288
const currentSlot = this.lucidService.lucid.currentSlot();
@@ -329,7 +331,8 @@ export class PacketService {
329331
ackPacketOperator,
330332
constructedAddress,
331333
);
332-
const unsignedAckPacketTxValidTo: TxBuilder = unsignedAckPacketTx.validTo(Date.now() + 300 * 1e3);
334+
const validToTime = Date.now() + TRANSACTION_TIME_TO_LIVE;
335+
const unsignedAckPacketTxValidTo: TxBuilder = unsignedAckPacketTx.validTo(validToTime);
333336

334337
// Todo: signing should be done in the relayer in the future
335338
const signedAckPacketCompleted = await (await unsignedAckPacketTxValidTo.complete()).sign.withWallet().complete();

cardano/onchain/lib/ibc/client/ics-007-tendermint-client/client_datum.ak

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,25 @@ pub fn update_state(
9797
},
9898
}
9999

100-
expect
101-
(expected_updated_output.state.client_state == output_datum.state.client_state)?
102-
expect (expected_updated_output.token == output_datum.token)?
103-
104100
let output_cons_states = output_datum.state.consensus_states
105101
let expected_cons_states = expected_updated_output.state.consensus_states
106102

107103
let block_heights = pairs.keys(output_cons_states)
108104
expect list.difference(block_heights, pairs.keys(expected_cons_states)) == []
109105
expect list.difference(pairs.keys(expected_cons_states), block_heights) == []
110-
list.all(
111-
block_heights,
112-
fn(block_height) {
113-
pairs.get_all(output_cons_states, block_height) == pairs.get_all(
114-
expected_cons_states,
115-
block_height,
116-
)
117-
},
118-
)
106+
and {
107+
(expected_updated_output.state.client_state == output_datum.state.client_state)?,
108+
(expected_updated_output.token == output_datum.token)?,
109+
list.all(
110+
block_heights,
111+
fn(block_height) {
112+
pairs.get_all(output_cons_states, block_height) == pairs.get_all(
113+
expected_cons_states,
114+
block_height,
115+
)
116+
},
117+
),
118+
}
119119
}
120120

121121
pub fn update_state_on_misbehaviour(

cardano/onchain/lib/ibc/client/ics-007-tendermint-client/client_datum.test.ak

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ test test_is_initialized_valid_fail_with_invalid_consensus_states() fail {
238238
mock_latest_height,
239239
[],
240240
)
241-
let mock_consensus_states =
242-
[]
241+
let mock_consensus_states = []
243242
let mock_auth_token =
244243
AuthToken {
245244
policy_id: mock_auth_token_policy_id,

cardano/onchain/lib/ibc/client/mithril-client/protos/mithril_pb.test.ak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ test test_size_for_protocol_parameters_succeed() {
5656
phi_f: Some(Fraction { numerator: 20, denominator: 100 }),
5757
},
5858
),
59-
) == 10
59+
) == 27
6060
}
6161

6262
test test_marshal_for_fraction_same_result_empty() {

cardano/onchain/validators/minting_channel.test.ak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ fn setup() -> MockData {
299299
Input {
300300
output_reference: OutputReference {
301301
transaction_id: #"30b9c5259b2a19052508957a025b5f150204027f1c6545fd886da6d281f6e926",
302-
output_index: 0,
302+
output_index: 1,
303303
},
304304
output: Output {
305305
address: from_script("mock module script hash"),

0 commit comments

Comments
 (0)