Skip to content

Commit 4447a3f

Browse files
Handle EIP-7702 code delgation
Signed-off-by: Lukasz Gasior <[email protected]>
1 parent 1d6cdf0 commit 4447a3f

File tree

68 files changed

+804
-1014
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+804
-1014
lines changed

hedera-node/hedera-config/src/main/java/com/hedera/node/config/data/ContractsConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public record ContractsConfig(
100100
@ConfigProperty(value = "evm.version", defaultValue = "v0.51") @NetworkProperty String evmVersion,
101101
@ConfigProperty(value = "evm.nativeLibVerification.halt.enabled", defaultValue = "false") @NetworkProperty
102102
boolean nativeLibVerificationHaltEnabled,
103-
@ConfigProperty(value = "metrics.smartContract.primary.enabled", defaultValue = "true") @NetworkProperty
103+
@ConfigProperty(value = "metrics.smartContract.primary.enabled", defaultValue = "false") @NetworkProperty
104104
boolean metricsSmartContractPrimaryEnabled,
105105
@ConfigProperty(value = "metrics.smartContract.secondary.enabled", defaultValue = "true") @NetworkProperty
106106
boolean metricsSmartContractSecondaryEnabled) {}

hedera-node/hedera-smart-contract-service-impl/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ description = "Default Hedera Smart Contract Service Implementation"
55

66
// Remove the following line to enable all 'javac' lint checks that we have turned on by default
77
// and then fix the reported issues.
8-
tasks.withType<JavaCompile>().configureEach { options.compilerArgs.add("-Xlint:-exports") }
8+
// TODO: bring back .add("-Xlint:-exports")
9+
tasks.withType<JavaCompile>().configureEach { options.compilerArgs.clear() }
910

1011
mainModuleInfo { annotationProcessor("dagger.compiler") }
1112

hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/TransactionProcessor.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import edu.umd.cs.findbugs.annotations.Nullable;
3737
import org.hyperledger.besu.datatypes.Address;
3838
import org.hyperledger.besu.evm.code.CodeFactory;
39+
import org.hyperledger.besu.evm.gascalculator.GasCalculator;
3940
import org.hyperledger.besu.evm.processor.ContractCreationProcessor;
4041

