Skip to content

Commit

Permalink
Merge pull request #2802 from rsksmart/enhance_eth_compatibility_cont…
Browse files Browse the repository at this point in the history
…ract_deployment

Enhance Ethereum compatibility while deploying contracts
  • Loading branch information
Vovchyk authored Dec 17, 2024
2 parents d072012 + 428263c commit 50137dc
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public enum ConsensusRule {
RSKIP434("rskip434"),
RSKIP438("rskip438"),
RSKIP445("rskip445"), // From EIP-5656 MCOPY instruction
RSKIP453("rskip453"),
RSKIP454("rskip454"),
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private boolean init() {
}

long txGasLimit = GasCost.toGas(tx.getGasLimit());
long gasLimit = activations.isActive(RSKIP144)? sublistGasLimit : GasCost.toGas(executionBlock.getGasLimit());
long gasLimit = activations.isActive(RSKIP144) ? sublistGasLimit : GasCost.toGas(executionBlock.getGasLimit());

if (!gasIsValid(txGasLimit, gasLimit)) {
return false;
Expand Down
12 changes: 12 additions & 0 deletions rskj-core/src/main/java/org/ethereum/vm/program/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -688,12 +688,24 @@ private ProgramResult getProgramResult(RskAddress senderAddress, byte[] nonce, D
this,
"No gas to return just created contract",
storageCost));

if (activations.isActive(ConsensusRule.RSKIP453)) {
track.rollback();
stackPushZero();
return null;
}
} else if (codeLength > Constants.getMaxContractSize()) {
programResult.setException(
ExceptionHelper.tooLargeContractSize(
this,
Constants.getMaxContractSize(),
codeLength));

if (activations.isActive(ConsensusRule.RSKIP453)) {
track.rollback();
stackPushZero();
return null;
}
} else {
programResult.spendGas(storageCost);
track.saveCode(contractAddress, code);
Expand Down
1 change: 1 addition & 0 deletions rskj-core/src/main/resources/expected.conf
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ blockchain = {
rskip434 = <hardforkName>
rskip438 = <hardforkName>
rskip445 = <hardforkName>
rskip453 = <hardforkName>
rskip454 = <hardforkName>
}
}
Expand Down
1 change: 1 addition & 0 deletions rskj-core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ blockchain = {
rskip434 = arrowhead631
rskip438 = lovell700
rskip445 = lovell700
rskip453 = lovell700
rskip454 = lovell700
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class ActivationConfigTest {
" rskip434: arrowhead631",
" rskip438: lovell700",
" rskip445: lovell700",
" rskip453: lovell700",
" rskip454: lovell700",
"}"
));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.ethereum.core;

import co.rsk.config.TestSystemProperties;
import co.rsk.test.World;
import co.rsk.test.dsl.DslParser;
import co.rsk.test.dsl.DslProcessorException;
import co.rsk.test.dsl.WorldDslProcessor;
import com.typesafe.config.ConfigValueFactory;
import org.junit.jupiter.api.Test;

import java.io.FileNotFoundException;

import static org.junit.jupiter.api.Assertions.*;

