Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit cf9eb6c

Browse files
committed
fix instruction offset check in instruction constructor
1 parent 9fb3f74 commit cf9eb6c

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

token/program-2022/src/extension/confidential_transfer/instruction.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,11 +1047,13 @@ pub fn withdraw(
10471047
range_proof_data_location,
10481048
)?];
10491049

1050+
let mut expected_instruction_offset = 1;
1051+
10501052
if let ProofLocation::InstructionOffset(proof_instruction_offset, proof_data) =
10511053
equality_proof_data_location
10521054
{
10531055
let proof_instruction_offset: i8 = proof_instruction_offset.into();
1054-
if proof_instruction_offset != 1 {
1056+
if proof_instruction_offset != expected_instruction_offset {
10551057
return Err(TokenError::InvalidProofInstructionOffset.into());
10561058
}
10571059
match proof_data {
@@ -1064,13 +1066,15 @@ pub fn withdraw(
10641066
.encode_verify_proof_from_account(None, address, offset),
10651067
),
10661068
};
1069+
1070+
expected_instruction_offset += 1;
10671071
};
10681072

10691073
if let ProofLocation::InstructionOffset(proof_instruction_offset, proof_data) =
10701074
range_proof_data_location
10711075
{
10721076
let proof_instruction_offset: i8 = proof_instruction_offset.into();
1073-
if proof_instruction_offset != 2 {
1077+
if proof_instruction_offset != expected_instruction_offset {
10741078
return Err(TokenError::InvalidProofInstructionOffset.into());
10751079
}
10761080
match proof_data {
@@ -1212,11 +1216,13 @@ pub fn transfer(
12121216
range_proof_data_location,
12131217
)?];
12141218

1219+
let mut expected_instruction_offset = 1;
1220+
12151221
if let ProofLocation::InstructionOffset(proof_instruction_offset, proof_data) =
12161222
equality_proof_data_location
12171223
{
12181224
let proof_instruction_offset: i8 = proof_instruction_offset.into();
1219-
if proof_instruction_offset != 1 {
1225+
if proof_instruction_offset != expected_instruction_offset {
12201226
return Err(TokenError::InvalidProofInstructionOffset.into());
12211227
}
12221228
match proof_data {
@@ -1229,13 +1235,15 @@ pub fn transfer(
12291235
.encode_verify_proof_from_account(None, address, offset),
12301236
),
12311237
};
1238+
1239+
expected_instruction_offset += 1;
12321240
}
12331241

12341242
if let ProofLocation::InstructionOffset(proof_instruction_offset, proof_data) =
12351243
ciphertext_validity_proof_data_location
12361244
{
12371245
let proof_instruction_offset: i8 = proof_instruction_offset.into();
1238-
if proof_instruction_offset != 2 {
1246+
if proof_instruction_offset != expected_instruction_offset {
12391247
return Err(TokenError::InvalidProofInstructionOffset.into());
12401248
}
12411249
match proof_data {
@@ -1248,13 +1256,15 @@ pub fn transfer(
12481256
.encode_verify_proof_from_account(None, address, offset),
12491257
),
12501258
};
1259+
1260+
expected_instruction_offset += 1;
12511261
}
12521262

12531263
if let ProofLocation::InstructionOffset(proof_instruction_offset, proof_data) =
12541264
range_proof_data_location
12551265
{
12561266
let proof_instruction_offset: i8 = proof_instruction_offset.into();
1257-
if proof_instruction_offset != 3 {
1267+
if proof_instruction_offset != expected_instruction_offset {
12581268
return Err(TokenError::InvalidProofInstructionOffset.into());
12591269
}
12601270
match proof_data {
@@ -1580,11 +1590,13 @@ pub fn transfer_with_fee(
15801590
range_proof_data_location,
15811591
)?];
15821592

1593+
let mut expected_instruction_offset = 1;
1594+
15831595
if let ProofLocation::InstructionOffset(proof_instruction_offset, proof_data) =
15841596
equality_proof_data_location
15851597
{
15861598
let proof_instruction_offset: i8 = proof_instruction_offset.into();
1587-
if proof_instruction_offset != 1 {
1599+
if proof_instruction_offset != expected_instruction_offset {
15881600
return Err(TokenError::InvalidProofInstructionOffset.into());
15891601
}
15901602
match proof_data {
@@ -1597,13 +1609,14 @@ pub fn transfer_with_fee(
15971609
.encode_verify_proof_from_account(None, address, offset),
15981610
),
15991611
};
1612+
expected_instruction_offset += 1;
16001613
}
16011614

16021615
if let ProofLocation::InstructionOffset(proof_instruction_offset, proof_data) =
16031616
transfer_amount_ciphertext_validity_proof_data_location
16041617
{
16051618
let proof_instruction_offset: i8 = proof_instruction_offset.into();
1606-
if proof_instruction_offset != 2 {
1619+
if proof_instruction_offset != expected_instruction_offset {
16071620
return Err(TokenError::InvalidProofInstructionOffset.into());
16081621
}
16091622
match proof_data {
@@ -1616,13 +1629,14 @@ pub fn transfer_with_fee(
16161629
.encode_verify_proof_from_account(None, address, offset),
16171630
),
16181631
};
1632+
expected_instruction_offset += 1;
16191633
}
16201634

16211635
if let ProofLocation::InstructionOffset(proof_instruction_offset, proof_data) =
16221636
fee_sigma_proof_data_location
16231637
{
16241638
let proof_instruction_offset: i8 = proof_instruction_offset.into();
1625-
if proof_instruction_offset != 3 {
1639+
if proof_instruction_offset != expected_instruction_offset {
16261640
return Err(TokenError::InvalidProofInstructionOffset.into());
16271641
}
16281642
match proof_data {
@@ -1633,13 +1647,14 @@ pub fn transfer_with_fee(
16331647
.encode_verify_proof_from_account(None, address, offset),
16341648
),
16351649
};
1650+
expected_instruction_offset += 1;
16361651
}
16371652

16381653
if let ProofLocation::InstructionOffset(proof_instruction_offset, proof_data) =
16391654
fee_ciphertext_validity_proof_data_location
16401655
{
16411656
let proof_instruction_offset: i8 = proof_instruction_offset.into();
1642-
if proof_instruction_offset != 4 {
1657+
if proof_instruction_offset != expected_instruction_offset {
16431658
return Err(TokenError::InvalidProofInstructionOffset.into());
16441659
}
16451660
match proof_data {
@@ -1652,13 +1667,14 @@ pub fn transfer_with_fee(
16521667
.encode_verify_proof_from_account(None, address, offset),
16531668
),
16541669
};
1670+
expected_instruction_offset += 1;
16551671
}
16561672

16571673
if let ProofLocation::InstructionOffset(proof_instruction_offset, proof_data) =
16581674
range_proof_data_location
16591675
{
16601676
let proof_instruction_offset: i8 = proof_instruction_offset.into();
1661-
if proof_instruction_offset != 5 {
1677+
if proof_instruction_offset != expected_instruction_offset {
16621678
return Err(TokenError::InvalidProofInstructionOffset.into());
16631679
}
16641680
match proof_data {

0 commit comments

Comments
 (0)