Skip to content

Commit

Permalink
Merge branch 'master' into ap/lim-tree-max-encoded-len
Browse files Browse the repository at this point in the history
  • Loading branch information
playX18 authored Jan 28, 2025
2 parents 04e8498 + b1aa585 commit 495b21d
Show file tree
Hide file tree
Showing 29 changed files with 193 additions and 184 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ jobs:
run: |
npm cache clean --force
# version from ethexe/contracts/lib/openzeppelin-foundry-upgrades/src/internal/Versions.sol
# npx @openzeppelin/upgrades-core@^1.37.0
# temp fix for CI
npx @openzeppelin/upgrades-core@=1.41.0
sed -i 's/\^1\.37\.0/=1.41.0/' ethexe/contracts/lib/openzeppelin-foundry-upgrades/src/internal/Versions.sol
npx @openzeppelin/upgrades-core@^1.37.0
cd ethexe/contracts
forge fmt --check
Expand Down
8 changes: 5 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
[submodule "ethexe/contracts/lib/openzeppelin-contracts"]
path = ethexe/contracts/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
branch = "release-v5.1"
branch = "release-v5.2"
[submodule "ethexe/contracts/lib/openzeppelin-foundry-upgrades"]
path = ethexe/contracts/lib/openzeppelin-foundry-upgrades
url = https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades
branch = "main"
[submodule "ethexe/contracts/lib/openzeppelin-contracts-upgradeable"]
path = ethexe/contracts/lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
branch = "release-v5.1"
branch = "release-v5.2"
[submodule "ethexe/contracts/lib/symbiotic-core"]
path = ethexe/contracts/lib/symbiotic-core
url = https://github.com/grishasobol/symbiotic-core
url = https://github.com/gear-tech/symbiotic-core
branch = "gear-main"
[submodule "ethexe/contracts/lib/frost-secp256k1-evm"]
path = ethexe/contracts/lib/frost-secp256k1-evm
url = https://github.com/StackOverflowExcept1on/frost-secp256k1-evm
branch = "master"
26 changes: 25 additions & 1 deletion core-errors/src/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ impl ErrorReplyReason {
bytes
}

