Skip to content

Commit 4558182

Browse files
feat: Add HIP-1340 protobuf changes (#24176)
Signed-off-by: Lukasz Gasior <lukasz.gasior@swirldslabs.com>
1 parent e52f449 commit 4558182

File tree

11 files changed

+108
-4
lines changed

11 files changed

+108
-4
lines changed

hapi/hedera-protobuf-java-api/src/main/proto/services/crypto_create.proto

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,17 @@ message CryptoCreateTransactionBody {
204204
* Details of hooks to add immediately after creating this account.
205205
*/
206206
repeated com.hedera.hapi.node.hooks.HookCreationDetails hook_creation_details = 19;
207+
208+
/**
209+
* The initial delegated contract address to set for the new account.
210+
* <p>
211+
* If set, the value MUST be 20 bytes long (EVM address).
212+
* A value of `0x0000000000000000000000000000000000000000` will be ignored.
213+
*
214+
* If this field is set on the account, anytime a call is made to the account's address
215+
* (either an EVM call within HSCS or a child call dispatched by CryptoTransfer)
216+
* the EVM code of the contract referenced by `delegation_address` will be
217+
* executed in the context of the account.
218+
*/
219+
bytes delegation_address = 20;
207220
}

hapi/hedera-protobuf-java-api/src/main/proto/services/crypto_get_info.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,16 @@ message CryptoGetInfoResponse {
269269
* Staking information for this account.
270270
*/
271271
StakingInfo staking_info = 22;
272+
273+
/**
274+
* The delegated contract address set for this account.
275+
* <p>
276+
* If this field is set on the account, anytime a call is made to the account's address
277+
* (either an EVM call within HSCS or a child call dispatched by CryptoTransfer)
278+
* the EVM code of the contract referenced by `delegation_address` will be
279+
* executed in the context of the account.
280+
*/
281+
bytes delegation_address = 23;
272282
}
273283

274284
/**

hapi/hedera-protobuf-java-api/src/main/proto/services/crypto_update.proto

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,19 @@ message CryptoUpdateTransactionBody {
226226
* The hooks to create for the account.
227227
*/
228228
repeated com.hedera.hapi.node.hooks.HookCreationDetails hook_creation_details = 20;
229+
230+
/**
231+
* The delegated contract address to set for the account.
232+
* <p>
233+
* If this field is unset (empty), no change is made to account's `delegation_address`.
234+
* If set, the value MUST be 20 bytes long (EVM address).
235+
* Submitting a value of `0x0000000000000000000000000000000000000000` will clear
236+
* account's current `delegation_address`.
237+
*
238+
* If this field is set on the account, anytime a call is made to the account's address
239+
* (either an EVM call within HSCS or a child call dispatched by CryptoTransfer)
240+
* the EVM code of the contract referenced by `delegation_address` will be
241+
* executed in the context of the account.
242+
*/
243+
bytes delegation_address = 21;
229244
}

hapi/hedera-protobuf-java-api/src/main/proto/services/state/token/account.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,16 @@ message Account {
481481
* The number of storage slots in use by this account's EVM hooks.
482482
*/
483483
uint64 number_evm_hook_storage_slots = 38;
484+
485+
/**
486+
* The delegated contract address set for this account.
487+
* <p>
488+
* If this field is set on the account, anytime a call is made to the account's address
489+
* (either an EVM call within HSCS or a child call dispatched by CryptoTransfer)
490+
* the EVM code of the contract referenced by `delegation_address` will be
491+
* executed in the context of the account.
492+
*/
493+
bytes delegation_address = 39;
484494
}
485495

