From 985b4f15d2f9046b22c9e7cfd0a196bccd0b2045 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Mon, 16 Sep 2024 15:16:02 +0400 Subject: [PATCH] New constant bridge address in EL: 0x0000000000000000000000000000000000006a7e --- docker/genesis-testnet.json | 2 +- local-network/configs/ec-common/genesis.json | 2 +- local-network/deploy/src/common-settings.ts | 2 +- src/main/scala/units/Bridge.scala | 4 +++- src/main/scala/units/ELUpdater.scala | 14 +++++++------- .../client/contract/ChainContractClient.scala | 5 +---- .../client/contract/ChainContractOptions.scala | 4 ++-- 7 files changed, 16 insertions(+), 17 deletions(-) diff --git a/docker/genesis-testnet.json b/docker/genesis-testnet.json index 1512a6ec..5df32716 100644 --- a/docker/genesis-testnet.json +++ b/docker/genesis-testnet.json @@ -1,6 +1,6 @@ { "alloc": { - "0x1000000000000000000000000000000000000000": { + "0x0000000000000000000000000000000000006a7e": { "code": "0x60806040526004361061006e575f3560e01c806396f396c31161004c57806396f396c3146100e3578063c4a4326d14610105578063e984df0e1461011d578063fccc281314610131575f80fd5b806339dd5d1b146100725780637157405a146100b957806378338413146100ce575b5f80fd5b34801561007d575f80fd5b506100a161008c36600461059e565b5f6020819052908152604090205461ffff1681565b60405161ffff90911681526020015b60405180910390f35b3480156100c4575f80fd5b506100a161040081565b6100e16100dc3660046105b5565b61015c565b005b3480156100ee575f80fd5b506100f761044e565b6040519081526020016100b0565b348015610110575f80fd5b506100f76402540be40081565b348015610128575f80fd5b506100f7610468565b34801561013c575f80fd5b506101445f81565b6040516001600160a01b0390911681526020016100b0565b61016c6402540be40060016105fc565b34101561017834610478565b61019061018b6402540be40060016105fc565b610478565b6040516020016101a1929190610630565b604051602081830303815290604052906101d75760405162461bcd60e51b81526004016101ce9190610688565b60405180910390fd5b506101ef6402540be400677fffffffffffffff6105fc565b3411156101fb34610478565b61021561018b6402540be400677fffffffffffffff6105fc565b6040516020016102269291906106bd565b604051602081830303815290604052906102535760405162461bcd60e51b81526004016101ce9190610688565b50435f8181526020819052604090205461ffff166104009081119061027790610478565b604051602001610287919061070c565b604051602081830303815290604052906102b45760405162461bcd60e51b81526004016101ce9190610688565b505f818152602081905260408120805461ffff16916102d283610786565b91906101000a81548161ffff021916908361ffff160217905550505f6402540be400346102ff91906107a6565b9050346103116402540be400836105fc565b1461031b34610478565b6103296402540be400610478565b60405160200161033a9291906107c5565b604051602081830303815290604052906103675760405162461bcd60e51b81526004016101ce9190610688565b506040515f90819034908281818185825af1925050503d805f81146103a7576040519150601f19603f3d011682016040523d82523d5f602084013e6103ac565b606091505b50509050806103fd5760405162461bcd60e51b815260206004820152601e60248201527f4661696c656420746f2073656e6420746f206275726e2061646472657373000060448201526064016101ce565b604080516bffffffffffffffffffffffff1986168152600784900b60208201527ffeadaf04de8d7c2594453835b9a93b747e20e7a09a7fdb9280579a6dbaf131a8910160405180910390a150505050565b6104656402540be400677fffffffffffffff6105fc565b81565b6104656402540be40060016105fc565b6060815f0361049e5750506040805180820190915260018152600360fc1b602082015290565b815f5b81156104c757806104b181610814565b91506104c09050600a836107a6565b91506104a1565b5f8167ffffffffffffffff8111156104e1576104e161082c565b6040519080825280601f01601f19166020018201604052801561050b576020820181803683370190505b509050815b851561059557610521600182610840565b90505f61052f600a886107a6565b61053a90600a6105fc565b6105449088610840565b61054f906030610853565b90505f8160f81b90508084848151811061056b5761056b61086c565b60200101906001600160f81b03191690815f1a90535061058c600a896107a6565b97505050610510565b50949350505050565b5f602082840312156105ae575f80fd5b5035919050565b5f602082840312156105c5575f80fd5b81356bffffffffffffffffffffffff19811681146105e1575f80fd5b9392505050565b634e487b7160e01b5f52601160045260245ffd5b8082028115828204841417610613576106136105e8565b92915050565b5f81518060208401855e5f93019283525090919050565b6a029b2b73a103b30b63ab2960ad1b81525f61064f600b830185610619565b7f206d7573742062652067726561746572206f7220657175616c20746f20000000815261067f601d820185610619565b95945050505050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b6a029b2b73a103b30b63ab2960ad1b81525f6106dc600b830185610619565b7f206d757374206265206c657373206f7220657175616c20746f20000000000000815261067f601a820185610619565b7f4d6178207472616e7366657273206c696d6974206f662000000000000000000081525f61073d6017830184610619565b7f207265616368656420696e207468697320626c6f636b2e2054727920746f207381527232b732103a3930b739b332b9399030b3b0b4b760691b60208201526033019392505050565b5f61ffff821661ffff810361079d5761079d6105e8565b60010192915050565b5f826107c057634e487b7160e01b5f52601260045260245ffd5b500490565b6a029b2b73a103b30b63ab2960ad1b81525f6107e4600b830185610619565b7f206d7573742062652061206d756c7469706c65206f6620000000000000000000815261067f6017820185610619565b5f60018201610825576108256105e8565b5060010190565b634e487b7160e01b5f52604160045260245ffd5b81810381811115610613576106136105e8565b60ff8181168382160190811115610613576106136105e8565b634e487b7160e01b5f52603260045260245ffdfea2646970667358221220106399f534da089226c14e2f183f8421d059a924c65c97d7e4f3e931c54fe1bb64736f6c634300081a0033", "balance": "0x0" } diff --git a/local-network/configs/ec-common/genesis.json b/local-network/configs/ec-common/genesis.json index 6e586158..d9cbe0fe 100644 --- a/local-network/configs/ec-common/genesis.json +++ b/local-network/configs/ec-common/genesis.json @@ -36,7 +36,7 @@ "//": "private key and this comment are ignored. In a real chain, the private key should NOT be stored", "balance": "90000000000000000000000" }, - "0x1000000000000000000000000000000000000000": { + "0x0000000000000000000000000000000000006a7e": { "//1": "Bridge contract. To get new code, run: bridge-compile.sh", "//2": "To update get storage, see the storage layout and setup primitive fields. Or use 0xweb: https://stackoverflow.com/a/76490163", "code": "0x60806040526004361061006e575f3560e01c806396f396c31161004c57806396f396c3146100e3578063c4a4326d14610105578063e984df0e1461011d578063fccc281314610131575f80fd5b806339dd5d1b146100725780637157405a146100b957806378338413146100ce575b5f80fd5b34801561007d575f80fd5b506100a161008c36600461059e565b5f6020819052908152604090205461ffff1681565b60405161ffff90911681526020015b60405180910390f35b3480156100c4575f80fd5b506100a161040081565b6100e16100dc3660046105b5565b61015c565b005b3480156100ee575f80fd5b506100f761044e565b6040519081526020016100b0565b348015610110575f80fd5b506100f76402540be40081565b348015610128575f80fd5b506100f7610468565b34801561013c575f80fd5b506101445f81565b6040516001600160a01b0390911681526020016100b0565b61016c6402540be40060016105fc565b34101561017834610478565b61019061018b6402540be40060016105fc565b610478565b6040516020016101a1929190610630565b604051602081830303815290604052906101d75760405162461bcd60e51b81526004016101ce9190610688565b60405180910390fd5b506101ef6402540be400677fffffffffffffff6105fc565b3411156101fb34610478565b61021561018b6402540be400677fffffffffffffff6105fc565b6040516020016102269291906106bd565b604051602081830303815290604052906102535760405162461bcd60e51b81526004016101ce9190610688565b50435f8181526020819052604090205461ffff166104009081119061027790610478565b604051602001610287919061070c565b604051602081830303815290604052906102b45760405162461bcd60e51b81526004016101ce9190610688565b505f818152602081905260408120805461ffff16916102d283610786565b91906101000a81548161ffff021916908361ffff160217905550505f6402540be400346102ff91906107a6565b9050346103116402540be400836105fc565b1461031b34610478565b6103296402540be400610478565b60405160200161033a9291906107c5565b604051602081830303815290604052906103675760405162461bcd60e51b81526004016101ce9190610688565b506040515f90819034908281818185825af1925050503d805f81146103a7576040519150601f19603f3d011682016040523d82523d5f602084013e6103ac565b606091505b50509050806103fd5760405162461bcd60e51b815260206004820152601e60248201527f4661696c656420746f2073656e6420746f206275726e2061646472657373000060448201526064016101ce565b604080516bffffffffffffffffffffffff1986168152600784900b60208201527ffeadaf04de8d7c2594453835b9a93b747e20e7a09a7fdb9280579a6dbaf131a8910160405180910390a150505050565b6104656402540be400677fffffffffffffff6105fc565b81565b6104656402540be40060016105fc565b6060815f0361049e5750506040805180820190915260018152600360fc1b602082015290565b815f5b81156104c757806104b181610814565b91506104c09050600a836107a6565b91506104a1565b5f8167ffffffffffffffff8111156104e1576104e161082c565b6040519080825280601f01601f19166020018201604052801561050b576020820181803683370190505b509050815b851561059557610521600182610840565b90505f61052f600a886107a6565b61053a90600a6105fc565b6105449088610840565b61054f906030610853565b90505f8160f81b90508084848151811061056b5761056b61086c565b60200101906001600160f81b03191690815f1a90535061058c600a896107a6565b97505050610510565b50949350505050565b5f602082840312156105ae575f80fd5b5035919050565b5f602082840312156105c5575f80fd5b81356bffffffffffffffffffffffff19811681146105e1575f80fd5b9392505050565b634e487b7160e01b5f52601160045260245ffd5b8082028115828204841417610613576106136105e8565b92915050565b5f81518060208401855e5f93019283525090919050565b6a029b2b73a103b30b63ab2960ad1b81525f61064f600b830185610619565b7f206d7573742062652067726561746572206f7220657175616c20746f20000000815261067f601d820185610619565b95945050505050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b6a029b2b73a103b30b63ab2960ad1b81525f6106dc600b830185610619565b7f206d757374206265206c657373206f7220657175616c20746f20000000000000815261067f601a820185610619565b7f4d6178207472616e7366657273206c696d6974206f662000000000000000000081525f61073d6017830184610619565b7f207265616368656420696e207468697320626c6f636b2e2054727920746f207381527232b732103a3930b739b332b9399030b3b0b4b760691b60208201526033019392505050565b5f61ffff821661ffff810361079d5761079d6105e8565b60010192915050565b5f826107c057634e487b7160e01b5f52601260045260245ffd5b500490565b6a029b2b73a103b30b63ab2960ad1b81525f6107e4600b830185610619565b7f206d7573742062652061206d756c7469706c65206f6620000000000000000000815261067f6017820185610619565b5f60018201610825576108256105e8565b5060010190565b634e487b7160e01b5f52604160045260245ffd5b81810381811115610613576106136105e8565b60ff8181168382160190811115610613576106136105e8565b634e487b7160e01b5f52603260045260245ffdfea2646970667358221220106399f534da089226c14e2f183f8421d059a924c65c97d7e4f3e931c54fe1bb64736f6c634300081a0033", diff --git a/local-network/deploy/src/common-settings.ts b/local-network/deploy/src/common-settings.ts index dbf00f01..a33ebbc1 100644 --- a/local-network/deploy/src/common-settings.ts +++ b/local-network/deploy/src/common-settings.ts @@ -21,7 +21,7 @@ function mkWavesAccount(seed: string, nonce: number): WavesAccount { } } -export const elBridgeContractAddress = '0x1000000000000000000000000000000000000000'; +export const elBridgeContractAddress = '0x0000000000000000000000000000000000006a7e'; export const chainContract = mkWavesAccount('devnet-1', 2); export const wavesMiner1 = mkWavesAccount('devnet-1', 0); export const wavesMiner2 = mkWavesAccount('devnet-2', 0); diff --git a/src/main/scala/units/Bridge.scala b/src/main/scala/units/Bridge.scala index 5760258c..d4ad0e34 100644 --- a/src/main/scala/units/Bridge.scala +++ b/src/main/scala/units/Bridge.scala @@ -8,7 +8,7 @@ import org.web3j.abi.datatypes.Event import org.web3j.abi.datatypes.generated.{Bytes20, Int64} import org.web3j.abi.{FunctionReturnDecoder, TypeEncoder, TypeReference} import units.client.engine.model.GetLogsResponseEntry -import units.eth.Gwei +import units.eth.{EthAddress, Gwei} import java.math.BigInteger import scala.jdk.CollectionConverters.{ListHasAsScala, SeqHasAsJava} @@ -16,6 +16,8 @@ import scala.util.Try import scala.util.control.NonFatal object Bridge { + val ElAddress = EthAddress.unsafeFrom("0x0000000000000000000000000000000000006a7e") + private val ExactTransfersNumber = 1024 private val PublicKeyHashType = new TypeReference[Bytes20](false) {} private val AmountType = new TypeReference[Int64](false) {} diff --git a/src/main/scala/units/ELUpdater.scala b/src/main/scala/units/ELUpdater.scala index 48e64ad6..d0ebdf67 100644 --- a/src/main/scala/units/ELUpdater.scala +++ b/src/main/scala/units/ELUpdater.scala @@ -234,7 +234,7 @@ class ELUpdater( ClientError(s"Failed to broadcast block ${newBlock.hash}: ${err.toString}") ) ecBlock = newBlock.toEcBlock - transfersRootHash <- getElToClTransfersRootHash(ecBlock.hash, chainContractOptions.elBridgeAddress) + transfersRootHash <- getElToClTransfersRootHash(ecBlock.hash) funcCall <- contractFunction.toFunctionCall(ecBlock.hash, transfersRootHash, m.lastClToElTransferIndex) _ <- callContract( funcCall, @@ -1234,11 +1234,11 @@ class ELUpdater( } } - private def getElToClTransfersRootHash(hash: BlockHash, elBridgeAddress: EthAddress): Job[Digest] = + private def getElToClTransfersRootHash(hash: BlockHash): Job[Digest] = for { - elRawLogs <- engineApiClient.getLogs(hash, elBridgeAddress, Bridge.ElSentNativeEventTopic) + elRawLogs <- engineApiClient.getLogs(hash, Bridge.ElAddress, Bridge.ElSentNativeEventTopic) rootHash <- { - val relatedElRawLogs = elRawLogs.filter(x => x.address == elBridgeAddress && x.topics.contains(Bridge.ElSentNativeEventTopic)) + val relatedElRawLogs = elRawLogs.filter(x => x.address == Bridge.ElAddress && x.topics.contains(Bridge.ElSentNativeEventTopic)) Bridge .mkTransfersHash(relatedElRawLogs) .leftMap(e => ClientError(e)) @@ -1272,8 +1272,8 @@ class ELUpdater( ) } - private def validateElToClTransfers(contractBlock: ContractBlock, elBridgeAddress: EthAddress): Job[Unit] = - getElToClTransfersRootHash(contractBlock.hash, elBridgeAddress).flatMap { elRootHash => + private def validateElToClTransfers(contractBlock: ContractBlock): Job[Unit] = + getElToClTransfersRootHash(contractBlock.hash).flatMap { elRootHash => // elRootHash is the source of true if (java.util.Arrays.equals(contractBlock.elToClTransfersRootHash, elRootHash)) Either.unit else @@ -1337,7 +1337,7 @@ class ELUpdater( (), ClientError(s"Miner in EC block ${ecBlock.minerRewardL2Address} should be equal to miner on contract ${contractBlock.minerRewardL2Address}") ) - _ <- validateElToClTransfers(contractBlock, prevState.options.elBridgeAddress) + _ <- validateElToClTransfers(contractBlock) updatedLastElWithdrawalIndex <- fullWithdrawalsValidation(contractBlock, ecBlock, prevState.fullValidationStatus, prevState.options) } yield updatedLastElWithdrawalIndex diff --git a/src/main/scala/units/client/contract/ChainContractClient.scala b/src/main/scala/units/client/contract/ChainContractClient.scala index 93d9007e..af41fd88 100644 --- a/src/main/scala/units/client/contract/ChainContractClient.scala +++ b/src/main/scala/units/client/contract/ChainContractClient.scala @@ -198,10 +198,7 @@ trait ChainContractClient { def getOptions: ChainContractOptions = ChainContractOptions( miningReward = getLongData("minerReward") .map(Gwei.ofRawGwei) - .getOrElse(throw new IllegalStateException("minerReward is empty on contract")), - elBridgeAddress = getStringData("elBridgeAddress") - .map(EthAddress.unsafeFrom) - .getOrElse(throw new IllegalStateException("elBridgeAddress is empty on contract")) + .getOrElse(throw new IllegalStateException("minerReward is empty on contract")) ) private def getChainMeta(chainId: Long): Option[(Int, BlockHash)] = { diff --git a/src/main/scala/units/client/contract/ChainContractOptions.scala b/src/main/scala/units/client/contract/ChainContractOptions.scala index 5b752ba2..1e81ee09 100644 --- a/src/main/scala/units/client/contract/ChainContractOptions.scala +++ b/src/main/scala/units/client/contract/ChainContractOptions.scala @@ -3,12 +3,12 @@ package units.client.contract import com.wavesplatform.common.state.ByteStr import units.BlockHash import units.client.contract.ContractFunction.* -import units.eth.{EthAddress, Gwei} +import units.eth.Gwei /** @note * Make sure you have an activation gap: a new feature should not be activated suddenly during nearest blocks. */ -case class ChainContractOptions(miningReward: Gwei, elBridgeAddress: EthAddress) { +case class ChainContractOptions(miningReward: Gwei) { def startEpochChainFunction(reference: BlockHash, vrf: ByteStr, chainInfo: Option[ChainInfo]): ContractFunction = { chainInfo match { case Some(ci) => extendChainFunction(reference, vrf, ci)