Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
test(all): changes based on the latest protocol proxy updates (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Nov 29, 2023
1 parent 904d3e7 commit 93fc0e2
Show file tree
Hide file tree
Showing 17 changed files with 6,171 additions and 1,555 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
with:
repository: taikoxyz/taiko-mono
path: ${{ env.TAIKO_MONO_DIR }}
ref: update_relayer_eventindexer_post_hooks
ref: based_contestable_zkrollup_improved

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
Expand Down
2 changes: 1 addition & 1 deletion bindings/.githead
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8a27392aead6350fd00d8add2ab0a459808e6160
b20ff337693efc3191a00ff883d258de322fdf3c
6 changes: 6 additions & 0 deletions bindings/encoding/custom_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ func TryParsingCustomError(originalError error) error {
}
}

for _, hookCustomError := range AssignemntHookABI.Errors {
if strings.HasPrefix(hookCustomError.ID.Hex(), errData) {
return errors.New(hookCustomError.Name)
}
}

return originalError
}

Expand Down
9 changes: 7 additions & 2 deletions bindings/encoding/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,9 @@ var (

// Contract ABIs.
var (
TaikoL1ABI *abi.ABI
TaikoL2ABI *abi.ABI
TaikoL1ABI *abi.ABI
TaikoL2ABI *abi.ABI
AssignemntHookABI *abi.ABI
)

func init() {
Expand All @@ -260,6 +261,10 @@ func init() {
if TaikoL2ABI, err = bindings.TaikoL2ClientMetaData.GetAbi(); err != nil {
log.Crit("Get TaikoL2 ABI error", "error", err)
}

if AssignemntHookABI, err = bindings.AssignmentHookMetaData.GetAbi(); err != nil {
log.Crit("Get AssignmentHook ABI error", "error", err)
}
}

// EncodeBlockParams performs the solidity `abi.encode` for the given blockParams.
Expand Down
824 changes: 728 additions & 96 deletions bindings/gen_address_manager.go

Large diffs are not rendered by default.

582 changes: 436 additions & 146 deletions bindings/gen_assignment_hook.go

Large diffs are not rendered by default.

569 changes: 430 additions & 139 deletions bindings/gen_guardian_prover.go

Large diffs are not rendered by default.

1,037 changes: 292 additions & 745 deletions bindings/gen_taiko_l1.go

Large diffs are not rendered by default.

611 changes: 447 additions & 164 deletions bindings/gen_taiko_l2.go

Large diffs are not rendered by default.

3,247 changes: 3,247 additions & 0 deletions bindings/gen_taiko_timelock_controller.go

Large diffs are not rendered by default.

693 changes: 492 additions & 201 deletions bindings/gen_taiko_token.go

Large diffs are not rendered by default.

10 changes: 1 addition & 9 deletions driver/chain_syncer/chain_syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,7 @@ func (s *ChainSyncerTestSuite) TestAheadOfProtocolVerifiedHead2() {
log.Info("LatestVerifiedBlock number", "number", s.s.state.GetLatestVerifiedBlock().ID.Uint64())

// increase evm time to make blocks verifiable.
var result uint64
s.Nil(s.RpcClient.L1RawRPC.CallContext(
context.Background(),
&result,
"evm_increaseTime",
(1024 * time.Hour).Seconds(),
))
s.NotNil(result)
log.Info("EVM time increase", "number", result)
s.IncreaseTime(uint64((1024 * time.Hour).Seconds()))

// interact with TaikoL1 contract to allow for verification of L2 blocks
tx, err := s.s.rpc.TaikoL1.VerifyBlocks(opts, uint64(3))
Expand Down
6 changes: 5 additions & 1 deletion integration_test/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ DEPLOYMENT_JSON=$(cat $TAIKO_MONO_DIR/packages/protocol/deployments/deploy_l1.js
TAIKO_L1_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.taiko' | sed 's/\"//g')
L1_SIGNAL_SERVICE_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.signal_service' | sed 's/\"//g')
TAIKO_TOKEN_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.taiko_token' | sed 's/\"//g')
ADDRESS_MANAGER_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.address_manager' | sed 's/\"//g')
ADDRESS_MANAGER_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.address_manager_for_rollup' | sed 's/\"//g')
GUARDIAN_PROVER_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.guardian_prover' | sed 's/\"//g')
ASSIGNMENT_HOOK_CONTRACT_ADDRESS=$(echo $DEPLOYMENT_JSON | jq '.assignment_hook' | sed 's/\"//g')
TIMELOCK_CONTROLLER=$(echo $DEPLOYMENT_JSON | jq '.timelock_controller' | sed 's/\"//g')

trap "docker compose -f $TESTNET_CONFIG down -v" EXIT INT KILL ERR

Expand All @@ -41,6 +42,7 @@ echo "TAIKO_TOKEN_CONTRACT_ADDRESS: $TAIKO_TOKEN_CONTRACT_ADDRESS"
echo "L1_SIGNAL_SERVICE_CONTRACT_ADDRESS: $L1_SIGNAL_SERVICE_CONTRACT_ADDRESS"
echo "GUARDIAN_PROVER_CONTRACT_ADDRESS: $GUARDIAN_PROVER_CONTRACT_ADDRESS"
echo "ASSIGNMENT_HOOK_CONTRACT_ADDRESS: $ASSIGNMENT_HOOK_CONTRACT_ADDRESS"
echo "TIMELOCK_CONTROLLER: $TIMELOCK_CONTROLLER"

if [ "$RUN_TESTS" == "true" ]; then
L1_NODE_HTTP_ENDPOINT=http://localhost:18545 \
Expand All @@ -52,10 +54,12 @@ if [ "$RUN_TESTS" == "true" ]; then
TAIKO_L2_ADDRESS=0x1670010000000000000000000000000000010001 \
TAIKO_TOKEN_ADDRESS=$TAIKO_TOKEN_CONTRACT_ADDRESS \
ASSIGNMENT_HOOK_ADDRESS=$ASSIGNMENT_HOOK_CONTRACT_ADDRESS \
TIMELOCK_CONTROLLER=$TIMELOCK_CONTROLLER \
ADDRESS_MANAGER_CONTRACT_ADDRESS=$ADDRESS_MANAGER_CONTRACT_ADDRESS \
GUARDIAN_PROVER_CONTRACT_ADDRESS=$GUARDIAN_PROVER_CONTRACT_ADDRESS \
L1_SIGNAL_SERVICE_CONTRACT_ADDRESS=$L1_SIGNAL_SERVICE_CONTRACT_ADDRESS \
L1_CONTRACT_OWNER_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
L1_SECURITY_COUNCIL_PRIVATE_KEY=dbda1821b80551c9d65939329250298aa3472ba22feea921c0cf5d620ea67b97 \
L1_PROPOSER_PRIVATE_KEY=ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
L2_SUGGESTED_FEE_RECIPIENT=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
L1_PROVER_PRIVATE_KEY=59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d \
Expand Down
12 changes: 7 additions & 5 deletions integration_test/nodes/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,20 @@ cd $TAIKO_MONO_DIR/packages/protocol &&
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
GUARDIAN_PROVERS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8,0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266,0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC,0x90F79bf6EB2c4f870365E785982E1f101E93b906,0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65 \
OWNER=0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC \
TAIKO_L2_ADDRESS=0x1000777700000000000000000000000000000001 \
L2_SIGNAL_SERVICE=0x1000777700000000000000000000000000000007 \
SINGLETON_SIGNAL_SERVICE=0x0000000000000000000000000000000000000000 \
SINGLETON_BRIDGE=0x0000000000000000000000000000000000000000 \
TAIKO_L2_ADDRESS=0x1670010000000000000000000000000000010001 \
L2_SIGNAL_SERVICE=0x1670010000000000000000000000000000010005 \
SECURITY_COUNCIL=0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f \
SHARED_ADDRESS_MANAGER=0x0000000000000000000000000000000000000000 \
PROPOSER=0x0000000000000000000000000000000000000000 \
PROPOSER_ONE=0x0000000000000000000000000000000000000000 \
TAIKO_TOKEN_PREMINT_RECIPIENT=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
TIER_PROVIDER=0x0 \
TAIKO_TOKEN_NAME="Taiko Token Test" \
TAIKO_TOKEN_SYMBOL=TTKOt \
L2_GENESIS_HASH=$L2_GENESIS_HASH \
forge script script/DeployOnL1.s.sol:DeployOnL1 \
--fork-url http://localhost:18545 \
--broadcast \
--ffi \
-vvvvv \
--private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
--block-gas-limit 100000000
23 changes: 8 additions & 15 deletions proposer/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,21 +370,14 @@ func (p *Proposer) sendProposeBlockTx(
}
}

state, err := p.rpc.TaikoL1.State(&bind.CallOpts{
Context: ctx,
})

if err != nil {
return nil, err
}

var parentMetaHash [32]byte = [32]byte{}
if p.cfg.IncludeParentMetaHash {
parent, err := p.rpc.TaikoL1.GetBlock(&bind.CallOpts{
Context: ctx,
},
state.SlotB.NumBlocks-1,
)
state, err := p.rpc.TaikoL1.State(&bind.CallOpts{Context: ctx})
if err != nil {
return nil, err
}

parent, err := p.rpc.TaikoL1.GetBlock(&bind.CallOpts{Context: ctx}, state.SlotB.NumBlocks-1)
if err != nil {
return nil, err
}
Expand All @@ -398,7 +391,7 @@ func (p *Proposer) sendProposeBlockTx(
// TODO: flag for additional hook addresses and data.
hookInputData, err := encoding.EncodeAssignmentHookInput(&encoding.AssignmentHookInput{
Assignment: assignment,
Tip: big.NewInt(0), // TODO: flag for tip
Tip: common.Big0, // TODO: flag for tip
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -469,7 +462,7 @@ func (p *Proposer) ProposeTxList(
maxFee,
isReplacement,
); err != nil {
log.Warn("Failed to send propose block transaction", "error", encoding.TryParsingCustomError(err))
log.Warn("Failed to send taikoL1.proposeBlock transaction", "error", encoding.TryParsingCustomError(err))
if strings.Contains(err.Error(), core.ErrNonceTooLow.Error()) {
return nil
}
Expand Down
4 changes: 4 additions & 0 deletions scripts/gen_bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ cat ${TAIKO_MONO_DIR}/packages/protocol/out/AssignmentHook.sol/AssignmentHook.js
jq .abi |
${ABIGEN_BIN} --abi - --type AssignmentHook --pkg bindings --out $DIR/../bindings/gen_assignment_hook.go

cat ${TAIKO_MONO_DIR}/packages/protocol/out/TaikoTimelockController.sol/TaikoTimelockController.json |
jq .abi |
${ABIGEN_BIN} --abi - --type TaikoTimelockController --pkg bindings --out $DIR/../bindings/gen_taiko_timelock_controller.go

git -C ${TAIKO_MONO_DIR} log --format="%H" -n 1 >./bindings/.githead

echo "🍻 Go contract bindings generated!"
89 changes: 59 additions & 30 deletions testutils/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,49 +88,24 @@ func (s *ClientTestSuite) SetupTest() {

if allowance.Cmp(common.Big0) == 0 {
// Do not verify zk && sgx proofs in tests.
addressManager, err := bindings.NewAddressManager(
common.HexToAddress(os.Getenv("ADDRESS_MANAGER_CONTRACT_ADDRESS")),
rpcCli.L1,
)
s.Nil(err)

chainID, err := rpcCli.L1.ChainID(context.Background())
securityConcilPrivKey, err := crypto.ToECDSA(common.Hex2Bytes(os.Getenv("L1_SECURITY_COUNCIL_PRIVATE_KEY")))
s.Nil(err)
s.setAddress(securityConcilPrivKey, rpc.StringToBytes32("tier_sgx_and_pse_zkevm"), common.Address{})
s.setAddress(securityConcilPrivKey, rpc.StringToBytes32("tier_sgx"), common.Address{})

ownerPrivKey, err := crypto.ToECDSA(common.Hex2Bytes(os.Getenv("L1_CONTRACT_OWNER_PRIVATE_KEY")))
s.Nil(err)

opts, err := bind.NewKeyedTransactorWithChainID(ownerPrivKey, rpcCli.L1ChainID)
s.Nil(err)

tx, err := addressManager.SetAddress(
opts,
chainID.Uint64(),
rpc.StringToBytes32("tier_sgx_and_pse_zkevm"),
common.Address{},
)
s.Nil(err)
_, err = rpc.WaitReceipt(context.Background(), rpcCli.L1, tx)
s.Nil(err)

tx, err = addressManager.SetAddress(opts, chainID.Uint64(), rpc.StringToBytes32("tier_sgx"), common.Address{})
s.Nil(err)
_, err = rpc.WaitReceipt(context.Background(), rpcCli.L1, tx)
s.Nil(err)

// Transfer some tokens to provers.
balance, err := rpcCli.TaikoToken.BalanceOf(nil, crypto.PubkeyToAddress(ownerPrivKey.PublicKey))
s.Nil(err)
s.Greater(balance.Cmp(common.Big0), 0)

opts, err = bind.NewKeyedTransactorWithChainID(ownerPrivKey, rpcCli.L1ChainID)
opts, err := bind.NewKeyedTransactorWithChainID(ownerPrivKey, rpcCli.L1ChainID)
s.Nil(err)
proverBalance := new(big.Int).Div(balance, common.Big2)
if proverBalance.Cmp(common.Big0) == 1 {
tx, err = rpcCli.TaikoToken.Transfer(
opts,
crypto.PubkeyToAddress(l1ProverPrivKey.PublicKey), proverBalance,
)
tx, err := rpcCli.TaikoToken.Transfer(opts, crypto.PubkeyToAddress(l1ProverPrivKey.PublicKey), proverBalance)
s.Nil(err)
_, err = rpc.WaitReceipt(context.Background(), rpcCli.L1, tx)
s.Nil(err)
Expand Down Expand Up @@ -162,6 +137,54 @@ func (s *ClientTestSuite) SetupTest() {
s.NotEmpty(s.testnetL1SnapshotID)
}

func (s *ClientTestSuite) setAddress(ownerPrivKey *ecdsa.PrivateKey, name [32]byte, address common.Address) {
var (
salt = RandomHash()
)

controller, err := bindings.NewTaikoTimelockController(
common.HexToAddress(os.Getenv("TIMELOCK_CONTROLLER")),
s.RpcClient.L1,
)
s.Nil(err)

opts, err := bind.NewKeyedTransactorWithChainID(ownerPrivKey, s.RpcClient.L1ChainID)
s.Nil(err)

addressManagerABI, err := bindings.AddressManagerMetaData.GetAbi()
s.Nil(err)

data, err := addressManagerABI.Pack("setAddress", s.RpcClient.L1ChainID.Uint64(), name, address)
s.Nil(err)

tx, err := controller.Schedule(
opts,
common.HexToAddress(os.Getenv("ADDRESS_MANAGER_CONTRACT_ADDRESS")),
common.Big0,
data,
[32]byte{},
salt,
common.Big0,
)
s.Nil(err)

_, err = rpc.WaitReceipt(context.Background(), s.RpcClient.L1, tx)
s.Nil(err)

tx, err = controller.Execute(
opts,
common.HexToAddress(os.Getenv("ADDRESS_MANAGER_CONTRACT_ADDRESS")),
common.Big0,
data,
[32]byte{},
salt,
)
s.Nil(err)

_, err = rpc.WaitReceipt(context.Background(), s.RpcClient.L1, tx)
s.Nil(err)
}

func (s *ClientTestSuite) TearDownTest() {
var revertRes bool
s.Nil(s.RpcClient.L1RawRPC.CallContext(context.Background(), &revertRes, "evm_revert", s.testnetL1SnapshotID))
Expand All @@ -174,3 +197,9 @@ func (s *ClientTestSuite) TearDownTest() {
func (s *ClientTestSuite) SetL1Automine(automine bool) {
s.Nil(s.RpcClient.L1RawRPC.CallContext(context.Background(), nil, "evm_setAutomine", automine))
}

func (s *ClientTestSuite) IncreaseTime(time uint64) {
var result uint64
s.Nil(s.RpcClient.L1RawRPC.CallContext(context.Background(), &result, "evm_increaseTime", time))
s.NotNil(result)
}

0 comments on commit 93fc0e2

Please sign in to comment.