486496
/**

hedera-node/hedera-network-admin-service-impl/src/test/java/com/hedera/node/app/service/networkadmin/impl/test/handlers/NetworkAdminHandlerTestBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ protected void givenValidAccount(
460460
0,
461461
0L,
462462
0L,
463-
0L);
463+
0L,
464+
Bytes.EMPTY);
464465
}
465466

466467
protected void givenFungibleTokenRelation() {

hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/handlers/CryptoCreateHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static com.hedera.hapi.node.base.ResponseCodeEnum.KEY_NOT_PROVIDED;
1818
import static com.hedera.hapi.node.base.ResponseCodeEnum.KEY_REQUIRED;
1919
import static com.hedera.hapi.node.base.ResponseCodeEnum.MAX_ENTITIES_IN_PRICE_REGIME_HAVE_BEEN_CREATED;
20+
import static com.hedera.hapi.node.base.ResponseCodeEnum.NOT_SUPPORTED;
2021
import static com.hedera.hapi.node.base.ResponseCodeEnum.PROXY_ACCOUNT_ID_FIELD_IS_DEPRECATED;
2122
import static com.hedera.node.app.hapi.fees.usage.SingletonUsageProperties.USAGE_PROPERTIES;
2223
import static com.hedera.node.app.hapi.fees.usage.crypto.CryptoOpsUsage.CREATE_SLOT_MULTIPLIER;
@@ -128,6 +129,8 @@ public void pureChecks(@NonNull final PureChecksContext context) throws PreCheck
128129
requireNonNull(context);
129130
final var txn = context.body();
130131
final var op = txn.cryptoCreateAccountOrThrow();
132+
// HIP-1340 isn't supported yet
133+
validateTruePreCheck(op.delegationAddress().length() == 0, NOT_SUPPORTED);
131134
// Note: validation lives here for now but should take place in handle in the future
132135
validateTruePreCheck(op.hasAutoRenewPeriod(), INVALID_RENEWAL_PERIOD);
133136
validateTruePreCheck(op.autoRenewPeriodOrThrow().seconds() >= 0, INVALID_RENEWAL_PERIOD);

hedera-node/hedera-token-service-impl/src/main/java/com/hedera/node/app/service/token/impl/handlers/CryptoUpdateHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_ACCOUNT_ID;
1010
import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_ADMIN_KEY;
1111
import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_MAX_AUTO_ASSOCIATIONS;
12+
import static com.hedera.hapi.node.base.ResponseCodeEnum.NOT_SUPPORTED;
1213
import static com.hedera.hapi.node.base.ResponseCodeEnum.PROXY_ACCOUNT_ID_FIELD_IS_DEPRECATED;
1314
import static com.hedera.hapi.node.base.ResponseCodeEnum.REQUESTED_NUM_AUTOMATIC_ASSOCIATIONS_EXCEEDS_ASSOCIATION_LIMIT;
1415
import static com.hedera.node.app.hapi.fees.pricing.BaseOperationUsage.THREE_MONTHS_IN_SECONDS;
@@ -93,6 +94,8 @@ public void pureChecks(@NonNull final PureChecksContext context) throws PreCheck
9394
requireNonNull(context);
9495
final var txn = context.body();
9596
final var op = txn.cryptoUpdateAccountOrThrow();
97+
// HIP-1340 isn't supported yet
98+
validateTruePreCheck(op.delegationAddress().length() == 0, NOT_SUPPORTED);
9699
validateTruePreCheck(op.hasAccountIDToUpdate(), ACCOUNT_ID_DOES_NOT_EXIST);
97100
validateFalsePreCheck(
98101
op.hasProxyAccountID() && !op.proxyAccountID().equals(AccountID.DEFAULT),

hedera-node/hedera-token-service-impl/src/test/java/com/hedera/node/app/service/token/impl/test/handlers/CryptoCreateHandlerTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_SEND_RECORD_THRESHOLD;
1515
import static com.hedera.hapi.node.base.ResponseCodeEnum.KEY_REQUIRED;
1616
import static com.hedera.hapi.node.base.ResponseCodeEnum.MEMO_TOO_LONG;
17+
import static com.hedera.hapi.node.base.ResponseCodeEnum.NOT_SUPPORTED;
1718
import static com.hedera.hapi.node.base.ResponseCodeEnum.PROXY_ACCOUNT_ID_FIELD_IS_DEPRECATED;
1819
import static com.hedera.hapi.node.base.SubType.DEFAULT;
1920
import static com.hedera.node.app.service.token.impl.schemas.V0490TokenSchema.ACCOUNTS_STATE_ID;
@@ -194,6 +195,17 @@ void whenInitialBalanceIsNegative() {
194195
assertThat(INVALID_INITIAL_BALANCE).isEqualTo(msg.responseCode());
195196
}
196197

198+
@Test
199+
@DisplayName("pureChecks fail when delegation address is not empty")
200+
void whenDelegationAddressIsNonEmpty() {
201+
txn = new CryptoCreateBuilder()
202+
.withDelegationAddress(Bytes.fromHex("cafebabe"))
203+
.build();
204+
given(pureChecksContext.body()).willReturn(txn);
205+
final var msg = assertThrows(PreCheckException.class, () -> subject.pureChecks(pureChecksContext));
206+
assertThat(NOT_SUPPORTED).isEqualTo(msg.responseCode());
207+
}
208+
197209
@Test
198210
@DisplayName("pureChecks fail without auto-renew period specified")
199211
void whenNoAutoRenewPeriodSpecified() {
@@ -812,6 +824,8 @@ private class CryptoCreateBuilder {
812824

813825
private String memo = null;
814826

827+
private Bytes delegationAddress;
828+
815829
private CryptoCreateBuilder() {}
816830

817831
public TransactionBody build() {
@@ -848,6 +862,9 @@ public TransactionBody build() {
848862
if (maxAutoAssociations != -1) {
849863
createTxnBody.maxAutomaticTokenAssociations(maxAutoAssociations);
850864
}
865+
if (delegationAddress != null) {
866+
createTxnBody.delegationAddress(delegationAddress);
867+
}
851868

852869
return TransactionBody.newBuilder()
853870
.transactionID(transactionID)
@@ -925,5 +942,10 @@ public CryptoCreateBuilder withMaxAutoAssociations(final int maxAutoAssociations
925942
this.maxAutoAssociations = maxAutoAssociations;
926943
return this;
927944
}
945+
946+
public CryptoCreateBuilder withDelegationAddress(final Bytes delegationAddress) {
947+
this.delegationAddress = delegationAddress;
948+
return this;
949+
}
928950
}
929951
}

hedera-node/hedera-token-service-impl/src/test/java/com/hedera/node/app/service/token/impl/test/handlers/CryptoUpdateHandlerTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_EXPIRATION_TIME;
1313
import static com.hedera.hapi.node.base.ResponseCodeEnum.INVALID_STAKING_ID;
1414
import static com.hedera.hapi.node.base.ResponseCodeEnum.MEMO_TOO_LONG;
15+
import static com.hedera.hapi.node.base.ResponseCodeEnum.NOT_SUPPORTED;
1516
import static com.hedera.hapi.node.base.ResponseCodeEnum.OK;
1617
import static com.hedera.hapi.node.base.ResponseCodeEnum.PROXY_ACCOUNT_ID_FIELD_IS_DEPRECATED;
1718
import static com.hedera.hapi.node.base.ResponseCodeEnum.REQUESTED_NUM_AUTOMATIC_ASSOCIATIONS_EXCEEDS_ASSOCIATION_LIMIT;
@@ -70,6 +71,7 @@
7071
import com.hedera.node.config.ConfigProvider;
7172
import com.hedera.node.config.VersionedConfigImpl;
7273
import com.hedera.node.config.testfixtures.HederaTestConfigBuilder;
74+
import com.hedera.pbj.runtime.io.buffer.Bytes;
7375
import com.swirlds.config.api.Configuration;
7476
import java.util.List;
7577
import java.util.Map;
@@ -167,6 +169,18 @@ void cryptoUpdateMissingAccountID() throws PreCheckException {
167169
assertThrowsPreCheck(() -> subject.pureChecks(pureChecksContext), ACCOUNT_ID_DOES_NOT_EXIST);
168170
}
169171

172+
@Test
173+
void cryptoUpdateWithDelegationAddressIsRejected() {
174+
final var txn = new CryptoUpdateBuilder()
175+
.withKey(key)
176+
.withDelegationAddress(Bytes.fromHex("cafebabe"))
177+
.build();
178+
179+
given(pureChecksContext.body()).willReturn(txn);
180+
181+
assertThrowsPreCheck(() -> subject.pureChecks(pureChecksContext), NOT_SUPPORTED);
182+
}
183+
170184
@Test
171185
void cryptoUpdateNewSignatureKeyWaivedVanilla() throws PreCheckException {
172186
final var txn = new CryptoUpdateBuilder().withKey(key).build();
@@ -910,6 +924,7 @@ private class CryptoUpdateBuilder {
910924
private String memo;
911925
private Key opKey;
912926
private AccountID target = updateAccountId;
927+
private Bytes delegationAddress;
913928

914929
public CryptoUpdateBuilder() {}
915930

@@ -960,6 +975,10 @@ public TransactionBody build() {
960975
builder.key(opKey);
961976
}
962977

978+
if (delegationAddress != null) {
979+
builder.delegationAddress(delegationAddress);
980+
}
981+
963982
return TransactionBody.newBuilder()
964983
.transactionID(transactionID)
965984
.cryptoUpdateAccount(builder.build())
@@ -1047,6 +1066,11 @@ public CryptoUpdateBuilder withPayer(AccountID payer) {
10471066
this.payer = payer;
10481067
return this;
10491068
}
1069+
1070+
public CryptoUpdateBuilder withDelegationAddress(Bytes delegationAddress) {
1071+
this.delegationAddress = delegationAddress;
1072+
return this;
1073+
}
10501074
}
10511075

10521076
private void updateReadableAccountStore(Map<Long, Account> accountsToAdd) {

hedera-node/hedera-token-service-impl/src/test/java/com/hedera/node/app/service/token/impl/test/handlers/util/CryptoHandlerTestBase.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ protected Account givenValidAccount(final long accountNum) {
400400
0,
401401
0L,
402402
0L,
403-
0L);
403+
0L,
404+
Bytes.EMPTY);
404405
}
405406

406407
protected void givenValidContract() {
@@ -441,7 +442,8 @@ protected void givenValidContract() {
441442
0,
442443
0L,
443444
0L,
444-
0L);
445+
0L,
446+
Bytes.EMPTY);
445447
}
446448

447449
/**

0 commit comments

Comments
 (0)