-
Notifications
You must be signed in to change notification settings - Fork 132
feat: callDelegation testing for different targets - no collision #2370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
64097be
feat: targetIsSmc
amkCha a1442f0
feat: delegated to prc
amkCha 5d00446
feat: add test on eoa, self delegation
amkCha 224f44a
doc: schema + clean up
amkCha 008705f
feat: add simple EOA to EOA
amkCha c5b70bf
feat: disable tests
amkCha 75cdbb2
feat: add utils for prefix and code delegation + rm unused account
amkCha d57bed7
feat: add a note a delegation loop
amkCha cee5b29
fix spotless
amkCha 7515764
feat: only one eoa address + timeout fast replay to 30min
amkCha e24f62d
Merge branch 'main' into 2132-call-to-delegated-accounts-direct
amkCha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
262 changes: 262 additions & 0 deletions
262
...est/java/net/consensys/linea/zktracer/instructionprocessing/callTests/CallDelegation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,262 @@ | ||
| package net.consensys.linea.zktracer.instructionprocessing.callTests; | ||
|
|
||
| import static net.consensys.linea.zktracer.Utils.*; | ||
|
|
||
| import java.util.List; | ||
| import net.consensys.linea.reporting.TracerTestBase; | ||
| import net.consensys.linea.testing.ToyAccount; | ||
| import net.consensys.linea.testing.ToyExecutionEnvironmentV2; | ||
| import net.consensys.linea.testing.ToyTransaction; | ||
| import org.apache.tuweni.bytes.Bytes; | ||
| import org.hyperledger.besu.crypto.KeyPair; | ||
| import org.hyperledger.besu.crypto.SECP256K1; | ||
| import org.hyperledger.besu.datatypes.Address; | ||
| import org.hyperledger.besu.datatypes.Hash; | ||
| import org.hyperledger.besu.datatypes.Wei; | ||
| import org.hyperledger.besu.ethereum.core.Transaction; | ||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.TestInfo; | ||
|
|
||
| /* | ||
|
|
||
| CALL DELEGATION TEST | ||
|
|
||
| We test code delegation to different types of targets | ||
| (1) TARGET is a Smart Contract | ||
| CALL | ||
| --------> - EOA | ||
| |---------------> Smart Contract | ||
| (delegated to) | ||
| (2) TARGET is an EOA delegated to another EOA | ||
| CALL | ||
| --------> - EOA1 | ||
| |---------------> EOA2 | ||
| (delegated to) | ||
| (3) TARGET is an EOA delegated to itself | ||
| CALL | ||
| --------> - EOA <---------| | ||
| |-------------| | ||
| (delegated to) | ||
| (4) TARGET is an EOA delegated to another EOA delegated to a Smart Contract | ||
| CALL | ||
| --------> - EOA1 | ||
| |---------------> EOA2 | ||
| (delegated to) |---------------> Smart Contract | ||
| (delegated to) | ||
| Note : to avoid a loop of delegations, exec client retrieve only the first code and then stop following the delegation chain. | ||
| Hence, the Smart Contract is never reached and its code never executed | ||
| (5) TARGET is a precompile | ||
| CALL | ||
| --------> - EOA | ||
| |---------------> PRC, here P256_VERIFY | ||
| (delegated to) | ||
| */ | ||
|
|
||
| // TODO: reenable once 7702 feature is merged | ||
| @Disabled | ||
| public class CallDelegation extends TracerTestBase { | ||
|
|
||
| /* Smart contract byte code | ||
| ADDRESS | ||
| SELFBALANCE | ||
| CODESIZE | ||
| CALLER | ||
| CALLVALUE | ||
| GAS | ||
| */ | ||
|
|
||
| final String smcBytecode = "0x30473833345a"; | ||
| final ToyAccount smcAccount = | ||
| ToyAccount.builder() | ||
| .address(Address.fromHexString("1234")) | ||
| .nonce(90) | ||
| .code(Bytes.concatenate(Bytes.fromHexString(smcBytecode))) | ||
| .build(); | ||
| final String delegationCodeToSmc = addDelegationPrefixToAccount(smcAccount); | ||
|
|
||
| // Sender account setting | ||
| final KeyPair keyPair = new SECP256K1().generateKeyPair(); | ||
| final Address senderAddress = | ||
| Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); | ||
| final ToyAccount senderAccount = | ||
| ToyAccount.builder() | ||
| .balance(Wei.of(1_550_000_000_000L)) | ||
| .nonce(23) | ||
| .address(senderAddress) | ||
| .build(); | ||
|
|
||
| /* | ||
| (1) TARGET is a Smart Contract | ||
| CALL | ||
| --------> - EOA | ||
| |---------------> Smart Contract | ||
| (delegated to) | ||
| */ | ||
| @Test | ||
| void EOADelegatedToSmc(TestInfo testInfo) { | ||
|
|
||
| ToyAccount eoaDelegatedToSmc = | ||
| ToyAccount.builder() | ||
| .address(Address.fromHexString("ca11ee")) // identity caller | ||
| .nonce(99) | ||
| .code(Bytes.concatenate(Bytes.fromHexString(delegationCodeToSmc))) | ||
| .build(); | ||
|
|
||
| Transaction tx = | ||
| ToyTransaction.builder() | ||
| .sender(senderAccount) | ||
| .keyPair(keyPair) | ||
| .to(eoaDelegatedToSmc) | ||
| .build(); | ||
|
|
||
| ToyExecutionEnvironmentV2.builder(chainConfig, testInfo) | ||
| .accounts(List.of(senderAccount, smcAccount, eoaDelegatedToSmc)) | ||
| .transaction(tx) | ||
| .build() | ||
| .run(); | ||
| } | ||
|
|
||
| /* | ||
| (2) TARGET is an EOA delegated to another EOA | ||
| CALL | ||
| --------> - EOA1 | ||
| |---------------> EOA2 | ||
| (delegated to) | ||
| */ | ||
| @Test | ||
| void EOA1DelegatedEOA2(TestInfo testInfo) { | ||
|
|
||
| ToyAccount eoa2 = | ||
| ToyAccount.builder() | ||
| .address(Address.fromHexString("ca11ee2")) // identity caller | ||
| .nonce(80) | ||
| .build(); | ||
|
|
||
| String delegationCodeToEoa2 = addDelegationPrefixToAccount(eoa2); | ||
|
|
||
| ToyAccount eoa1DelegatedToEoa2 = | ||
| ToyAccount.builder() | ||
| .address(Address.fromHexString("ca11ee1")) // identity caller | ||
| .nonce(99) | ||
| .code(Bytes.concatenate(Bytes.fromHexString(delegationCodeToEoa2))) | ||
| .build(); | ||
|
|
||
| Transaction tx = | ||
| ToyTransaction.builder() | ||
| .sender(senderAccount) | ||
| .keyPair(keyPair) | ||
| .to(eoa1DelegatedToEoa2) | ||
| .build(); | ||
|
|
||
| ToyExecutionEnvironmentV2.builder(chainConfig, testInfo) | ||
| .accounts(List.of(senderAccount, eoa1DelegatedToEoa2, eoa2)) | ||
| .transaction(tx) | ||
| .build() | ||
| .run(); | ||
| } | ||
|
|
||
| /* | ||
| (3) TARGET is an EOA delegated to itself | ||
| CALL | ||
| --------> - EOA <---------| | ||
| |-------------| | ||
| (delegated to) | ||
| */ | ||
| @Test | ||
| void EOADelegatedToItself(TestInfo testInfo) { | ||
|
|
||
| Address eoaAddress = Address.fromHexString("ca11ee1"); | ||
|
|
||
| String delegationCodeToEoa = addDelegationPrefixToAddress(eoaAddress); | ||
|
|
||
| ToyAccount eoa = | ||
| ToyAccount.builder() | ||
| .address(Address.fromHexString("ca11ee1")) // identity caller | ||
amkCha marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .nonce(99) | ||
| .code(Bytes.concatenate(Bytes.fromHexString(delegationCodeToEoa))) | ||
| .build(); | ||
|
|
||
| Transaction tx = | ||
| ToyTransaction.builder().sender(senderAccount).keyPair(keyPair).to(eoa).build(); | ||
|
|
||
| ToyExecutionEnvironmentV2.builder(chainConfig, testInfo) | ||
| .accounts(List.of(senderAccount, eoa)) | ||
| .transaction(tx) | ||
| .build() | ||
| .run(); | ||
| } | ||
|
|
||
| /* | ||
| (4) TARGET is an EOA delegated to another EOA | ||
| CALL | ||
| --------> - EOA1 | ||
| |---------------> EOA2 | ||
| (delegated to) |---------------> Smart Contract | ||
| (delegated to) | ||
| */ | ||
| @Test | ||
| void EOA1DelegatedEOA2DelegatedToSmc(TestInfo testInfo) { | ||
|
|
||
| ToyAccount eoa2DelegatedToSmc = | ||
| ToyAccount.builder() | ||
| .address(Address.fromHexString("ca11ee2")) // identity caller | ||
| .nonce(80) | ||
| .code(Bytes.concatenate(Bytes.fromHexString(delegationCodeToSmc))) | ||
| .build(); | ||
|
|
||
| String delegationCodeToEoa2 = addDelegationPrefixToAccount(eoa2DelegatedToSmc); | ||
|
|
||
| ToyAccount eoa1DelegatedToEoa2 = | ||
| ToyAccount.builder() | ||
| .address(Address.fromHexString("ca11ee1")) // identity caller | ||
| .nonce(99) | ||
| .code(Bytes.concatenate(Bytes.fromHexString(delegationCodeToEoa2))) | ||
| .build(); | ||
|
|
||
| Transaction tx = | ||
| ToyTransaction.builder() | ||
| .sender(senderAccount) | ||
| .keyPair(keyPair) | ||
| .to(eoa1DelegatedToEoa2) | ||
| .build(); | ||
|
|
||
| ToyExecutionEnvironmentV2.builder(chainConfig, testInfo) | ||
| .accounts(List.of(senderAccount, smcAccount, eoa1DelegatedToEoa2, eoa2DelegatedToSmc)) | ||
| .transaction(tx) | ||
| .build() | ||
| .run(); | ||
| } | ||
|
|
||
| /* | ||
| (5) TARGET is a precompile | ||
| CALL | ||
| --------> - EOA | ||
| |---------------> PRC, here P256_VERIFY | ||
| (delegated to) | ||
| */ | ||
| @Test | ||
| void targetIsPrc(TestInfo testInfo) { | ||
|
|
||
| String delegationCodeToP256Verify = addDelegationPrefixToAddress(Address.P256_VERIFY); | ||
| ToyAccount eoaDelegatedToPrc = | ||
| ToyAccount.builder() | ||
| .address(Address.fromHexString("ca11ee")) // identity caller | ||
| .nonce(99) | ||
| .code(Bytes.concatenate(Bytes.fromHexString(delegationCodeToP256Verify))) | ||
| .build(); | ||
|
|
||
| Transaction tx = | ||
| ToyTransaction.builder() | ||
| .sender(senderAccount) | ||
| .keyPair(keyPair) | ||
| .to(eoaDelegatedToPrc) | ||
| .build(); | ||
|
|
||
| ToyExecutionEnvironmentV2.builder(chainConfig, testInfo) | ||
| .accounts(List.of(senderAccount, eoaDelegatedToPrc)) | ||
| .transaction(tx) | ||
| .build() | ||
| .run(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.