@@ -14,6 +14,7 @@ use tasm_lib::memory::encode_to_memory;
14
14
use tasm_lib:: memory:: FIRST_NON_DETERMINISTICALLY_INITIALIZED_MEMORY_ADDRESS ;
15
15
use tasm_lib:: prelude:: Library ;
16
16
use tasm_lib:: prelude:: TasmObject ;
17
+ use tasm_lib:: structure:: tasm_object:: DEFAULT_MAX_DYN_FIELD_SIZE ;
17
18
use tasm_lib:: structure:: verify_nd_si_integrity:: VerifyNdSiIntegrity ;
18
19
use tasm_lib:: triton_vm:: prelude:: * ;
19
20
use tasm_lib:: twenty_first:: math:: b_field_element:: BFieldElement ;
@@ -43,6 +44,9 @@ const BAD_SALTED_UTXOS_ERROR: i128 = 1_000_031;
43
44
const NO_INFLATION_VIOLATION : i128 = 1_000_032 ;
44
45
const BAD_STATE_SIZE_ERROR : i128 = 1_000_033 ;
45
46
const COINBASE_TIMELOCK_INSUFFICIENT : i128 = 1_000_034 ;
47
+ const UTXO_SIZE_TOO_LARGE_ERROR : i128 = 1_000_035 ;
48
+ const TOO_BIG_COIN_FIELD_SIZE_ERROR : i128 = 1_000_036 ;
49
+ const STATE_LENGTH_FOR_TIME_LOCK_NOT_ONE_ERROR : i128 = 1_000_037 ;
46
50
47
51
/// `NativeCurrency` is the type script that governs Neptune's native currency,
48
52
/// Neptune coins.
@@ -661,7 +665,6 @@ impl ConsensusProgram for NativeCurrency {
661
665
hint coins_j_si = stack[ 8 ]
662
666
hint j = stack[ 9 ]
663
667
hint emm = stack[ 10 ]
664
- break
665
668
666
669
push 0 push 0 push 0 push 0
667
670
push 0
@@ -679,7 +682,8 @@ impl ConsensusProgram for NativeCurrency {
679
682
pick 7 pick 7 pick 7 pick 7
680
683
// _ N i *utxos[i]_si M M *coins[M]_si [amount'] [timelocked_amount']
681
684
682
- dup 12 push 1 add
685
+ // prepare next iteration
686
+ dup 12 addi 1
683
687
// _ N i *utxos[i]_si M M *coins[M]_si [amount'] [timelocked_amount'] (i+1)
684
688
685
689
swap 13 pop 1
@@ -688,6 +692,11 @@ impl ConsensusProgram for NativeCurrency {
688
692
dup 11 read_mem 1 push 2 add
689
693
// _ N (i+1) *utxos[i]_si M M *coins[M]_si [amount'] [timelocked_amount'] size(utxos[i]) *utxos[i]
690
694
695
+ push { DEFAULT_MAX_DYN_FIELD_SIZE }
696
+ dup 2
697
+ lt
698
+ assert error_id { UTXO_SIZE_TOO_LARGE_ERROR }
699
+
691
700
add swap 12 pop 1
692
701
// _ N (i+1) *utxos[i+1]_si M M *coins[M]_si [amount'] [timelocked_amount']
693
702
@@ -776,6 +785,13 @@ impl ConsensusProgram for NativeCurrency {
776
785
dup 13 read_mem 1 push 2 add
777
786
// _ M (j+1) *coins[j]_si [amount] [timelocked_amount] [utxo_amount] utxo_is_timelocked size(coins[j]) *coins[j]
778
787
788
+ /* Range-check on size */
789
+ push { DEFAULT_MAX_DYN_FIELD_SIZE }
790
+ dup 2
791
+ lt
792
+ assert error_id { TOO_BIG_COIN_FIELD_SIZE_ERROR }
793
+ // _ M (j+1) *coins[j]_si [amount] [timelocked_amount] [utxo_amount] utxo_is_timelocked size(coins[j]) *coins[j]
794
+
779
795
add
780
796
// _ M (j+1) *coins[j]_si [amount] [timelocked_amount] [utxo_amount] utxo_is_timelocked *coins[j+1]_si
781
797
@@ -801,7 +817,7 @@ impl ConsensusProgram for NativeCurrency {
801
817
// _ M j *coins[j]_si [amount] [timelocked_amount] [utxo_amount'] utxo_is_timelocked state[0] state.len()
802
818
803
819
// time lock states must encode exactly one element
804
- assert
820
+ assert error_id { STATE_LENGTH_FOR_TIME_LOCK_NOT_ONE_ERROR }
805
821
// _ M j *coins[j]_si [amount] [timelocked_amount] [utxo_amount'] utxo_is_timelocked utxo_release_date
806
822
807
823
split
0 commit comments