4142
/**
@@ -51,6 +52,7 @@ public class TransactionProcessor {
5152
private final ContractCreationProcessor contractCreation;
5253
private final FeatureFlags featureFlags;
5354
private final CodeFactory codeFactory;
55+
private final GasCalculator gasCalculator;
5456

5557
public TransactionProcessor(
5658
@NonNull final FrameBuilder frameBuilder,
@@ -59,14 +61,16 @@ public TransactionProcessor(
5961
@NonNull final CustomMessageCallProcessor messageCall,
6062
@NonNull final ContractCreationProcessor contractCreation,
6163
@NonNull final FeatureFlags featureFlags,
62-
@NonNull final CodeFactory codeFactory) {
64+
@NonNull final CodeFactory codeFactory,
65+
@NonNull final GasCalculator gasCalculator) {
6366
this.frameBuilder = requireNonNull(frameBuilder);
6467
this.frameRunner = requireNonNull(frameRunner);
6568
this.gasCharging = requireNonNull(gasCharging);
6669
this.messageCall = requireNonNull(messageCall);
6770
this.contractCreation = requireNonNull(contractCreation);
6871
this.featureFlags = requireNonNull(featureFlags);
69-
this.codeFactory = codeFactory;
72+
this.codeFactory = requireNonNull(codeFactory);
73+
this.gasCalculator = requireNonNull(gasCalculator);
7074
}
7175

7276
/**
@@ -136,7 +140,8 @@ private HederaEvmTransactionResult processTransactionWithParties(
136140
parties.sender().getAddress(),
137141
parties.receiverAddress(),
138142
gasCharges.intrinsicGas(),
139-
codeFactory);
143+
codeFactory,
144+
gasCalculator);
140145

141146
// Compute the result of running the frame to completion
142147
final var result = frameRunner.runToCompletion(

hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/gas/CustomGasCalculator.java

Lines changed: 170 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,23 @@
99

1010
import com.hedera.node.config.data.CacheConfig;
1111
import edu.umd.cs.findbugs.annotations.NonNull;
12+
import java.math.BigInteger;
13+
import java.util.List;
14+
import java.util.Optional;
1215
import javax.inject.Inject;
1316
import javax.inject.Singleton;
1417
import org.apache.tuweni.bytes.Bytes;
18+
import org.hyperledger.besu.datatypes.AccessListEntry;
19+
import org.hyperledger.besu.datatypes.Address;
20+
import org.hyperledger.besu.datatypes.BlobsWithCommitments;
21+
import org.hyperledger.besu.datatypes.CodeDelegation;
22+
import org.hyperledger.besu.datatypes.Hash;
23+
import org.hyperledger.besu.datatypes.Quantity;
24+
import org.hyperledger.besu.datatypes.Transaction;
25+
import org.hyperledger.besu.datatypes.TransactionType;
26+
import org.hyperledger.besu.datatypes.VersionedHash;
1527
import org.hyperledger.besu.evm.frame.MessageFrame;
16-
import org.hyperledger.besu.evm.gascalculator.CancunGasCalculator;
28+
import org.hyperledger.besu.evm.gascalculator.PragueGasCalculator;
1729

1830
/**
1931
* FUTURE(#12991): GasCalculators for specific EVM versions should be injected based on
@@ -26,10 +38,163 @@
2638
*/
2739
@SuppressWarnings("java:S110")
2840
@Singleton
29-
public class CustomGasCalculator extends CancunGasCalculator {
30-
private static final long TX_DATA_ZERO_COST = 4L;
31-
private static final long ISTANBUL_TX_DATA_NON_ZERO_COST = 16L;
32-
private static final long TX_BASE_COST = 21_000L;
41+
public class CustomGasCalculator extends PragueGasCalculator {
42+
43+
public static Transaction fakeTxnForIntrinsicGasCalc(Bytes payload, boolean isContractCreation) {
44+
return new PlaceholderTransactionForIntrinsicGasCalc(payload, isContractCreation);
45+
}
46+
47+
public static class PlaceholderTransactionForIntrinsicGasCalc implements Transaction {
48+
private final Bytes payload;
49+
private final boolean isContractCreation;
50+
51+
public PlaceholderTransactionForIntrinsicGasCalc(Bytes payload, boolean isContractCreation) {
52+
this.payload = payload;
53+
this.isContractCreation = isContractCreation;
54+
}
55+
56+
@Override
57+
public Hash getHash() {
58+
return null;
59+
}
60+
61+
@Override
62+
public long getNonce() {
63+
return 0;
64+
}
65+
66+
@Override
67+
public Optional<? extends Quantity> getGasPrice() {
68+
return Optional.empty();
69+
}
70+
71+
@Override
72+
public long getGasLimit() {
73+
return 0;
74+
}
75+
76+
@Override
77+
public Optional<? extends Address> getTo() {
78+
return Optional.empty();
79+
}
80+
81+
@Override
82+
public Quantity getValue() {
83+
return null;
84+
}
85+
86+
@Override
87+
public BigInteger getYParity() {
88+
return null;
89+
}
90+
91+
@Override
92+
public BigInteger getV() {
93+
return null;
94+
}
95+
96+
@Override
97+
public BigInteger getR() {
98+
return null;
99+
}
100+
101+
@Override
102+
public BigInteger getS() {
103+
return null;
104+
}
105+
106+
@Override
107+
public Address getSender() {
108+
return null;
109+
}
110+
111+
@Override
112+
public Optional<BigInteger> getChainId() {
113+
return Optional.empty();
114+
}
115+
116+
@Override
117+
public Optional<Bytes> getInit() {
118+
return Optional.empty();
119+
}
120+
121+
@Override
122+
public Optional<Bytes> getData() {
123+
return Optional.empty();
124+
}
125+
126+
@Override
127+
public Bytes getPayload() {
128+
return payload;
129+
}
130+
131+
@Override
132+
public long getPayloadZeroBytes() {
133+
int zeros = 0;
134+
for (int i = 0; i < payload.size(); i++) {
135+
if (payload.get(i) == 0) {
136+
zeros += 1;
137+
}
138+
}
139+
return zeros;
140+
}
141+
142+
@Override
143+
public TransactionType getType() {
144+
return null;
145+
}
146+
147+
@Override
148+
public Optional<List<VersionedHash>> getVersionedHashes() {
149+
return Optional.empty();
150+
}
151+
152+
@Override
153+
public Optional<BlobsWithCommitments> getBlobsWithCommitments() {
154+
return Optional.empty();
155+
}
156+
157+
@Override
158+
public Optional<Address> contractAddress() {
159+
return Optional.empty();
160+
}
161+
162+
@Override
163+
public Optional<List<AccessListEntry>> getAccessList() {
164+
return Optional.empty();
165+
}
166+
167+
@Override
168+
public Bytes encoded() {
169+
return null;
170+
}
171+
172+
@Override
173+
public Bytes encodedPreimage() {
174+
return null;
175+
}
176+
177+
@Override
178+
public int getSize() {
179+
return 0;
180+
}
181+
182+
@Override
183+
public boolean isContractCreation() {
184+
return isContractCreation;
185+
}
186+
187+
@Override
188+
public Optional<List<CodeDelegation>> getCodeDelegationList() {
189+
return Optional.empty();
190+
}
191+
192+
@Override
193+
public int codeDelegationListSize() {
194+
return 0;
195+
}
196+
}
197+
33198
private static final int LOG_CONTRACT_ID_SIZE = 24;
34199
private static final int LOG_TOPIC_SIZE = 32;
35200
private static final int LOG_BLOOM_SIZE = 256;
@@ -42,24 +207,6 @@ public CustomGasCalculator() {
42207
// Dagger2
43208
}
44209

45-
// We won't use the baseline cost for now
46-
// should revisit with the Pectra support epic
47-
@Override
48-
public long transactionIntrinsicGasCost(
49-
final Bytes payload, final boolean isContractCreate, final long baselineCost) {
50-
int zeros = 0;
51-
for (int i = 0; i < payload.size(); i++) {
52-
if (payload.get(i) == 0) {
53-
++zeros;
54-
}
55-
}
56-
final int nonZeros = payload.size() - zeros;
57-
58-
long cost = TX_BASE_COST + TX_DATA_ZERO_COST * zeros + ISTANBUL_TX_DATA_NON_ZERO_COST * nonZeros;
59-
60-
return isContractCreate ? (cost + txCreateExtraGasCost()) : cost;
61-
}
62-
63210
@Override
64211
public long logOperationGasCost(
65212
@NonNull final MessageFrame frame, final long dataOffset, final long dataLength, final int numTopics) {

hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/gas/CustomGasCharging.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static com.hedera.hapi.node.base.ResponseCodeEnum.INSUFFICIENT_GAS;
55
import static com.hedera.hapi.node.base.ResponseCodeEnum.INSUFFICIENT_PAYER_BALANCE;
66
import static com.hedera.hapi.node.base.ResponseCodeEnum.INSUFFICIENT_TX_FEE;
7+
import static com.hedera.node.app.service.contract.impl.exec.gas.CustomGasCalculator.fakeTxnForIntrinsicGasCalc;
78
import static com.hedera.node.app.spi.workflows.HandleException.validateTrue;
89
import static java.util.Objects.requireNonNull;
910

@@ -113,8 +114,8 @@ public GasCharges chargeForGas(
113114
requireNonNull(transaction);
114115

115116
// TODO: Revisit baselineGas with Pectra support epic
116-
final var intrinsicGas =
117-
gasCalculator.transactionIntrinsicGasCost(transaction.evmPayload(), transaction.isCreate(), 0L);
117+
final var intrinsicGas = gasCalculator.transactionIntrinsicGasCost(
118+
fakeTxnForIntrinsicGasCalc(transaction.evmPayload(), transaction.isCreate()), 0L);
118119
if (context.isNoopGasContext()) {
119120
return new GasCharges(intrinsicGas, 0L);
120121
}
@@ -155,7 +156,8 @@ public void chargeGasForAbortedTransaction(
155156
requireNonNull(transaction);
156157

157158
// TODO: Revisit baselineGas with Pectra support epic
158-
final var intrinsicGas = gasCalculator.transactionIntrinsicGasCost(transaction.evmPayload(), false, 0L);
159+
final var intrinsicGas = gasCalculator.transactionIntrinsicGasCost(
160+
fakeTxnForIntrinsicGasCalc(transaction.evmPayload(), false), 0L);
159161

160162
if (transaction.isEthereumTransaction()) {
161163
final var fee = feeForAborted(transaction.relayerId(), context, worldUpdater, intrinsicGas);

0 commit comments

Comments
 (0)