// TODO: add test this method works correctly for all possible variants #3715
fn from_bytes(bytes: [u8; 3]) -> Self {
match bytes[0] {
b if Self::Execution(Default::default()).discriminant() == b => {
Expand Down Expand Up @@ -410,10 +409,35 @@ impl SignalCode {
v if Self::Execution(SimpleExecutionError::StackLimitExceeded).to_u32() == v => {
Self::Execution(SimpleExecutionError::StackLimitExceeded)
}
v if Self::Execution(SimpleExecutionError::Unsupported).to_u32() == v => {
Self::Execution(SimpleExecutionError::Unsupported)
}
v if Self::RemovedFromWaitlist.to_u32() == v => Self::RemovedFromWaitlist,
_ => return None,
};

Some(res)
}
}

#[cfg(feature = "codec")]
#[cfg(test)]
mod tests {
use super::{ReplyCode, SignalCode};

#[test]
fn test_reply_code_encode_decode() {
for code in enum_iterator::all::<ReplyCode>() {
let bytes = code.to_bytes();
assert_eq!(code, ReplyCode::from_bytes(bytes));
}
}

#[test]
fn test_signal_code_encode_decode() {
for signal in enum_iterator::all::<SignalCode>() {
let code = signal.to_u32();
assert_eq!(signal, SignalCode::from_u32(code).unwrap());
}
}
}
7 changes: 6 additions & 1 deletion ethexe/cli/src/commands/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,14 @@ impl TxCommand {

println!("Uploading {} to Ethereum", path_to_wasm.display(),);

let (tx, code_id) = router
let pending_builder = router
.request_code_validation_with_sidecar(&code)
.await
.with_context(|| "failed to create code validation request")?;

let (tx, code_id) = pending_builder
.send()
.await
.with_context(|| "failed to request code validation")?;

println!("Completed in transaction {tx:?}");
Expand Down
2 changes: 1 addition & 1 deletion ethexe/common/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub trait CodesStorage: Send + Sync {
fn set_instrumented_code(&self, runtime_id: u32, code_id: CodeId, code: InstrumentedCode);

fn code_blob_tx(&self, code_id: CodeId) -> Option<H256>;
fn set_code_blob_tx(&self, code_id: CodeId, blob_tx_hash: H256);
fn set_code_blob_tx(&self, code_id: CodeId, tx_hash: H256);

fn code_valid(&self, code_id: CodeId) -> Option<bool>;
fn set_code_valid(&self, code_id: CodeId, valid: bool);
Expand Down
16 changes: 5 additions & 11 deletions ethexe/common/src/events/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ pub enum Event {
},
CodeValidationRequested {
code_id: CodeId,
/// This field is replaced with tx hash in case of zero.
blob_tx_hash: H256,
tx_hash: H256,
},
ComputationSettingsChanged {
threshold: u64,
Expand All @@ -51,13 +50,9 @@ pub enum Event {
impl Event {
pub fn to_request(self) -> Option<RequestEvent> {
Some(match self {
Self::CodeValidationRequested {
code_id,
blob_tx_hash,
} => RequestEvent::CodeValidationRequested {
code_id,
blob_tx_hash,
},
Self::CodeValidationRequested { code_id, tx_hash } => {
RequestEvent::CodeValidationRequested { code_id, tx_hash }
}
Self::ComputationSettingsChanged {
threshold,
wvara_per_second,
Expand All @@ -82,8 +77,7 @@ pub enum RequestEvent {
CodeValidationRequested {
code_id: CodeId,
// TODO (breathx): replace with `code: Vec<u8>`
/// This field is replaced with tx hash in case of zero.
blob_tx_hash: H256,
tx_hash: H256,
},
ComputationSettingsChanged {
threshold: u64,
Expand Down
2 changes: 1 addition & 1 deletion ethexe/contracts/lib/forge-std
2 changes: 1 addition & 1 deletion ethexe/contracts/lib/openzeppelin-contracts
2 changes: 1 addition & 1 deletion ethexe/contracts/lib/openzeppelin-contracts-upgradeable
Submodule openzeppelin-contracts-upgradeable updated 96 files
+1 −0 .codecov.yml
+0 −20 .eslintrc
+6 −2 .github/workflows/checks.yml
+1 −1 .github/workflows/formal-verification.yml
+1 −1 .gitmodules
+43 −1 CHANGELOG.md
+8 −1 GUIDELINES.md
+ audits/2024-10-v5.1.pdf
+1 −0 audits/README.md
+12 −0 contracts/account/README.adoc
+6 −1 contracts/finance/VestingWalletUpgradeable.sol
+38 −57 contracts/governance/GovernorUpgradeable.sol
+6 −0 contracts/governance/README.adoc
+250 −0 contracts/governance/extensions/GovernorCountingOverridableUpgradeable.sol
+4 −14 contracts/governance/extensions/GovernorPreventLateQuorumUpgradeable.sol
+106 −0 contracts/governance/utils/VotesExtendedUpgradeable.sol
+12 −11 contracts/governance/utils/VotesUpgradeable.sol
+1 −1 contracts/mocks/DummyImplementationUpgradeable.sol
+1 −1 contracts/mocks/MerkleTreeMockUpgradeable.sol
+8 −1 contracts/mocks/StatelessUpgradeable.sol
+53 −0 contracts/mocks/VotesExtendedMockUpgradeable.sol
+50 −1 contracts/mocks/WithInit.sol
+29 −0 contracts/mocks/account/utils/ERC7579UtilsMockUpgradeable.sol
+0 −0 contracts/mocks/docs/access-control/AccessControlNonRevokableAdminUpgradeable.sol
+24 −0 contracts/mocks/governance/GovernorCountingOverridableMockUpgradeable.sol
+2 −8 contracts/mocks/governance/GovernorPreventLateQuorumMockUpgradeable.sol
+1 −1 contracts/mocks/governance/GovernorStorageMockUpgradeable.sol
+1 −1 contracts/mocks/proxy/UUPSUpgradeableMockUpgradeable.sol
+42 −0 contracts/mocks/token/ERC20VotesAdditionalCheckpointsMockUpgradeable.sol
+2 −2 contracts/package.json
+2 −2 contracts/proxy/utils/UUPSUpgradeable.sol
+2 −2 contracts/token/ERC20/ERC20Upgradeable.sol
+6 −3 contracts/token/ERC20/extensions/ERC1363Upgradeable.sol
+94 −0 contracts/utils/NoncesKeyedUpgradeable.sol
+6 −1 contracts/utils/README.adoc
+1 −1 docs/modules/ROOT/pages/erc1155.adoc
+2 −2 docs/modules/ROOT/pages/erc4626.adoc
+1 −1 docs/modules/ROOT/pages/extending-contracts.adoc
+1 −1 docs/modules/ROOT/pages/governance.adoc
+26 −0 eslint.config.mjs
+1 −0 foundry.toml
+1 −1 fv-requirements.txt
+1 −1 lib/forge-std
+1 −1 lib/openzeppelin-contracts
+402 −311 package-lock.json
+9 −6 package.json
+5 −4 scripts/checks/inheritance-ordering.js
+49 −0 scripts/checks/pragma-consistency.js
+1 −1 scripts/generate/run.js
+0 −1 scripts/generate/templates/Checkpoints.js
+0 −1 scripts/generate/templates/Checkpoints.t.js
+0 −2 scripts/generate/templates/EnumerableMap.js
+0 −2 scripts/generate/templates/EnumerableSet.js
+0 −2 scripts/generate/templates/MerkleProof.js
+1 −1 scripts/generate/templates/Packing.opts.js
+2 −2 scripts/generate/templates/Packing.t.js
+0 −2 scripts/generate/templates/SafeCast.js
+2 −2 scripts/release/workflow/state.js
+1 −1 scripts/update-docs-branch.js
+1 −1 slither.config.json
+288 −0 test/account/utils/draft-ERC4337Utils.test.js
+421 −0 test/account/utils/draft-ERC7579Utils.t.sol
+353 −0 test/account/utils/draft-ERC7579Utils.test.js
+1 −0 test/bin/EntryPoint070.abi
+ test/bin/EntryPoint070.bytecode
+1 −0 test/bin/SenderCreator070.abi
+ test/bin/SenderCreator070.bytecode
+346 −0 test/governance/extensions/GovernorCountingOverridable.test.js
+11 −8 test/governance/utils/ERC6372.behavior.js
+152 −0 test/governance/utils/VotesExtended.test.js
+109 −0 test/helpers/chains.js
+7 −0 test/helpers/eip712-types.js
+31 −0 test/helpers/erc4337-entrypoint.js
+111 −0 test/helpers/erc4337.js
+58 −0 test/helpers/erc7579.js
+17 −0 test/helpers/governance.js
+1 −1 test/helpers/storage.js
+192 −78 test/metatx/ERC2771Forwarder.t.sol
+0 −77 test/metatx/ERC2771Forwarder.test.js
+34 −2 test/proxy/Clones.t.sol
+151 −71 test/proxy/Clones.test.js
+2 −2 test/proxy/transparent/TransparentUpgradeableProxy.behaviour.js
+8 −8 test/token/ERC721/extensions/ERC721Consecutive.test.js
+3 −2 test/utils/Address.test.js
+88 −0 test/utils/Bytes.test.js
+53 −0 test/utils/CAIP.test.js
+2 −2 test/utils/Create2.test.js
+189 −0 test/utils/Nonces.behavior.js
+3 −62 test/utils/Nonces.test.js
+17 −0 test/utils/NoncesKeyed.test.js
+402 −90 test/utils/Packing.t.sol
+50 −0 test/utils/Strings.t.sol
+174 −12 test/utils/Strings.test.js
+3 −5 test/utils/cryptography/ECDSA.test.js
+5 −100 test/utils/cryptography/P256.t.sol
+2 −2 test/utils/introspection/SupportsInterface.behavior.js
2 changes: 1 addition & 1 deletion ethexe/contracts/lib/symbiotic-core
Submodule symbiotic-core updated 230 files
5 changes: 2 additions & 3 deletions ethexe/contracts/src/IRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ interface IRouter {
/// @notice Emitted when a new code validation request is submitted.
/// @dev This is a *requesting* event, signaling that validators need to download and validate the code from the transaction blob.
/// @param codeId The expected code ID of the applied WASM blob, represented as a Blake2 hash.
/// @param blobTxHash The transaction hash that contains the WASM blob. Set to zero if applied to the current transaction.
event CodeValidationRequested(bytes32 codeId, bytes32 blobTxHash);
event CodeValidationRequested(bytes32 codeId);

/// @notice Emitted when validators for the next era has been set.
/// @dev This is an *informational* and *request* event, signaling that validators has been set for the next era.
Expand Down Expand Up @@ -104,7 +103,7 @@ interface IRouter {
function lookupGenesisHash() external;

/// @dev CodeValidationRequested Emitted on success.
function requestCodeValidation(bytes32 codeId, bytes32 blobTxHash) external;
function requestCodeValidation(bytes32 codeId) external;
/// @dev ProgramCreated Emitted on success.
function createProgram(bytes32 codeId, bytes32 salt) external returns (address);
/// @dev ProgramCreated Emitted on success.
Expand Down
6 changes: 3 additions & 3 deletions ethexe/contracts/src/Router.sol
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ contract Router is IRouter, OwnableUpgradeable, ReentrancyGuardTransient {
router.genesisBlock.hash = blockhash(router.genesisBlock.number);
}

function requestCodeValidation(bytes32 _codeId, bytes32 _blobTxHash) external {
require(_blobTxHash != 0 || blobhash(0) != 0, "blob can't be found");
function requestCodeValidation(bytes32 _codeId) external {
require(blobhash(0) != 0, "blob can't be found, router expected EIP-4844 transaction with WASM blob");

Storage storage router = _router();
require(router.genesisBlock.hash != bytes32(0), "router genesis is zero; call `lookupGenesisHash()` first");
Expand All @@ -242,7 +242,7 @@ contract Router is IRouter, OwnableUpgradeable, ReentrancyGuardTransient {

router.protocolData.codes[_codeId] = Gear.CodeState.ValidationRequested;

emit CodeValidationRequested(_codeId, _blobTxHash);
emit CodeValidationRequested(_codeId);
}

function createProgram(bytes32 _codeId, bytes32 _salt) external returns (address) {
Expand Down
7 changes: 5 additions & 2 deletions ethexe/contracts/test/POC.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ contract POCTest is Base {

function test_POC() public {
bytes32 _codeId = bytes32(uint256(1));
bytes32 _blobTxHash = bytes32(uint256(2));

router.requestCodeValidation(_codeId, _blobTxHash);
bytes32[] memory hashes = new bytes32[](1);
hashes[0] = bytes32(uint256(1));
vm.blobhashes(hashes);

router.requestCodeValidation(_codeId);

address[] memory _validators = router.validators();
assertEq(_validators.length, maxValidators);
Expand Down
4 changes: 2 additions & 2 deletions ethexe/db/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ impl CodesStorage for Database {
})
}

fn set_code_blob_tx(&self, code_id: CodeId, blob_tx_hash: H256) {
fn set_code_blob_tx(&self, code_id: CodeId, tx_hash: H256) {
self.kv
.put(&KeyPrefix::CodeUpload.one(code_id), blob_tx_hash.encode());
.put(&KeyPrefix::CodeUpload.one(code_id), tx_hash.encode());
}

fn code_valid(&self, code_id: CodeId) -> Option<bool> {
Expand Down
2 changes: 1 addition & 1 deletion ethexe/ethereum/Mirror.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ethexe/ethereum/MirrorProxy.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ethexe/ethereum/Router.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ethexe/ethereum/TransparentUpgradeableProxy.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ethexe/ethereum/WrappedVara.json

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions ethexe/ethereum/src/abi/events/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,6 @@ impl From<IRouter::CodeGotValidated> for RouterEvent {
}
}

impl From<IRouter::CodeValidationRequested> for RouterEvent {
fn from(value: IRouter::CodeValidationRequested) -> Self {
Self::CodeValidationRequested {
code_id: bytes32_to_code_id(value.codeId),
blob_tx_hash: bytes32_to_h256(value.blobTxHash),
}
}
}

impl From<IRouter::ComputationSettingsChanged> for RouterEvent {
fn from(value: IRouter::ComputationSettingsChanged) -> Self {
Self::ComputationSettingsChanged {
Expand Down
15 changes: 8 additions & 7 deletions ethexe/ethereum/src/router/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::{abi::utils::bytes32_to_h256, decode_log, IRouter};
use crate::{
abi::utils::{bytes32_to_code_id, bytes32_to_h256},
decode_log, IRouter,
};
use alloy::{primitives::B256, rpc::types::eth::Log, sol_types::SolEvent};
use anyhow::{anyhow, Result};
use ethexe_common::events::{RouterEvent, RouterRequestEvent};
Expand Down Expand Up @@ -58,14 +61,12 @@ pub fn try_extract_event(log: &Log) -> Result<Option<RouterEvent>> {
let tx_hash = log
.transaction_hash
.ok_or_else(|| anyhow!("Tx hash not found"))?;
let event = decode_log::<IRouter::CodeValidationRequested>(log)?;

let mut event = decode_log::<IRouter::CodeValidationRequested>(log)?;

if event.blobTxHash.is_zero() {
event.blobTxHash = tx_hash;
RouterEvent::CodeValidationRequested {
code_id: bytes32_to_code_id(event.codeId),
tx_hash: bytes32_to_h256(tx_hash),
}

event.into()
}
COMPUTATION_SETTINGS_CHANGED => {
decode_log::<IRouter::ComputationSettingsChanged>(log)?.into()
Expand Down
51 changes: 30 additions & 21 deletions ethexe/ethereum/src/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
use crate::{
abi::{utils::uint256_to_u256, Gear::CodeState, IRouter},
wvara::WVara,
AlloyProvider, AlloyTransport, TryGetReceipt,
AlloyEthereum, AlloyProvider, AlloyTransport, TryGetReceipt,
};
use alloy::{
consensus::{SidecarBuilder, SimpleCoder},
primitives::{Address, Bytes, B256, U256},
providers::{Provider, ProviderBuilder, RootProvider},
primitives::{Address, Bytes, U256},
providers::{PendingTransactionBuilder, Provider, ProviderBuilder, RootProvider},
rpc::types::Filter,
transports::BoxTransport,
};
Expand All @@ -46,6 +46,26 @@ type Instance = IRouter::IRouterInstance<AlloyTransport, InstanceProvider>;

type QueryInstance = IRouter::IRouterInstance<AlloyTransport, Arc<RootProvider<BoxTransport>>>;

pub struct PendingCodeRequestBuilder {
code_id: CodeId,
pending_builder: PendingTransactionBuilder<AlloyTransport, AlloyEthereum>,
}

impl PendingCodeRequestBuilder {
pub fn code_id(&self) -> CodeId {
self.code_id
}

pub fn tx_hash(&self) -> H256 {
H256(self.pending_builder.tx_hash().0)
}

pub async fn send(self) -> Result<(H256, CodeId)> {
let receipt = self.pending_builder.try_get_receipt().await?;
Ok(((*receipt.transaction_hash).into(), self.code_id))
}
}

#[derive(Clone)]
pub struct Router {
instance: Instance,
Expand Down Expand Up @@ -81,33 +101,22 @@ impl Router {
WVara::new(self.wvara_address, self.instance.provider().clone())
}

pub async fn request_code_validation(
&self,
code_id: CodeId,
blob_tx_hash: H256,
) -> Result<H256> {
let builder = self.instance.requestCodeValidation(
code_id.into_bytes().into(),
blob_tx_hash.to_fixed_bytes().into(),
);
let receipt = builder.send().await?.try_get_receipt().await?;

Ok((*receipt.transaction_hash).into())
}

pub async fn request_code_validation_with_sidecar(
&self,
code: &[u8],
) -> Result<(H256, CodeId)> {
) -> Result<PendingCodeRequestBuilder> {
let code_id = CodeId::generate(code);

let builder = self
.instance
.requestCodeValidation(code_id.into_bytes().into(), B256::ZERO)
.requestCodeValidation(code_id.into_bytes().into())
.sidecar(SidecarBuilder::<SimpleCoder>::from_slice(code).build()?);
let receipt = builder.send().await?.try_get_receipt().await?;
let pending_builder = builder.send().await?;

Ok(((*receipt.transaction_hash).into(), code_id))
Ok(PendingCodeRequestBuilder {
code_id,
pending_builder,
})
}

pub async fn wait_code_validation(&self, code_id: CodeId) -> Result<bool> {
Expand Down
8 changes: 4 additions & 4 deletions ethexe/observer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ impl ObserverService {
}
}

pub fn lookup_code(&mut self, code_id: CodeId, blob_tx_hash: H256) {
pub fn lookup_code(&mut self, code_id: CodeId, tx_hash: H256) {
self.codes_futures.push(Box::pin(read_code_from_tx_hash(
self.blobs.clone(),
code_id,
blob_tx_hash,
tx_hash,
Some(3),
)));
}
Expand Down Expand Up @@ -200,8 +200,8 @@ impl ObserverService {

// TODO: replace me with proper processing of all events, including commitments.
for event in &events {
if let BlockEvent::Router(RouterEvent::CodeValidationRequested { code_id, blob_tx_hash }) = event {
self.lookup_code(*code_id, *blob_tx_hash);
if let BlockEvent::Router(RouterEvent::CodeValidationRequested { code_id, tx_hash }) = event {
self.lookup_code(*code_id, *tx_hash);
}
}

Expand Down
8 changes: 2 additions & 6 deletions ethexe/observer/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,15 +439,11 @@ impl Query {
Ok(events)
}

pub async fn download_code(
&self,
expected_code_id: CodeId,
blob_tx_hash: H256,
) -> Result<Vec<u8>> {
pub async fn download_code(&self, expected_code_id: CodeId, tx_hash: H256) -> Result<Vec<u8>> {
let blob_reader = self.blob_reader.clone();
let attempts = Some(3);

crate::read_code_from_tx_hash(blob_reader, expected_code_id, blob_tx_hash, attempts)
crate::read_code_from_tx_hash(blob_reader, expected_code_id, tx_hash, attempts)
.await
.map(|res| res.1)
}
Expand Down
Loading

0 comments on commit 495b21d

Please sign in to comment.