ethereum/ethereumj

EVM dataword ONE is null

tangkunprimeledger opened this issue · 3 comments

class https://github.com/ethereum/ethereumj/blob/develop/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java static ONE is null, bug in line 81;

   public static final DataWord ONE = DataWord.of((byte) 1);

    public static DataWord of(int num) {
       return of(intToBytes(num));
     }
   
     public static DataWord of(byte[] data) {
       if (data == null || data.length == 0) {
           return DataWord.ZERO;
       }
       int leadingZeroBits = numberOfLeadingZeros(data);
       int valueBits = 8 * data.length - leadingZeroBits;
       if (valueBits <= 8) {
           if (data[data.length - 1] == 0) {
               return DataWord.ZERO;
           }
           if (data[data.length - 1] == 1) {
        //hotfix: dataWord one is not init 
             /* * byte[] bytes = new byte[8 * data.length];
               bytes[bytes.length - 1] = 1;
               return new DataWord(bytes);*/
          //bug:return ONE but ONE is not init,so ONE is null
             return DataWord.ONE ;
           }
       }

       if (data.length == 32) {
           return new DataWord(java.util.Arrays.copyOf(data, data.length));
       } else if (data.length <= 32) {
           byte[] bytes = new byte[32];
           System.arraycopy(data, 0, bytes, 32 - data.length, data.length);
           return new DataWord(bytes);
       } else {
           throw new RuntimeException(String.format("Data word can't exceed 32 bytes: 0x%s", ByteUtil.toHexString(data)));
       }
   }

I've created test and it passes. Why do you think it's bugged?


    @Test
    public void testOne() {
        byte[] input = new byte[] {0x01};
        DataWord one = DataWord.of(input);
        assertArrayEquals(Hex.decode("0000000000000000000000000000000000000000000000000000000000000001"), one.getData());
    }

@zilm13 Are you sure your source code(DataWord ) is consistent with mine?

@tangkunprimeledger mine is develop