class ContractCreatingDslRollbackTest {

@Test
void testCreateExecutionFailsAfter453IsRollingBack() throws FileNotFoundException, DslProcessorException {
TestSystemProperties properties = new TestSystemProperties();

String resourcePath = "dsl/453_rollback_during_creation/not_enough_gas";
DslParser parser = DslParser.fromResource(resourcePath);
World world = new World(properties);
WorldDslProcessor processor = new WorldDslProcessor(world);
processor.processCommands(parser);

TransactionReceipt transactionReceipt = world.getTransactionReceiptByName("txContractCreation");
assertNotNull(transactionReceipt);
assertFalse(transactionReceipt.isSuccessful());
}

@Test
void testCreateExecutionBefore453isNotRollingBackHavingNotEnoughGaa() throws FileNotFoundException, DslProcessorException {
TestSystemProperties properties = new TestSystemProperties(rawConfig ->
rawConfig.withValue("blockchain.config.consensusRules.rskip453", ConfigValueFactory.fromAnyRef(-1))
);

String resourcePath = "dsl/453_rollback_during_creation/not_enough_gas";
DslParser parser = DslParser.fromResource(resourcePath);
World world = new World(properties);
WorldDslProcessor processor = new WorldDslProcessor(world);
processor.processCommands(parser);

TransactionReceipt transactionReceipt = world.getTransactionReceiptByName("txContractCreation");
assertNotNull(transactionReceipt);
assertTrue(transactionReceipt.isSuccessful());
}

@Test
void createExecutionExceedingCodeSizeDoesNotRollbackBefore453() throws FileNotFoundException, DslProcessorException {
TestSystemProperties properties = new TestSystemProperties(rawConfig ->
rawConfig.withValue("blockchain.config.consensusRules.rskip453", ConfigValueFactory.fromAnyRef(-1))
);

String resourcePath = "dsl/453_rollback_during_creation/exceeding_code_size";
DslParser parser = DslParser.fromResource(resourcePath);
World world = new World(properties);
WorldDslProcessor processor = new WorldDslProcessor(world);
processor.processCommands(parser);

TransactionReceipt transactionReceipt = world.getTransactionReceiptByName("txContractCreation");
assertNotNull(transactionReceipt);
assertTrue(transactionReceipt.isSuccessful());
}

@Test
void createExecutionExceedingCodeSizeDoesRollbackAfter453() throws FileNotFoundException, DslProcessorException {
TestSystemProperties properties = new TestSystemProperties();

String resourcePath = "dsl/453_rollback_during_creation/exceeding_code_size";
DslParser parser = DslParser.fromResource(resourcePath);
World world = new World(properties);
WorldDslProcessor processor = new WorldDslProcessor(world);
processor.processCommands(parser);

TransactionReceipt transactionReceipt = world.getTransactionReceiptByName("txContractCreation");
assertNotNull(transactionReceipt);
assertFalse(transactionReceipt.isSuccessful());
}

}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
comment

// Contracts compiled using 0.8.20
// the contract source code

contract StorageFactory {

function testOpcodeCreate(bytes memory _data) external returns (address) {
return address(new Storage(_data));
}

function testOpcodeCreate2(bytes memory _data) public payable returns (address)
{
bytes32 _salt = bytes32(uint256(1));
return address(new Storage{salt: _salt}(_data));
}
}

contract Storage {
address public owner;
bytes data;

constructor(bytes memory _data) {
owner = msg.sender;
data = _data;
}

function get() external view returns (bytes memory) {
return data;
}
}

end

account_new acc1 20000000

