Skip to content

Commit

Permalink
Merge pull request #2014 from rsksmart/investigate-remasc-config-err-…
Browse files Browse the repository at this point in the history
…related-to-invalid-block

RemascConfigFactory refactoring
  • Loading branch information
Vovchyk authored Jul 11, 2023
2 parents 7169151 + 6c80974 commit af47aaa
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions rskj-core/src/main/java/org/ethereum/vm/PrecompiledContracts.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ public class PrecompiledContracts {

// this maps needs to be updated by hand any time a new pcc is added
public static final Map<RskAddress, ConsensusRule> CONSENSUS_ENABLED_ADDRESSES = Collections.unmodifiableMap(
Stream.of(
new AbstractMap.SimpleEntry<>(HD_WALLET_UTILS_ADDR, ConsensusRule.RSKIP106),
new AbstractMap.SimpleEntry<>(BLOCK_HEADER_ADDR, ConsensusRule.RSKIP119),
new AbstractMap.SimpleEntry<>(ALT_BN_128_ADD_ADDR, ConsensusRule.RSKIP137),
new AbstractMap.SimpleEntry<>(ALT_BN_128_MUL_ADDR, ConsensusRule.RSKIP137),
new AbstractMap.SimpleEntry<>(ALT_BN_128_PAIRING_ADDR, ConsensusRule.RSKIP137),
new AbstractMap.SimpleEntry<>(BLAKE2F_ADDR, ConsensusRule.RSKIP153)
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
Stream.of(
new AbstractMap.SimpleEntry<>(HD_WALLET_UTILS_ADDR, ConsensusRule.RSKIP106),
new AbstractMap.SimpleEntry<>(BLOCK_HEADER_ADDR, ConsensusRule.RSKIP119),
new AbstractMap.SimpleEntry<>(ALT_BN_128_ADD_ADDR, ConsensusRule.RSKIP137),
new AbstractMap.SimpleEntry<>(ALT_BN_128_MUL_ADDR, ConsensusRule.RSKIP137),
new AbstractMap.SimpleEntry<>(ALT_BN_128_PAIRING_ADDR, ConsensusRule.RSKIP137),
new AbstractMap.SimpleEntry<>(BLAKE2F_ADDR, ConsensusRule.RSKIP153)
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))
);

private static ECRecover ecRecover = new ECRecover();
Expand All @@ -136,13 +136,15 @@ public class PrecompiledContracts {
private final RskSystemProperties config;
private final BridgeSupportFactory bridgeSupportFactory;
private final SignatureCache signatureCache;
private final RemascConfig remascConfig;

public PrecompiledContracts(RskSystemProperties config,
BridgeSupportFactory bridgeSupportFactory,
SignatureCache signatureCache) {
this.config = config;
this.bridgeSupportFactory = bridgeSupportFactory;
this.signatureCache = signatureCache;
this.remascConfig = new RemascConfigFactory(RemascContract.REMASC_CONFIG).createRemascConfig(config.netName());
}


Expand Down Expand Up @@ -174,7 +176,6 @@ public PrecompiledContract getContractForAddress(ActivationConfig.ForBlock activ
return bigIntegerModexp;
}
if (address.equals(REMASC_ADDR_DW)) {
RemascConfig remascConfig = new RemascConfigFactory(RemascContract.REMASC_CONFIG).createRemascConfig(config.netName());
return new RemascContract(REMASC_ADDR, remascConfig, config.getNetworkConstants(), config.getActivationConfig());
}

Expand Down Expand Up @@ -211,9 +212,12 @@ public abstract static class PrecompiledContract {

public abstract long getGasForData(byte[] data);

public void init(Transaction tx, Block executionBlock, Repository repository, BlockStore blockStore, ReceiptStore receiptStore, List<LogInfo> logs) {}
public void init(Transaction tx, Block executionBlock, Repository repository, BlockStore blockStore, ReceiptStore receiptStore, List<LogInfo> logs) {
}

public List<ProgramSubtrace> getSubtraces() { return Collections.emptyList(); }
public List<ProgramSubtrace> getSubtraces() {
return Collections.emptyList();
}

public abstract byte[] execute(byte[] data) throws VMException;
}
Expand Down Expand Up @@ -289,8 +293,7 @@ public byte[] execute(byte[] data) {
byte[] result = null;
if (data == null) {
result = HashUtil.ripemd160(ByteUtil.EMPTY_BYTE_ARRAY);
}
else {
} else {
result = HashUtil.ripemd160(data);
}

Expand Down Expand Up @@ -352,12 +355,12 @@ private boolean isValid(byte[] rBytes, byte[] sBytes, byte[] vBytes) {

/**
* Computes modular exponentiation on big numbers
*
* <p>
* format of data[] array:
* [length_of_BASE] [length_of_EXPONENT] [length_of_MODULUS] [BASE] [EXPONENT] [MODULUS]
* where every length is a 32-byte left-padded integer representing the number of bytes.
* Call data is assumed to be infinitely right-padded with zero bytes.
*
* <p>
* Returns an output as a byte array with the same length as the modulus
*/
public static class BigIntegerModexp extends PrecompiledContract {
Expand All @@ -372,7 +375,7 @@ public static class BigIntegerModexp extends PrecompiledContract {

@Override
public long getGasForData(byte[] data) {
byte[] safeData = data==null?EMPTY_BYTE_ARRAY:data;
byte[] safeData = data == null ? EMPTY_BYTE_ARRAY : data;

int baseLen = parseLen(safeData, BASE);
int expLen = parseLen(safeData, EXPONENT);
Expand Down

0 comments on commit af47aaa

Please sign in to comment.