Skip to content

Commit 7046a97

Browse files
committed
Add test case for calling TXCREATE in a loop
1 parent 66dcad5 commit 7046a97

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/unittests/state_transition_txcreate_test.cpp

+36
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,42 @@ TEST_F(state_transition, txcreate_from_blob_tx)
11701170
expect.post[*tx.to].storage[0x01_bytes32] = 0x01_bytes32;
11711171
}
11721172

1173+
TEST_F(state_transition, txcreate_loop)
1174+
{
1175+
rev = EVMC_OSAKA;
1176+
block.gas_limit = 30'000'000;
1177+
tx.gas_limit = block.gas_limit;
1178+
pre.get(tx.sender).balance = tx.gas_limit * tx.max_gas_price + tx.value + 1;
1179+
1180+
const auto deploy_container = eof_bytecode(bytecode(OP_INVALID));
1181+
1182+
const auto init_code = returncode(0, 0, 0);
1183+
const bytecode init_container = eof_bytecode(init_code, 2).container(deploy_container);
1184+
1185+
tx.type = Transaction::Type::initcodes;
1186+
tx.initcodes.push_back(init_container);
1187+
1188+
constexpr auto iterations = 500;
1189+
const auto initcode_hash = keccak256(init_container);
1190+
const auto factory_code =
1191+
push0() + // initial salt
1192+
push(1) + OP_ADD + // increment salt
1193+
OP_DUP1 + push(iterations + 1) + rjumpi(45, OP_EQ) + // if (salt == iterations + 1) break;
1194+
txcreate().value(0).initcode(initcode_hash).input(0, 0).salt(OP_DUP4) + OP_POP +
1195+
rjump(-56) + OP_STOP;
1196+
const auto factory_container = eof_bytecode(factory_code, 6);
1197+
1198+
tx.to = To;
1199+
pre.insert(*tx.to, {.nonce = 1, .code = factory_container});
1200+
1201+
expect.post[*tx.to].nonce = pre.get(*tx.to).nonce + iterations;
1202+
for (uint16_t salt = 1; salt <= iterations; ++salt)
1203+
{
1204+
const auto create_address = compute_eofcreate_address(*tx.to, bytes32{salt});
1205+
expect.post[create_address].code = deploy_container;
1206+
expect.post[create_address].nonce = 1;
1207+
}
1208+
}
11731209

11741210
TEST_F(state_transition, legacy_txcreate_empty_auxdata)
11751211
{

0 commit comments

Comments
 (0)