# deploy contract compiled with 0.8.20
transaction_build txCreateContractFactory
sender acc1
receiverAddress 00
value 0
data 608060405234801561001057600080fd5b50610cde806100206000396000f3fe6080604052600436106200002c5760003560e01c8063490af4231462000031578063fdaaa16f1462000067575b600080fd5b6200004f6004803603810190620000499190620002c1565b620000ab565b6040516200005e919062000357565b60405180910390f35b3480156200007457600080fd5b506200009360048036038101906200008d9190620002c1565b620000fb565b604051620000a2919062000357565b60405180910390f35b600080600160001b90508083604051620000c5906200013d565b620000d19190620003fd565b8190604051809103906000f5905080158015620000f2573d6000803e3d6000fd5b50915050919050565b6000816040516200010c906200013d565b620001189190620003fd565b604051809103906000f08015801562000135573d6000803e3d6000fd5b509050919050565b610887806200042283390190565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b620001b48262000169565b810181811067ffffffffffffffff82111715620001d657620001d56200017a565b5b80604052505050565b6000620001eb6200014b565b9050620001f98282620001a9565b919050565b600067ffffffffffffffff8211156200021c576200021b6200017a565b5b620002278262000169565b9050602081019050919050565b82818337600083830152505050565b60006200025a6200025484620001fe565b620001df565b90508281526020810184848401111562000279576200027862000164565b5b6200028684828562000234565b509392505050565b600082601f830112620002a657620002a56200015f565b5b8135620002b884826020860162000243565b91505092915050565b600060208284031215620002da57620002d962000155565b5b600082013567ffffffffffffffff811115620002fb57620002fa6200015a565b5b62000309848285016200028e565b91505092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006200033f8262000312565b9050919050565b620003518162000332565b82525050565b60006020820190506200036e600083018462000346565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015620003b057808201518184015260208101905062000393565b60008484015250505050565b6000620003c98262000374565b620003d581856200037f565b9350620003e781856020860162000390565b620003f28162000169565b840191505092915050565b60006020820190508181036000830152620004198184620003bc565b90509291505056fe60806040523480156200001157600080fd5b506040516200088738038062000887833981810160405281019062000037919062000223565b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508060019081620000889190620004bf565b5050620005a6565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b620000f982620000ae565b810181811067ffffffffffffffff821117156200011b576200011a620000bf565b5b80604052505050565b60006200013062000090565b90506200013e8282620000ee565b919050565b600067ffffffffffffffff821115620001615762000160620000bf565b5b6200016c82620000ae565b9050602081019050919050565b60005b83811015620001995780820151818401526020810190506200017c565b60008484015250505050565b6000620001bc620001b68462000143565b62000124565b905082815260208101848484011115620001db57620001da620000a9565b5b620001e884828562000179565b509392505050565b600082601f830112620002085762000207620000a4565b5b81516200021a848260208601620001a5565b91505092915050565b6000602082840312156200023c576200023b6200009a565b5b600082015167ffffffffffffffff8111156200025d576200025c6200009f565b5b6200026b84828501620001f0565b91505092915050565b600081519050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680620002c757607f821691505b602082108103620002dd57620002dc6200027f565b5b50919050565b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b600060088302620003477fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8262000308565b62000353868362000308565b95508019841693508086168417925050509392505050565b6000819050919050565b6000819050919050565b6000620003a06200039a62000394846200036b565b62000375565b6200036b565b9050919050565b6000819050919050565b620003bc836200037f565b620003d4620003cb82620003a7565b84845462000315565b825550505050565b600090565b620003eb620003dc565b620003f8818484620003b1565b505050565b5b81811015620004205762000414600082620003e1565b600181019050620003fe565b5050565b601f8211156200046f576200043981620002e3565b6200044484620002f8565b8101602085101562000454578190505b6200046c6200046385620002f8565b830182620003fd565b50505b505050565b600082821c905092915050565b6000620004946000198460080262000474565b1980831691505092915050565b6000620004af838362000481565b9150826002028217905092915050565b620004ca8262000274565b67ffffffffffffffff811115620004e657620004e5620000bf565b5b620004f28254620002ae565b620004ff82828562000424565b600060209050601f83116001811462000537576000841562000522578287015190505b6200052e8582620004a1565b8655506200059e565b601f1984166200054786620002e3565b60005b8281101562000571578489015182556001820191506020850194506020810190506200054a565b868310156200059157848901516200058d601f89168262000481565b8355505b6001600288020188555050505b505050505050565b6102d180620005b66000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80636d4ce63c1461003b5780638da5cb5b14610059575b600080fd5b610043610077565b60405161005091906101bd565b60405180910390f35b610061610109565b60405161006e9190610220565b60405180910390f35b6060600180546100869061026a565b80601f01602080910402602001604051908101604052809291908181526020018280546100b29061026a565b80156100ff5780601f106100d4576101008083540402835291602001916100ff565b820191906000526020600020905b8154815290600101906020018083116100e257829003601f168201915b5050505050905090565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600081519050919050565b600082825260208201905092915050565b60005b8381101561016757808201518184015260208101905061014c565b60008484015250505050565b6000601f19601f8301169050919050565b600061018f8261012d565b6101998185610138565b93506101a9818560208601610149565b6101b281610173565b840191505092915050565b600060208201905081810360008301526101d78184610184565b905092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061020a826101df565b9050919050565b61021a816101ff565b82525050565b60006020820190506102356000830184610211565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b6000600282049050600182168061028257607f821691505b6020821081036102955761029461023b565b5b5091905056fea264697066735822122071163cf749253f921b29799fb8f2b856a099dcdc627d7622ee7536e5e392509464736f6c63430008180033a2646970667358221220bd9fa3c126989a1d6a7a7fe44541a0bf9a4b43a3d2e12733f1208d6beaf0ede564736f6c63430008180033
gas 6500000
build

block_build b01
parent g00
gasLimit 650000000
transactions txCreateContractFactory
build

block_connect b01

# Assert best block
assert_best b01


transaction_build txContractCreation
sender acc1
nonce 1
contract txCreateContractFactory # created in txCreateContractFactory
value 0
data 490af423000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000041234567800000000000000000000000000000000000000000000000000000000
gas 100000
build

block_build b02
parent b01
gasLimit 10000000
transactions txContractCreation
build

block_connect b02

# Assert best block
assert_best b02

0 comments on commit 50137dc

Please sign in to comment.