@@ -259,12 +259,19 @@ public static long getSuicideCost(Program ignored) {
259259 return SUICIDE ;
260260 }
261261
262+ public static long getSuicideCost2 (Program program ) {
263+ DataWord inheritorAddress = program .getStack ().peek ();
264+ if (isDeadAccount (program , inheritorAddress )) {
265+ return getSuicideCost (program ) + NEW_ACCT_CALL ;
266+ }
267+ return getSuicideCost (program );
268+ }
269+
262270 public static long getBalanceCost (Program ignored ) {
263271 return BALANCE ;
264272 }
265273
266274 public static long getFreezeCost (Program program ) {
267-
268275 Stack stack = program .getStack ();
269276 DataWord receiverAddressWord = stack .get (stack .size () - 3 );
270277 if (isDeadAccount (program , receiverAddressWord )) {
@@ -306,7 +313,27 @@ public static long getUnDelegateResourceCost(Program ignored) {
306313 }
307314
308315 public static long getVoteWitnessCost (Program program ) {
316+ Stack stack = program .getStack ();
317+ long oldMemSize = program .getMemSize ();
318+ DataWord amountArrayLength = stack .get (stack .size () - 1 ).clone ();
319+ DataWord amountArrayOffset = stack .get (stack .size () - 2 );
320+ DataWord witnessArrayLength = stack .get (stack .size () - 3 ).clone ();
321+ DataWord witnessArrayOffset = stack .get (stack .size () - 4 );
322+
323+ DataWord wordSize = new DataWord (DataWord .WORD_SIZE );
324+
325+ amountArrayLength .mul (wordSize );
326+ BigInteger amountArrayMemoryNeeded = memNeeded (amountArrayOffset , amountArrayLength );
327+
328+ witnessArrayLength .mul (wordSize );
329+ BigInteger witnessArrayMemoryNeeded = memNeeded (witnessArrayOffset , witnessArrayLength );
330+
331+ return VOTE_WITNESS + calcMemEnergy (oldMemSize ,
332+ (amountArrayMemoryNeeded .compareTo (witnessArrayMemoryNeeded ) > 0
333+ ? amountArrayMemoryNeeded : witnessArrayMemoryNeeded ), 0 , Op .VOTEWITNESS );
334+ }
309335
336+ public static long getVoteWitnessCost2 (Program program ) {
310337 Stack stack = program .getStack ();
311338 long oldMemSize = program .getMemSize ();
312339 DataWord amountArrayLength = stack .get (stack .size () - 1 ).clone ();
@@ -317,9 +344,11 @@ public static long getVoteWitnessCost(Program program) {
317344 DataWord wordSize = new DataWord (DataWord .WORD_SIZE );
318345
319346 amountArrayLength .mul (wordSize );
347+ amountArrayLength .add (wordSize ); // dynamic array length is at least 32 bytes
320348 BigInteger amountArrayMemoryNeeded = memNeeded (amountArrayOffset , amountArrayLength );
321349
322350 witnessArrayLength .mul (wordSize );
351+ witnessArrayLength .add (wordSize ); // dynamic array length is at least 32 bytes
323352 BigInteger witnessArrayMemoryNeeded = memNeeded (witnessArrayOffset , witnessArrayLength );
324353
325354 return VOTE_WITNESS + calcMemEnergy (oldMemSize ,
0 commit comments